useSelectState

Provides state management for a select component. Handles building a collection of items from props, handles the open state for the popup menu, and manages multiple selection state.

installyarn add @react-stately/select
version3.0.0-alpha.1
usageimport {useSelectState} from '@react-stately/select'

API#


useSelectState<T>( (props: SelectProps<T> )): SelectState<T>

Interface#


Properties

NameTypeDescription
selectedKeyKeyThe key for the currently selected item.
selectedItemNode<T>The value of the currently selected item.
isFocusedbooleanWhether the select is currently focused.
collectionCollection<Node<T>>A collection of items in the list.
disabledKeysSet<Key>A set of items that are disabled.
selectionManagerSelectionManagerA selection manager to read and update multiple selection state.
isOpenbooleanWhether the menu is currently open.
focusStrategyFocusStrategyControls which item will be auto focused when the menu opens.

Methods

MethodDescription
setSelectedKey( (key: Key )): voidSets the selected key.
setFocused( (isFocused: boolean )): voidSets whether the select is focused.
open( ( )): voidOpens the menu.
close( ( )): voidCloses the menu.
toggle( (focusStrategy: FocusStrategynull )): voidToggles the menu.

Example#


See the docs for useSelect in react-aria for an example of useSelectState.