Select
stableDisplays a list of options for the user to pick from, triggered by a button.
Basic usage
Examples
Controlled with groups
Group related options under labelled sections and control the value.
Searchable large options
Use searchable with the virtualized options prop to keep large lists responsive.
Creation flow
Pass onCreateOption to let users create a value when search has no match.
Features
- Can be controlled or uncontrolled.
- Full keyboard support with typeahead.
- Supports items, labels, groups of items.
- Positioning and collision handling.
Installation
pnpm dlx structyl add selectAPI Reference
Select.Root
Contains all select parts.
| Prop | Type | Default |
|---|---|---|
| value | stringControlled value. | — |
| defaultValue | stringInitial value. | — |
| onValueChange | (value: string) => voidCalled when the value changes. | — |
| open | booleanControlled open state. | — |
| onOpenChange | (open: boolean) => voidCalled when open state changes. | — |
| disabled | booleanDisable the select. | false |
| required | booleanMark as required. | false |
| name | stringName for form submission. | — |
| dir | 'ltr' | 'rtl'Reading direction. | — |
| searchable | booleanEnable option search. | false |
| searchValue | stringControlled search value. | — |
| onSearchValueChange | (value: string) => voidCalled when search text changes. | — |
| filterOption | (option, searchValue) => booleanCustomize option matching. | — |
| onCreateOption | (value: string) => voidCalled when a new option is created. | — |
| createOptionLabel | ReactNode | (value) => ReactNodeCustomize the create option label. | — |
| resetSearchOnClose | booleanClear search when the popup closes. | true |
Select.Trigger
The button that opens the listbox.
| Prop | Type | Default |
|---|---|---|
| className | stringAdditional Tailwind classes, merged with the component defaults. | — |
Select.Value
Displays the selected value.
| Prop | Type | Default |
|---|---|---|
| placeholder | ReactNodeShown when no value is selected. | — |
Select.SearchInput
Search field shown when the root is searchable.
| Prop | Type | Default |
|---|---|---|
| className | stringAdditional Tailwind classes, merged with the component defaults. | — |
Select.Content
The listbox popup.
| Prop | Type | Default |
|---|---|---|
| position | 'item-aligned' | 'popper'Positioning strategy. | 'popper' |
| side | 'top' | 'right' | 'bottom' | 'left'Preferred side. | — |
| align | 'start' | 'center' | 'end'Alignment. | — |
| options | SelectOption[]Array-backed options rendered with windowing. | — |
| optionHeight | numberVirtual row height in pixels. | 36 |
| optionOverscan | numberExtra rows rendered above and below the viewport. | 6 |
Select.Item
A selectable option.
| Prop | Type | Default |
|---|---|---|
| value | stringThe value submitted when selected. | — |
| disabled | booleanDisable the option. | false |
| textValue | stringOverride the typeahead text. | — |
Select.CreateItem
Creates the current search text with `onCreateOption`.
| Prop | Type | Default |
|---|---|---|
| className | stringAdditional Tailwind classes, merged with the component defaults. | — |
Select.Options
Virtualized renderer for large array-backed option lists.
| Prop | Type | Default |
|---|---|---|
| options | SelectOption[]Options to render. | — |
| itemHeight | numberRow height in pixels. | 36 |
| overscan | numberExtra rows rendered outside the viewport. | 6 |
Select.Group
Groups related items.
| Prop | Type | Default |
|---|
Select.Label
A group label.
| Prop | Type | Default |
|---|
Select.Separator
A visual divider.
| Prop | Type | Default |
|---|
Keyboard interactions
Adheres to the WAI-ARIA design pattern .
| Key | Description |
|---|---|
| Space / Enter | Opens the select / selects the focused item. |
| ArrowDown / ArrowUp | Moves focus between options. |
| Esc | Closes the select. |