Skip to content

Combobox

combobox

A text field that filters a list as you type, with one value chosen from the results. Composable parts, so the field can hold a plain value, an object with a label, or several of either. Filtering, keyboard navigation and the active option being announced all come from Base UI.

Install

$npxshadcnadd@forme/combobox

Adds the component, its registry dependencies, and the token stylesheet you import once.

Usage

import {
  Combobox,
  ComboboxContent,
  ComboboxInput,
  ComboboxInputGroup,
  ComboboxItem,
  ComboboxList,
} from "@/components/forme/combobox/combobox";

<Combobox items={currencies}>
  <ComboboxInputGroup>
    <ComboboxInput placeholder="Search currencies…" />
  </ComboboxInputGroup>
  <ComboboxContent>
    <ComboboxList>
      {(item) => <ComboboxItem key={item.value} value={item}>{item.label}</ComboboxItem>}
    </ComboboxList>
  </ComboboxContent>
</Combobox>

When to use

Reach for it

  • Picking one value from a list long enough that typing is faster than scrolling.
  • Grouped options: wrap each set in ComboboxGroup with a ComboboxLabel, and the search still spans the whole list.
  • Options that are objects rather than strings: pass itemToStringLabel and the field echoes the label while the form submits the value.

Use something else

  • A short fixed list; a Select shows every option at once and costs one click.
  • Choosing several values; that is a MultiSelect, which is the same primitive with chips.
  • Free text with no list behind it; that is an Input.

API reference

Read from the source, so it is the API of the file you install. A prop marked * is required.

ComboboxValue

PropTypeDefaultDescription
classNamestring—

Also takes every prop of Base UI Combobox.Value.

ComboboxItem

One option.

PropTypeDefaultDescription
destructiveboolean—Renders destructive: for an option the reader should think twice about.

Also takes every prop of Base UI Combobox.Item.

The other parts

  • ComboboxTakes ComponentProps<typeof ComboboxPrimitive.Root<Value, Multiple, Item>>
  • ComboboxInputGroupTakes Base UI Combobox.InputGroup
  • ComboboxInputTakes Base UI Combobox.Input
  • ComboboxTriggerTakes Base UI Combobox.Trigger
  • ComboboxClearTakes Base UI Combobox.Clear
  • ComboboxContentTakes Base UI Combobox.Popup and Pick<ComponentProps<typeof ComboboxPrimitive.Positioner>, "side" | "sideOffset" | "align">
  • ComboboxListTakes Base UI Combobox.List
  • ComboboxEmptyTakes Base UI Combobox.Empty
  • ComboboxGroupTakes Base UI Combobox.Group
  • ComboboxCollectionTakes Base UI Combobox.Collection
  • ComboboxLabelTakes Base UI Combobox.GroupLabel
  • ComboboxSeparatorTakes Base UI Combobox.Separator

Accessibility

  • Base UI supplies the combobox and listbox roles, aria-activedescendant on the highlighted option, and arrow keys, Home and End.
  • Typing filters without closing the popup, so the results are announced as the list shrinks.
  • The empty state stays mounted so a screen reader hears that there are no matches; it is :empty that hides it, not a conditional render.

Motion

  • The popup grows from its trigger and exits faster than it enters, both on the shared tokens.
  • The trigger's chevron rotates while the popup is open; nothing else moves, so the list does not shift under the pointer.

Responsive behaviour

  • The popup matches the field's width and is clamped to the room above or below it, so a long list scrolls instead of leaving the viewport.