VisorVisor
ComponentsForm

Combobox

An autocomplete input with a filterable dropdown list. Supports controlled and uncontrolled modes.

Filterable List

Empty State

Keyboard

Type to filter: the first match is highlighted, so typing "new y" then Enter picks New York. Arrow Down and Arrow Up move the highlight (Oregon is disabled and is skipped), Home and End jump to the ends, Enter picks, Escape closes and a second Escape clears the text. Tab picks nothing. Focus stays in the text field throughout.

Installation

npx visor add combobox

This copies two files into your project:

  • components/ui/combobox/combobox.tsx — the component
  • components/ui/combobox/combobox.module.css — the styles

Usage

import {
  Combobox,
  ComboboxInput,
  ComboboxContent,
  ComboboxItem,
  ComboboxEmpty,
} from '@/components/ui/combobox/combobox';

<Combobox>
  <ComboboxInput placeholder="Pick a fruit..." />
  <ComboboxContent>
    <ComboboxItem value="apple">Apple</ComboboxItem>
    <ComboboxItem value="banana">Banana</ComboboxItem>
    <ComboboxEmpty>No results found.</ComboboxEmpty>
  </ComboboxContent>
</Combobox>

API Reference

ComboboxProps

PropTypeDefaultDescription
inputValuestring—Controlled value of the search input.
onInputChange(value: string) => void—Callback when the input value changes.
valuestring—Controlled selected value.
onSelect(value: string) => void—Callback when an item is selected.
openboolean—Controlled open state of the dropdown.
onOpenChange(open: boolean) => void—Callback when the open state changes.

Sub-components

ComponentElementPurpose
Combobox<div>Root provider managing open state, input value, and selection
ComboboxInput<input>Text input with role="combobox" for typing and filtering
ComboboxContent<div> (portal)Popover dropdown containing the listbox
ComboboxItem<li>Selectable option with role="option" and check indicator
ComboboxEmpty<li>Placeholder shown when no options match the filter
ComboboxGroup<li>Groups related options under an optional heading
ComboboxSeparator<li>Visual divider between groups or items

Accessibility

  • Input renders with role="combobox", aria-expanded, and aria-autocomplete="list"
  • The dropdown list renders with role="listbox"; each option has role="option"
  • Focus stays in the input; aria-activedescendant names the highlighted option, and each option has a stable id
  • Keyboard: typing highlights the first match; Arrow Down opens the list and moves down, Arrow Up moves up, Home/End jump to the ends (no wrap), disabled options are skipped; Enter picks, Escape closes (a second Escape clears the text), Tab picks nothing
  • Hovering an option moves the same highlight the keys move
  • Screen readers announce the number of available options when the list opens