Skip to content
synccn

Combobox

Select with a search box for long lists.

Installation

$ pnpm dlx shadcn@latest add @synccn/combobox

First time in this project? Connect synccn with one command.

Usage

import { Combobox } from "@/components/ui/combobox";<Combobox options={zones} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

Combobox

Searchable select. options: [{ value, label, hint? }]

  • optionsrequired
    ComboboxOption[]

    Choices.

  • value
    string

    Controlled value.

  • defaultValue
    string

    Initial value when uncontrolled.

  • onValueChange
    (value: string | undefined) => void

    Called with the new value (undefined when cleared).

  • placeholder
    string

    Default "Select…"

    Shown when nothing is selected.

  • searchPlaceholder
    string

    Default "Search…"

    Placeholder for the search field.

  • empty
    React.ReactNode

    Default "No matches. Try a different word."

    Shown when the search matches nothing.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseAutoSide (flips to the side with room), useClickOutside (closes on an outside click), useControllable (works controlled or uncontrolled), useEscape (closes on Escape), usePresence (animates in and out)

npm packages

Keyboard

  • ↓or↑Move through matching options
  • EnterChoose the highlighted option
  • EscClose the list

Accessibility

  • Typing filters the list; the input keeps focus while you move through options.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: combobox, listbox, option
  • ARIA attributes: aria-expanded, aria-selected
  • Keys handled: ArrowUp, ArrowDown, Enter
  • Closes with Escape
  • Closes when you click or tap outside
  • Flips to whichever side has room, so it stays on screen
  • Shows a visible focus ring for keyboard users