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.1
usageimport {useSelectState} from '@react-stately/select'

API#


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

Interface#


Properties

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

Methods

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

Example#


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