useMultipleSelectionState

Manages state for multiple selection and focus in a collection.

installyarn add react-stately
version3.30.0
usageimport {useMultipleSelectionState} from 'react-stately'

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 useListState, and useSelectState. These expose a SelectionManager, which provides a higher level way to manipulate selection state.

API#


useMultipleSelectionState( (props: MultipleSelectionStateProps )): MultipleSelectionState

Interface#


Properties

NameTypeDescription
selectionModeSelectionModeThe type of selection that is allowed in the collection.
selectionBehaviorSelectionBehaviorThe selection behavior for the collection.
disallowEmptySelectionbooleanWhether the collection allows empty selection.
selectedKeysSelectionThe currently selected keys in the collection.
disabledKeysSet<Key>The currently disabled keys in the collection.
disabledBehaviorDisabledBehaviorWhether disabledKeys applies to selection, actions, or both.
isFocusedbooleanWhether the collection is currently focused.
focusedKeyKeyThe current focused key in the collection.
childFocusStrategyFocusStrategyWhether the first or last child of the focused key should receive focus.

Methods

MethodDescription
setSelectionBehavior( (selectionBehavior: SelectionBehavior )): voidSets the selection behavior for the collection.
setSelectedKeys( (keys: Selection )): voidSets the selected keys in the collection.
setFocused( (isFocused: boolean )): voidSets whether the collection is focused.
setFocusedKey( (key: Key, , child?: FocusStrategy )): voidSets the focused key, and optionally, whether the first or last child of that key should receive focus.