useMultipleSelectionState

Manages state for multiple selection and focus in a collection.

installyarn add @react-stately/selection
version3.3.0
usageimport {useMultipleSelectionState} from '@react-stately/selection'

Introduction#


useMultipleSelectionState manages selection state for many components. Oftentimes, you won't need to use this hook directly, since it's included in hooks like

, and . These expose a SelectionManager, which provides a higher level way to manipulate selection state.

API#


useMultipleSelectionState( (props: )):

Interface#


Properties

NameTypeDescription
selectionModeThe type of selection that is allowed in the collection.
disallowEmptySelectionbooleanWhether the collection allows empty selection.
selectedKeysThe currently selected keys in the collection.
disabledKeysSet<Key>The currently disabled keys in the collection.
isFocusedbooleanWhether the collection is currently focused.
isFocusWithinItembooleanWhether focus is currently within a cell in the collection.
focusedKeyKeyThe current focused key in the collection.

Methods

MethodDescription
setSelectedKeys( (keys: ( (v: )) => )): voidSets the selected keys in the collection.
setFocused( (isFocused: boolean )): voidSets whether the collection is focused.
setFocusWithinItem( (isFocused: boolean )): voidSets whether focus is currently within a cell in the collection.
setFocusedKey( (key: Key )): voidSets the focused key.