useSelect

Provides the behavior and accessibility implementation for a select component. A select displays a collapsible list of options and allows a user to select one of them.

Favorite Animal
Example
Select.tsx
DropdownListBox.tsx
Select.css
Button.css
Form.css
ListBox.css
Popover.css
import {Select, SelectItem} from './Select';

<Select label="Favorite Animal">
  <SelectItem>Aardvark</SelectItem>
  <SelectItem>Cat</SelectItem>
  <SelectItem>Dog</SelectItem>
  <SelectItem>Kangaroo</SelectItem>
  <SelectItem>Panda</SelectItem>
  <SelectItem>Snake</SelectItem>
</Select>

API

useSelectState<T, M extends = 'single'>(props: <T, M>): <T, M>useSelect<T, M extends = 'single'>( props: <T, M>, state: <T, M>, ref: <HTMLElementnull> ): <T, M>

SelectState

Properties

NameType
selectedItems<T>[]

The value of the selected items.

isFocusedboolean

Whether the select is currently focused.

focusStrategynull

Controls which item will be auto focused when the menu opens.

collection<<T>>

A collection of items in the list.

selectionManager

A selection manager to read and update multiple selection state.

pointnull

The cursor position when the overlay was triggered, relative to the window viewport.

realtimeValidation

Realtime validation results, updated as the user edits the value.

displayValidation

Currently displayed validation results, updated when the user commits their changes.

disabledKeysSet<Key>

A set of items that are disabled.

value<>

The current select value.

defaultValue<>

The default select value.

Methods

setValue(value: Keyreadonly Key[]null): void
Sets the select value.
setFocused(isFocused: boolean): void
Sets whether the select is focused.
open(focusStrategy?: null): void
Opens the menu.
toggle(focusStrategy?: null): void
Toggles the menu.
setOpen(isOpen: boolean): void
Sets whether the overlay is open.
close(): void
Closes the overlay.
setPoint(point: ): void
Sets the cursor position relative to the window viewport.
updateValidation(result: ): void
Updates the current validation result. Not displayed to the user until commitValidation is called.
resetValidation(): void
Resets the displayed validation state to valid when the user resets the form.
commitValidation(): void
Commits the realtime validation so it is displayed to the user.

AriaSelectOptions

NameType
keyboardDelegate

An optional keyboard delegate implementation for type to select, to override the default.

allowsEmptyCollectionboolean

Whether the select should be allowed to be open when the collection is empty.

isDisabledboolean

Whether the input is disabled.

placeholderstring

Temporary text that occupies the text input when it is empty.

itemsIterable<T>

Item objects in the collection.

selectionMode

Whether single or multiple selection is enabled.

disabledKeysIterable<Key>

The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.

value<>

The current value (controlled).

defaultValue<>

The default value (uncontrolled).

onChange(value: <>) => void

Handler that is called when the value changes.

SelectAria

NameType
labelPropsDOMAttributes

Props for the label element.

triggerProps

Props for the popup trigger element.

valuePropsDOMAttributes

Props for the element representing the selected value.

menuProps<T>

Props for the popup.

descriptionPropsDOMAttributes

Props for the select's description element, if any.

errorMessagePropsDOMAttributes

Props for the select's error message element, if any.

hiddenSelectProps<T, >

Props for the hidden select element.

validationDetailsValidityState

The native validation details for the input.