Duolith docs

Select

Picks one of many options from a list that opens next to the field, with keyboard selection.

Stability: experimental

Props

PropTypeDefaultMeans
labelstringThe text above the field, and its accessible name.
options{ value: string; label: string }[]The choices, in order.
valuestringbindable("")The chosen option's value. Bind it with bind:value={name}.
placeholderstringChooseShown, muted, while nothing is chosen.
disabledbooleanfalseThe field cannot be opened or focused.

States

StateLooks like
closedA 44px field with a border, the chosen label (or the muted placeholder) and a chevron.
openThe field's border turns primary; the list opens below it, at least as wide, flipping above when there is no room, with a check on the chosen option.
focused optionThe raised background.
disabledRaised background at 60% opacity, and the label at 50%.

Accessibility

rolecombobox (a button) that controls a listbox of options with aria-selected
nameThe label prop; each option by its text.
focusThe field is one Tab stop. On open, focus moves to the chosen option, or the first. On close, focus returns to the field.
keyboardOn the field: Enter, Space, ArrowDown or ArrowUp opens it. In the list: ArrowDown and ArrowUp move, wrapping; Home and End go to the ends; typing letters goes to the next option that starts with them; Enter or Space chooses and closes; Escape or Tab closes without choosing.
notesThe field carries aria-haspopup="listbox", aria-expanded and aria-controls.

Theme tokens

color.surface color.border color.primary color.raised color.ink color.muted shadow.lg radius.md radius.sm space.1 space.3 text.label text.body

Example

<Select label="Country" options={countries} bind:value={country} />