Select
Picks one of many options from a list that opens next to the field, with keyboard selection.
Stability: experimental
Props
| Prop | Type | Default | Means |
|---|---|---|---|
label | string | The text above the field, and its accessible name. | |
options | { value: string; label: string }[] | The choices, in order. | |
value | string | bindable("") | The chosen option's value. Bind it with bind:value={name}. |
placeholder | string | Choose | Shown, muted, while nothing is chosen. |
disabled | boolean | false | The field cannot be opened or focused. |
States
| State | Looks like |
|---|---|
closed | A 44px field with a border, the chosen label (or the muted placeholder) and a chevron. |
open | The 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 option | The raised background. |
disabled | Raised background at 60% opacity, and the label at 50%. |
Accessibility
| role | combobox (a button) that controls a listbox of options with aria-selected |
| name | The label prop; each option by its text. |
| focus | The field is one Tab stop. On open, focus moves to the chosen option, or the first. On close, focus returns to the field. |
| keyboard | On 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. |
| notes | The 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} />