SelectionManager
An interface for reading and updating multiple selection state.
install | yarn add @react-stately/selection |
---|---|
version | 3.3.0 |
usage | import {SelectionManager} from '@react-stately/selection' |
Introduction#
A provides a generic interface for reading and
updating selection and focus state based on a
.
As discussed in the selection introduction, a selection is represented
by a Set of item keys. Focus
is represented by a single item key.
Focus state is updated when navigating a collection with the keyboard. Selection state is updated when a user
clicks or taps an item, or uses the keyboard to select an item. These interactions are handled by
the hook in react-aria.
A SelectionManager
wraps the state returned by .
Oftentimes, you won't need to construct these directly because hooks like
and
already handle this and return
a
SelectionManager
for you.
Interface#
Properties
Name | Type | Description |
selectionMode |
| The type of selection that is allowed in the collection. |
disallowEmptySelection | boolean | Whether the collection allows empty selection. |
isFocused | boolean | Whether the collection is currently focused. |
isFocusWithinItem | boolean | Whether focus is currently within a cell in the collection. |
focusedKey | Key | The current focused key in the collection. |
selectedKeys | Set<Key> | The currently selected keys in the collection. |
isEmpty | boolean | Whether the selection is empty. |
isSelectAll | boolean | Whether all items in the collection are selected. |
firstSelectedKey | Key | null | |
lastSelectedKey | Key | null |
Methods
Method | Description |
setFocused(
(isFocused: boolean
)): void | Sets whether the collection is focused. |
setFocusWithinItem(
(isFocused: boolean
)): void | Sets whether focus is currently within a cell in the collection. |
setFocusedKey(
(key: Key
)): void | Sets the focused key. |
isSelected(
(key: Key
)): void | Returns whether a key is selected. |
extendSelection(
(toKey: Key
)): void | Extends the selection to the given key. |
toggleSelection(
(key: Key
)): void | Toggles whether the given key is selected. |
replaceSelection(
(key: Key
)): void | Replaces the selection with only the given key. |
selectAll(): void | Selects all items in the collection. |
clearSelection(): void | Removes all keys from the selection. |
toggleSelectAll(): void | Toggles between select all and an empty selection. |
select(
(key: Key,
, e:
| | PointerEvent
)): void |