structyl

Select

stable

Displays 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

bash
pnpm dlx structyl add select

API Reference

Select.Root

Contains all select parts.

PropTypeDefault
valuestring

Controlled value.

defaultValuestring

Initial value.

onValueChange(value: string) => void

Called when the value changes.

openboolean

Controlled open state.

onOpenChange(open: boolean) => void

Called when open state changes.

disabledboolean

Disable the select.

false
requiredboolean

Mark as required.

false
namestring

Name for form submission.

dir'ltr' | 'rtl'

Reading direction.

searchableboolean

Enable option search.

false
searchValuestring

Controlled search value.

onSearchValueChange(value: string) => void

Called when search text changes.

filterOption(option, searchValue) => boolean

Customize option matching.

onCreateOption(value: string) => void

Called when a new option is created.

createOptionLabelReactNode | (value) => ReactNode

Customize the create option label.

resetSearchOnCloseboolean

Clear search when the popup closes.

true

Select.Trigger

The button that opens the listbox.

PropTypeDefault
classNamestring

Additional Tailwind classes, merged with the component defaults.

Select.Value

Displays the selected value.

PropTypeDefault
placeholderReactNode

Shown when no value is selected.

Select.SearchInput

Search field shown when the root is searchable.

PropTypeDefault
classNamestring

Additional Tailwind classes, merged with the component defaults.

Select.Content

The listbox popup.

PropTypeDefault
position'item-aligned' | 'popper'

Positioning strategy.

'popper'
side'top' | 'right' | 'bottom' | 'left'

Preferred side.

align'start' | 'center' | 'end'

Alignment.

optionsSelectOption[]

Array-backed options rendered with windowing.

optionHeightnumber

Virtual row height in pixels.

36
optionOverscannumber

Extra rows rendered above and below the viewport.

6

Select.Item

A selectable option.

PropTypeDefault
valuestring

The value submitted when selected.

disabledboolean

Disable the option.

false
textValuestring

Override the typeahead text.

Select.CreateItem

Creates the current search text with `onCreateOption`.

PropTypeDefault
classNamestring

Additional Tailwind classes, merged with the component defaults.

Select.Options

Virtualized renderer for large array-backed option lists.

PropTypeDefault
optionsSelectOption[]

Options to render.

itemHeightnumber

Row height in pixels.

36
overscannumber

Extra rows rendered outside the viewport.

6

Select.Group

Groups related items.

PropTypeDefault

Select.Label

A group label.

PropTypeDefault

Select.Separator

A visual divider.

PropTypeDefault

Keyboard interactions

Adheres to the WAI-ARIA design pattern .

KeyDescription
Space / EnterOpens the select / selects the focused item.
ArrowDown / ArrowUpMoves focus between options.
EscCloses the select.
Select | structyl