<!-- index: /slotted/llms.txt -->
# select

`data-ui="select"` · Picks one option from a popup list.

## Import

```tsx
import { Select, SelectContent, SelectGroup, SelectItem, SelectSeparator, SelectTrigger, SelectValue } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@slotted/react/select';

const WAREHOUSES = [
  { value: 'RNO', label: 'Reno, NV' },
  { value: 'CMH', label: 'Columbus, OH' },
  { value: 'SAV', label: 'Savannah, GA' },
];

export default function SelectBasic() {
  return (
    <Field>
      <FieldLabel>Fulfilment warehouse</FieldLabel>
      <Select>
        <SelectTrigger>
          <SelectValue placeholder="Choose a warehouse" />
        </SelectTrigger>
        <SelectContent>
          {WAREHOUSES.map((warehouse) => (
            <SelectItem key={warehouse.value} value={warehouse.value}>
              {warehouse.label}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
      <FieldDescription>New orders ship from this warehouse.</FieldDescription>
    </Field>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, rendered by SelectTrigger | yes |
| `trigger` | button with role="combobox" | yes |
| `value` | span, rendered by SelectValue | yes |
| `arrow` | span | yes |
| `busy` | span | no |
| `tags` | span | no |
| `summary` | span | no |
| `clear` | button | no |
| `positioner` | div, rendered by SelectContent | yes |
| `backdrop` | div | no |
| `content` | div with role="listbox", or role="dialog" under search and in the sheet | yes |
| `grip` | span | no |
| `header` | div | no |
| `title` | div | no |
| `search` | div, drawn only under search | no |
| `search-icon` | span, aria-hidden | no |
| `search-input` | input with role="combobox" | no |
| `list` | div with role="listbox", drawn only under search | no |
| `chosen` | div, aria-hidden, drawn while several values are chosen | no |
| `match` | mark, the match part of the highlight family, whose root sits inside label | no |
| `group` | div with role="group" | no |
| `group-label` | div | no |
| `item` | div with role="option" | yes |
| `indicator` | span | yes |
| `icon` | span | no |
| `label` | span | yes |
| `description` | span | no |
| `separator` | div with role="separator" | no |
| `empty` | div | no |
| `status` | div with role="status" | no |
| `placeholder` | div | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `search` | `boolean` | false | Select | Puts a search field at the top of the list. The list becomes a dialog, DOM focus moves into the search field, and typeahead turns off. |
| `searchValue` | `string` | — | Select | The search query. Passing it makes the query controlled. It is never the selection. |
| `defaultSearchValue` | `string` | '' | Select | The query an uncontrolled search field starts with. Read once. |
| `filter` | `((label: string, query: string) => boolean) \| null` | createFilter | Select | Decides whether an option matches the query. Unset uses a locale-sensitive contains that ignores case and accents. null turns filtering off, for a list a server has already filtered. A function replaces the comparison. |
| `highlightMatch` | `boolean` | true | Select | Whether the span of a label that matched the query is marked. |
| `locale` | `string` | — | Select | The BCP 47 language the default filter compares in. Defaults to the language in force. |
| `searchProps` | `SelectSearchProps` | — | SelectContent | Props for the search field: every native input attribute, icon, and render to replace the row around the field. |
| `value` | `string \| string[] \| null` | — | Select | The chosen value, or values when multiple is set. Passing it makes the selection controlled. |
| `defaultValue` | `string \| string[] \| null` | — | Select | The value an uncontrolled select starts with, and the value a form reset restores. Read once. |
| `open` | `boolean` | — | Select | Whether the list is open. Passing it makes the open state controlled. |
| `defaultOpen` | `boolean` | false | Select | Whether an uncontrolled select starts open. |
| `highlightedValue` | `string \| null` | — | Select | The highlighted option. Passing it makes the highlight controlled. The highlight is where the keyboard is, not what is chosen. |
| `defaultHighlightedValue` | `string \| null` | — | Select | The option an uncontrolled highlight starts on. |
| `items` | `SelectItems` | — | Select | Values with their labels, read before any option renders. Without it, a held value takes its label from its SelectItem: while the list is closed and a held value has no label, the options render once outside the document and register theirs. Pass items when the options are not rendered until the list opens, such as options fetched on open. |
| `name` | `string` | — | Select | The name the value is submitted under. It renders a hidden native select, which FormData reads and a form reset restores. |
| `form` | `string` | — | Select | The id of the form the control belongs to, when it is not the enclosing form. |
| `total` | `number` | — | Select | The size of the whole collection when only part of it is rendered. Options with position then carry aria-setsize and aria-posinset. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Select | The step of the control scale. When unset, the select takes the size of its field. |
| `variant` | `'outline' \| 'subtle' \| 'plain'` | outline | Select | How much frame the control draws: an outline, a filled subtle frame, or plain, with no frame at rest. |
| `side` | `'bottom' \| 'top' \| 'inline-start' \| 'inline-end' \| 'left' \| 'right'` | bottom | Select | The edge of the control the list opens from. |
| `align` | `'start' \| 'center' \| 'end'` | start | Select | Where the list aligns along that edge. |
| `width` | `'anchor' \| 'content'` | content | Select | content keeps the list at least as wide as the control and widens it to its longest option; anchor pins it to the width of the control. |
| `mount` | `'active' \| 'lazy' \| 'eager'` | active | Select | When the list exists in the DOM: active while it is open, lazy from the first open on, eager from the start. |
| `strategy` | `'absolute' \| 'fixed'` | absolute | Select | The CSS position the positioner gives the list. |
| `multiple` | `boolean` | false | Select | Allows several values. The value becomes an array, and the list stays open as options are chosen. |
| `clearable` | `boolean` | false | Select | Draws a clear button once something is chosen. |
| `loop` | `boolean` | false | Select | Whether the arrow keys wrap from the last option to the first. |
| `typeahead` | `boolean` | true | Select | Whether typing the first letters of a label highlights the matching option. Off while search is set. |
| `typeaheadTimeout` | `number` | 500 | Select | How long typed letters keep building one search, in milliseconds. |
| `closeOnSelect` | `boolean` | true | Select | Whether choosing an option closes the list. A multiple select stays open regardless. |
| `closeOnEscape` | `boolean` | true | Select | Whether Escape closes the list. |
| `closeOnOutsidePress` | `boolean` | true | Select | Whether a press outside the list closes it. |
| `flip` | `boolean` | true | Select | Whether the list may open on the opposite side when it does not fit. |
| `shift` | `boolean` | true | Select | Whether the list may slide along its edge to stay in view. |
| `hideWhenDetached` | `boolean` | true | Select | Whether the list hides while its control is scrolled out of view. |
| `portal` | `boolean` | true | Select | Whether the list renders at the end of the document instead of inside the control. |
| `presentation` | `'popover' \| 'auto'` | popover | Select, SelectDefaultsProvider | auto draws the listbox in a bottom sheet under (max-width: 480px) and (pointer: coarse): modal, headed by the field’s label, every option at least --slotted-target-min tall, dismissed by its grip, its scrim, Escape and the platform’s way back, with focus given back to the trigger. A select with search keeps its anchored list, because the on-screen keyboard covers the bottom of the screen. |
| `fullWidth` | `boolean` | true | Select | Whether the control fills its container. false sizes it to its widest value. |
| `disabled` | `boolean` | false | Select | Disables the control and takes it out of the tab order. When unset, the select takes the state of its field. |
| `readOnly` | `boolean` | false | Select | Keeps the value visible and focusable and never opens the list. When unset, the select takes the state of its field. |
| `required` | `boolean` | false | Select | Sets aria-required, and the required attribute of the hidden native select. When unset, the select takes the state of its field. |
| `invalid` | `boolean` | false | Select | Sets aria-invalid and draws the border and the focus ring in the danger tone. When unset, the select takes the state of its field. |
| `loading` | `boolean` | false | Select | Shows the spinner, three placeholder rows and the loading message, and sets aria-busy on the listbox. |
| `sideOffset` | `number` | 4 | Select | The gap between the control and the list, in pixels. |
| `alignOffset` | `number` | 0 | Select | How far the list shifts along its edge, in pixels. |
| `collisionPadding` | `number` | 8 | Select | The distance the list keeps from the edges of the viewport, in pixels. |
| `messages` | `Partial<SelectMessages>` | — | Select | Replaces any of the phrases the select writes: clear, remove ({label}), summary ({count}), search, searchPlaceholder, count ({count}), empty and loading. Phrases left out come from the language in force. |
| `placeholder` | `ReactNode` | — | SelectValue | What the control shows while nothing is chosen. |
| `children` | `(values, labels) => ReactNode` | — | SelectValue | A function of the chosen values and their labels that returns what the control shows, in place of the built-in summary. |
| `empty` | `ReactNode` | — | SelectContent | Replaces the empty message for this list. |
| `status` | `ReactNode` | — | SelectContent | Replaces the loading message for this list. |
| `value` | `string` | — | SelectItem | The option’s value: what is submitted and what a change request carries. |
| `disabled` | `boolean` | false | SelectItem | Announces the option as unavailable, keeps it in the list, and skips it with every movement key. |
| `description` | `ReactNode` | — | SelectItem | A second line under the label. |
| `icon` | `ReactNode` | — | SelectItem | An element for the first column, such as an Icon holding a Glyph. |
| `textValue` | `string` | — | SelectItem | The text typeahead and the filter match on, when the label is not plain text. |
| `position` | `number` | — | SelectItem | The option’s one-based place in the whole collection, written as aria-posinset. |
| `label` | `ReactNode` | — | SelectGroup | The group’s heading, which names the group through aria-labelledby. |
| `SelectDefaultsProvider` | `component` | — | Application | Sets any axis once for every select below it. The words come from the language in force, set by SlottedProvider. A prop set on one select still wins. |
| `render` | `(props) => ReactNode` | — | SelectTrigger, SelectContent | Replaces the frame of SelectTrigger or the layer of SelectContent. The button and the listbox carry the role and the wiring, so they cannot be replaced. |
| `ref` | `Ref<SelectHandle>` | — | Select | A handle with focus(), open(), close(), focusSearch() and scrollToKey(value). |
| `ref` | `Ref<HTMLButtonElement>` | — | SelectTrigger | The button element. |
| `native props` | `ComponentPropsWithRef<…>` | — | every part | Each part accepts the props of its own element. Your onClick, onKeyDown or aria-label reaches that element, and the select’s own handler runs alongside yours instead of replacing it. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onValueChange` | `(value: string \| string[] \| null, request: ChangeRequest)` | Before the selection changes. request.reason is pointer, keyboard, clear, select or programmatic, and request.cancel() refuses the change. A form reset reports programmatic. |
| `onOpenChange` | `(open: boolean, request: ChangeRequest)` | Before the list opens or closes. request.reason tells a choice from a dismissal: select, escape, outsidePress, pointer, keyboard, dismiss, blur or programmatic. |
| `onHighlightedValueChange` | `(value: string \| null, request: ChangeRequest)` | Before the highlight moves. request.reason is pointer, keyboard or programmatic. |
| `onSearchValueChange` | `(value: string, request: ChangeRequest)` | Before the query changes. request.reason is keyboard for typing, select when an option is chosen while the list stays open, and clear when Escape empties the field or the list empties it as it opens and closes. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `variant` | `outline`, `subtle`, `plain` | `outline` |
| `side` | `bottom`, `top`, `inline-start`, `inline-end`, `left`, `right` | `bottom` |
| `align` | `start`, `center`, `end` | `start` |
| `width` | `anchor`, `content` | `content` |
| `mount` | `active`, `lazy`, `eager` | `active` |
| `strategy` | `absolute`, `fixed` | `absolute` |
| `multiple` | `true`, `false` | `false` |
| `clearable` | `true`, `false` | `false` |
| `loop` | `true`, `false` | `false` |
| `search` | `true`, `false` | `false` |
| `highlightMatch` | `true`, `false` | `true` |
| `typeahead` | `true`, `false` | `true` |
| `closeOnSelect` | `true`, `false` | `true` |
| `closeOnEscape` | `true`, `false` | `true` |
| `closeOnOutsidePress` | `true`, `false` | `true` |
| `flip` | `true`, `false` | `true` |
| `shift` | `true`, `false` | `true` |
| `hideWhenDetached` | `true`, `false` | `true` |
| `portal` | `true`, `false` | `true` |
| `fullWidth` | `true`, `false` | `true` |
| `disabled` | `true`, `false` | `false` |
| `readOnly` | `true`, `false` | `false` |
| `required` | `true`, `false` | `false` |
| `invalid` | `true`, `false` | `false` |
| `loading` | `true`, `false` | `false` |

## Rules

- The trigger is a button with role="combobox", aria-haspopup="listbox" and aria-expanded. The list is a listbox with an option for each row.
- DOM focus stays on the trigger. aria-activedescendant names the highlighted option, which also carries data-current; chosen options carry aria-selected and data-selected. The highlight is where the keyboard is; the selection is what was chosen.
- A disabled option carries aria-disabled, keeps its place in the list, and is skipped by every movement key, typeahead included.
- Inside a field, the trigger carries the field’s control id, so a press on the label focuses it without opening the list. The trigger also takes the label through aria-labelledby, because the name a label gives a button does not reliably reach a button with role="combobox". Outside a field, give SelectTrigger an aria-label.
- With search, the list is a dialog that holds a search field and a listbox, the trigger sets aria-haspopup="dialog", and focus moves into the search field while the list is open.
- Tab chooses the highlighted option and moves focus on, as the APG select-only example specifies; a native select only closes. Escape closes without choosing.

## Tokens

`--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-focus-ring-offset`, `--slotted-control-font-family`, `--slotted-control-font-size-lg`, `--slotted-control-font-size-md`, `--slotted-control-font-size-sm`, `--slotted-control-gap-lg`, `--slotted-control-gap-md`, `--slotted-control-gap-sm`, `--slotted-control-height-lg`, `--slotted-control-height-md`, `--slotted-control-height-sm`, `--slotted-control-icon-size-lg`, `--slotted-control-icon-size-md`, `--slotted-control-icon-size-sm`, `--slotted-control-inner-size-lg`, `--slotted-control-inner-size-md`, `--slotted-control-inner-size-sm`, `--slotted-control-invalid-edge-width`, `--slotted-control-padding-inline-lg`, `--slotted-control-padding-inline-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-shadow-focus-geometry`, `--slotted-control-surface`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-drawer-border-color`, `--slotted-drawer-radius`, `--slotted-drawer-resizer-line-color`, `--slotted-drawer-scrim`, `--slotted-drawer-scrim-backdrop-filter`, `--slotted-drawer-slide-duration`, `--slotted-drawer-slide-easing`, `--slotted-drawer-slide-exit-duration`, `--slotted-drawer-slide-exit-easing`, `--slotted-drawer-surface`, `--slotted-duration-long`, `--slotted-duration-medium`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-easing-exit`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-color-invalid`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-heading`, `--slotted-font-family-sans`, `--slotted-font-size-md`, `--slotted-font-size-xs`, `--slotted-font-weight-medium`, `--slotted-font-weight-semibold`, `--slotted-line-height-md`, `--slotted-line-height-sm`, `--slotted-overlay-max-block-size`, `--slotted-radius-lg`, `--slotted-radius-none`, `--slotted-scrim`, `--slotted-select-action-active-background`, `--slotted-select-action-color`, `--slotted-select-action-hover-background`, `--slotted-select-action-size`, `--slotted-select-arrow-color`, `--slotted-select-background`, `--slotted-select-border-color`, `--slotted-select-color`, `--slotted-select-content-backdrop-filter`, `--slotted-select-content-border-color`, `--slotted-select-content-padding-block`, `--slotted-select-content-padding-inline`, `--slotted-select-content-radius`, `--slotted-select-content-shadow`, `--slotted-select-content-text`, `--slotted-select-content-text-muted`, `--slotted-select-disabled-background`, `--slotted-select-disabled-border-color`, `--slotted-select-disabled-color`, `--slotted-select-group-label-height`, `--slotted-select-highlight`, `--slotted-select-highlight-active`, `--slotted-select-highlight-ring`, `--slotted-select-hover-border-color`, `--slotted-select-icon-size-min`, `--slotted-select-invalid-border-color`, `--slotted-select-invalid-edge-width`, `--slotted-select-invalid-focus-ring-color`, `--slotted-select-item-radius`, `--slotted-select-measure`, `--slotted-select-open-border-color`, `--slotted-select-placeholder-color`, `--slotted-select-plain-hover-background`, `--slotted-select-radius`, `--slotted-select-readonly-background`, `--slotted-select-search-icon-color`, `--slotted-select-selected-color`, `--slotted-select-separator-color`, `--slotted-select-shadow`, `--slotted-select-subtle-background`, `--slotted-select-subtle-border-color`, `--slotted-select-subtle-hover-background`, `--slotted-select-surface`, `--slotted-shadow-lg`, `--slotted-shadow-md`, `--slotted-space-1`, `--slotted-space-11`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-5`, `--slotted-surface-raised`, `--slotted-surface-sunken`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-accent-border`, `--slotted-tone-accent-surface`, `--slotted-tone-accent-text`, `--slotted-tone-danger-border`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-z-index-popover`

## Examples

See [select.examples.md](./select.examples.md).
