useMultipleSelectionState

Manages state for multiple selection and focus in a collection.

installyarn add react-stately
version3.35.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

, 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.
selectionBehaviorThe selection behavior for the collection.
disallowEmptySelectionbooleanWhether the collection allows empty selection.
selectedKeysThe currently selected keys in the collection.
disabledKeysSet<Key>The currently disabled keys in the collection.
disabledBehaviorWhether disabledKeys applies to selection, actions, or both.
isFocusedbooleanWhether the collection is currently focused.
focusedKeyKeynullThe current focused key in the collection.
childFocusStrategynullWhether the first or last child of the focused key should receive focus.

Methods

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