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

`data-ui="combobox"` · Text input that filters a list of options.

## Import

```tsx
import { Combobox, ComboboxContent, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxSeparator } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';
import { Field, FieldLabel } from '@slotted/react/field';

const CUSTOMERS = [
  { id: 'brightline', name: 'Brightline Studio' },
  { id: 'harbor-pine', name: 'Harbor & Pine' },
  { id: 'northgate', name: 'Northgate Labs' },
  { id: 'quill', name: 'Quill & Co.' },
  { id: 'solstice', name: 'Solstice Outdoor' },
  { id: 'verde', name: 'Verde Kitchen' },
  { id: 'atlas', name: 'Atlas Freight' },
  { id: 'juniper', name: 'Juniper Health' },
];

export default function ComboboxBasic() {
  return (
    <Field>
      <FieldLabel>Customer</FieldLabel>
      <Combobox>
        <ComboboxInput placeholder="Search customers" />
        <ComboboxContent>
          {CUSTOMERS.map((customer) => (
            <ComboboxItem key={customer.id} value={customer.id}>
              {customer.name}
            </ComboboxItem>
          ))}
        </ComboboxContent>
      </Combobox>
    </Field>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, rendered by ComboboxInput | yes |
| `input` | input with role="combobox" | yes |
| `trigger` | button | yes |
| `arrow` | span | yes |
| `busy` | span | no |
| `clear` | button | no |
| `positioner` | div, rendered by ComboboxContent | yes |
| `content` | div with role="listbox" | yes |
| `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 |
| `match` | mark | no |
| `description` | span | no |
| `separator` | div with role="separator" | no |
| `empty` | div | no |
| `status` | div with role="status" and aria-live="polite" | yes |
| `placeholder` | div | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `inputValue` | `string` | — | Combobox | The text in the input. Passing it makes the text controlled. |
| `defaultInputValue` | `string` | — | Combobox | The initial text of an uncontrolled input, read once. |
| `value` | `string \| null` | — | Combobox | The key of the chosen option, which is separate from the typed text. Passing it makes the value controlled. |
| `defaultValue` | `string \| null` | — | Combobox | The initial value of an uncontrolled combobox. It sets the key, not the text. |
| `open` | `boolean` | — | Combobox | Whether the popup is open. Passing it makes the open state controlled. |
| `defaultOpen` | `boolean` | false | Combobox | Whether an uncontrolled popup starts open. |
| `highlightedValue` | `string \| null` | — | Combobox | The key of the highlighted option, which is separate from the chosen one. |
| `defaultHighlightedValue` | `string \| null` | — | Combobox | The initial highlight of an uncontrolled combobox. |
| `filter` | `((label, query) => boolean) \| null` | — | Combobox | The comparison between a label and the query. Unset uses a locale-sensitive contains; null turns filtering off for a list a server has already filtered. |
| `locale` | `string` | — | Combobox | The BCP 47 language of the default filter. The active locale when unset. |
| `items` | `ComboboxItems` | — | Combobox | Labels for values, so a closed combobox can show the label of an option it has not rendered. |
| `name` | `string` | — | Combobox | The name the value is submitted under. Renders a hidden input that carries the chosen key. |
| `form` | `string` | — | Combobox | The id of the form the value is submitted with, when it is not the enclosing one. |
| `total` | `number` | — | Combobox | The size of the whole collection, written to aria-setsize on each option. |
| `autocomplete` | `'none' \| 'list' \| 'both'` | list | Combobox | What typing does: none keeps every option, list filters the options, and both also completes the first match inline. Written to aria-autocomplete. |
| `openOn` | `'input' \| 'focus' \| 'manual'` | input | Combobox | When the popup opens without the trigger: on typing or a press on the input (input), on every focus and press (focus), or only from the trigger and the arrow keys (manual). |
| `allowsCustomValue` | `boolean` | false | Combobox | Whether text that matches no option becomes the value on Enter or blur. |
| `autoHighlight` | `boolean` | false | Combobox | Whether the first match is highlighted when the popup opens and after each query typed, so Enter takes it. A chosen option that is showing takes precedence. |
| `highlightMatch` | `boolean` | true | Combobox | Whether the part of each label the query matched is marked. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Combobox | The control size. Unset follows the enclosing field. |
| `variant` | `'outline' \| 'subtle' \| 'plain'` | outline | Combobox | How much frame the control draws. |
| `side` | `'bottom' \| 'top' \| 'inline-start' \| 'inline-end' \| 'left' \| 'right'` | bottom | Combobox | The edge of the control the popup opens from. |
| `align` | `'start' \| 'center' \| 'end'` | start | Combobox | The alignment of the popup along that edge. |
| `width` | `'anchor' \| 'content'` | content | Combobox | The popup width: content keeps it 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 | Combobox | When the popup exists in the DOM: only while open, from the first open, or from the start. |
| `strategy` | `'absolute' \| 'fixed'` | absolute | Combobox | The CSS positioning the popup uses. |
| `clearable` | `boolean` | true | Combobox | Whether a clear button appears once the input holds text. |
| `loop` | `boolean` | false | Combobox | Whether ArrowDown and ArrowUp wrap at the ends of the list. |
| `closeOnSelect` | `boolean` | true | Combobox | Whether choosing an option closes the popup. |
| `closeOnEscape` | `boolean` | true | Combobox | Whether Escape closes the popup. |
| `closeOnOutsidePress` | `boolean` | true | Combobox | Whether a press outside the combobox closes the popup. |
| `flip` | `boolean` | true | Combobox | Whether the popup moves to the opposite side when it does not fit. |
| `shift` | `boolean` | true | Combobox | Whether the popup slides along its side to stay in view. |
| `hideWhenDetached` | `boolean` | true | Combobox | Whether the popup hides once the control scrolls out of view. |
| `portal` | `boolean` | true | Combobox | Whether the popup renders at the end of the document instead of inside the combobox. |
| `fullWidth` | `boolean` | true | Combobox | Whether the control fills its container or keeps its own width. |
| `disabled` | `boolean` | false | Combobox | Turns off the input, the trigger and the popup. Unset follows the enclosing field. |
| `readOnly` | `boolean` | false | Combobox | Keeps the text selectable and copyable and never opens the popup. Unset follows the enclosing field. |
| `required` | `boolean` | false | Combobox | Sets the native required attribute on the input. Unset follows the enclosing field. |
| `invalid` | `boolean` | false | Combobox | Draws the border and the focus ring in the invalid tone and sets aria-invalid. Unset follows the enclosing field. |
| `loading` | `boolean` | false | Combobox | Shows the spinner, the placeholder rows and the loading message, and sets aria-busy on the listbox. |
| `sideOffset` | `number` | 4 | Combobox | The gap between the control and the popup, in pixels. |
| `alignOffset` | `number` | 0 | Combobox | How far the popup shifts along its side, in pixels. |
| `collisionPadding` | `number` | 8 | Combobox | The minimum distance between the popup and the edge of the viewport, in pixels. |
| `messages` | `Partial<ComboboxMessages>` | — | Combobox | Phrases that replace the active locale’s, key by key: clear, trigger, create ({query}), empty, loading and count ({count}). |
| `empty` | `ReactNode` | — | ComboboxContent | Replaces the empty message for this popup. |
| `status` | `ReactNode` | — | ComboboxContent | Replaces the message in the status row for this popup. |
| `value` | `string` | — | ComboboxItem | The option key: what the form submits and what onValueChange receives. |
| `disabled` | `boolean` | false | ComboboxItem | Keeps the option in the list, announces it as unavailable, and skips it with every movement key. |
| `textValue` | `string` | — | ComboboxItem | The text the filter compares and the mark splits, when the children are not a string. |
| `description` | `ReactNode` | — | ComboboxItem | The second line under the label. |
| `icon` | `ReactNode` | — | ComboboxItem | The element in the first column. |
| `position` | `number` | — | ComboboxItem | The position of the option in the whole collection, written to aria-posinset. |
| `label` | `ReactNode` | — | ComboboxGroup | The name of the group, which the group references through aria-labelledby. |
| `ComboboxDefaultsProvider` | `component` | — | Application | Sets any axis once for a subtree. The phrases come from the active locale, set by SlottedProvider. |
| `render` | `(props) => ReactNode` | — | ComboboxInput, ComboboxContent | Replaces the frame around the input, or the popup layer. The input and the listbox carry the role and the ARIA wiring, so they cannot be replaced. |
| `ref` | `Ref<ComboboxHandle>` | — | Combobox | focus(), open(), close() and scrollToKey(value), for actions a prop cannot express. |
| `ref` | `Ref<HTMLInputElement>` | — | ComboboxInput | The input element, for code that reads the caret or the selection. |
| `native props` | `ComponentPropsWithRef<…>` | — | every part | Each part accepts the props of its element. Your onKeyDown, placeholder, maxLength or aria-label reaches that element, and the combobox handler runs alongside yours instead of replacing it. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onInputValueChange` | `(value: string, request: ChangeRequest)` | Before the text changes. The reason is keyboard while the reader types, select when an option is chosen, and clear, blur or programmatic otherwise. |
| `onValueChange` | `(value: string \| null, request: ChangeRequest)` | Before the chosen value changes. Typing calls only onInputValueChange; choosing an option calls both, each with the reason select. |
| `onOpenChange` | `(open: boolean, request: ChangeRequest)` | Before the popup opens or closes. The reason tells a selection from a dismissal: select, escape, outsidePress, dismiss, blur, pointer, keyboard or programmatic. |
| `onHighlightedValueChange` | `(value: string \| null, request: ChangeRequest)` | Before the highlight moves, by key or by pointer, and when the filter removes the highlighted option. |
| `onCreate` | `(query: string, details: { reason, source? })` | When the reader takes the create option, which appears while onCreate is set, the query is not empty and nothing matched. The popup closes and nothing is selected: add the option to your collection and select it. |
| `onInputReset` | `(rejected: string, details: { reason: 'blur', source? })` | When the input loses focus holding text that matches no option while allowsCustomValue is off. The text returns to the label of the chosen option, or empties, and the handler receives the rejected text. |
| `onLoadMore` | `()` | When the end of the rendered list scrolls into view. Fetch the next page; the combobox keeps no cursor of its own. |

## 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` |
| `autocomplete` | `none`, `list`, `both` | `list` |
| `openOn` | `input`, `focus`, `manual` | `input` |
| `allowsCustomValue` | `true`, `false` | `false` |
| `autoHighlight` | `true`, `false` | `false` |
| `highlightMatch` | `true`, `false` | `true` |
| `clearable` | `true`, `false` | `true` |
| `loop` | `true`, `false` | `false` |
| `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 input has role="combobox" with aria-autocomplete, aria-expanded and aria-controls. The popup has role="listbox", and each row has role="option". The trigger button is out of the tab sequence, as the ARIA combobox pattern requires.
- Focus stays on the input, so Home, End, ArrowLeft, ArrowRight, Backspace and Delete keep their text-editing behavior. The highlight moves through aria-activedescendant, and the caret does not move with it.
- Escape works in two steps, both named by the pattern. With the popup open, it closes the popup and keeps the text. With the popup closed, it restores the label of the chosen option, and a second press clears the selection.
- The status row is a polite live region. It announces how many options matched, and "Loading…" while a request is in flight.
- Tab commits nothing: an option the reader arrowed past is not a choice, which is where the combobox differs from the select. Tab does accept an inline completion that is still showing.

## Tokens

`--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-combobox-action-active-background`, `--slotted-combobox-action-color`, `--slotted-combobox-action-hover-background`, `--slotted-combobox-action-size`, `--slotted-combobox-arrow-color`, `--slotted-combobox-autofill-background`, `--slotted-combobox-background`, `--slotted-combobox-border-color`, `--slotted-combobox-color`, `--slotted-combobox-completion-background`, `--slotted-combobox-completion-color`, `--slotted-combobox-content-backdrop-filter`, `--slotted-combobox-content-border-color`, `--slotted-combobox-content-padding-block`, `--slotted-combobox-content-padding-inline`, `--slotted-combobox-content-radius`, `--slotted-combobox-content-shadow`, `--slotted-combobox-content-text`, `--slotted-combobox-content-text-muted`, `--slotted-combobox-disabled-background`, `--slotted-combobox-disabled-border-color`, `--slotted-combobox-disabled-color`, `--slotted-combobox-group-label-height`, `--slotted-combobox-highlight`, `--slotted-combobox-highlight-active`, `--slotted-combobox-highlight-ring`, `--slotted-combobox-hover-border-color`, `--slotted-combobox-icon-size-min`, `--slotted-combobox-invalid-border-color`, `--slotted-combobox-invalid-edge-width`, `--slotted-combobox-invalid-focus-ring-color`, `--slotted-combobox-item-radius`, `--slotted-combobox-measure`, `--slotted-combobox-open-border-color`, `--slotted-combobox-placeholder-color`, `--slotted-combobox-plain-hover-background`, `--slotted-combobox-radius`, `--slotted-combobox-readonly-background`, `--slotted-combobox-selected-color`, `--slotted-combobox-separator-color`, `--slotted-combobox-shadow`, `--slotted-combobox-subtle-background`, `--slotted-combobox-subtle-border-color`, `--slotted-combobox-subtle-hover-background`, `--slotted-combobox-surface`, `--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-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-sans`, `--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-shadow-md`, `--slotted-space-1`, `--slotted-space-2`, `--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 [combobox.examples.md](./combobox.examples.md).
