Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

@react-aria/selection

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/selection

Spectrum UI components in React


Version published
Weekly downloads
717K
increased by75.16%
Maintainers
2
Weekly downloads
 
Created
Issues
744

What is @react-aria/selection?

@react-aria/selection is a library that provides React hooks for managing selection state in components. It is part of the React Aria collection of hooks and components that help build accessible user interfaces. This package is particularly useful for creating custom selection logic in lists, tables, and other components where users need to select one or more items.

What are @react-aria/selection's main functionalities?

useSelectableCollection

The `useSelectableCollection` hook is used to manage the selection state of a collection of items. It supports multiple selection modes and provides properties and methods to handle item selection.

import { useSelectableCollection } from '@react-aria/selection';

function MyComponent() {
  let state = useSelectableCollection({
    selectionMode: 'multiple',
    disallowEmptySelection: false
  });

  return (
    <div>
      {state.collection.map(item => (
        <div key={item.key} {...state.getItemProps(item)}>
          {item.rendered}
        </div>
      ))}
    </div>
  );
}

useSelectableItem

The `useSelectableItem` hook is used to manage the selection state of an individual item within a collection. It provides properties and methods to handle item selection and focus.

import { useSelectableItem } from '@react-aria/selection';

function SelectableItem({ item, state }) {
  let ref = React.useRef();
  let { itemProps } = useSelectableItem({
    key: item.key,
    ref,
    state
  });

  return (
    <div {...itemProps} ref={ref}>
      {item.rendered}
    </div>
  );
}

Other packages similar to @react-aria/selection

FAQs

Package last updated on 26 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts