Combobox
- Seaside suite
- Garden room
- Loft
npx shadcn add @klarhimmel/combobox @klarhimmel/inputCopy for AIExamples
Basic
States
Long
DetailsAbout, usage, props and more
A text field that filters a list as you type and picks one option.
When to use
Use for
Long lists people can name: countries, staff, products. They type, the list narrows.
Not for
Fewer than seven options. Use Select. Free text with suggestions. Use Input.
Pairs with
Field, forms.
Preview
- Denmark
- Estonia
- Finland
- Germany
- Iceland
- Latvia
- Lithuania
- Netherlands
- Norway
- Poland
- Sweden
- United Kingdom
Start typing to narrow the list.
Nothing chosen yet.
Import
Import
- Files
- combobox.tsx, input.tsx, in components/klarhimmel/ui/. With it: button, editing, select, theme, utils. npm: lucide-react.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
options | SelectOption[] | required | Required. Matching is case-insensitive and anywhere in the label. |
value | string | - | Controlled or uncontrolled state. An empty string means nothing chosen. |
defaultValue | string | - | Controlled or uncontrolled state. An empty string means nothing chosen. |
onValueChange | (value: string) => void | - | Controlled or uncontrolled state. An empty string means nothing chosen. |
placeholder | string | - | Placeholder; the message when nothing matches. |
emptyText | string | 'No matches' | Shown when the typed text matches nothing. |
name | string | - | Submits the chosen value with a form (a hidden input). |
id | string | - | |
disabled | boolean | - | Error styling; switches it off. |
invalid | boolean | - | Error styling; switches it off. |
aria-label | string | - | |
aria-labelledby | string | - | |
aria-describedby | string | - | |
className | string | - | Extra classes, merged after the component's own. |
Accessibility
| Key | Does |
|---|---|
Type | Opens the list and filters it; the first match is highlighted |
Down / Up | Opens the list, or moves the highlight |
Enter | Chooses the highlighted option |
Escape | Closes and restores the chosen text; again, clears the field |
Home / End / Left / Right | Move the caret in the text, as in any field |
Tab | Leaves the field; unmatched text is replaced by the chosen label |
The WAI-ARIA combobox with list autocomplete. The number of matches is announced as you type.
Accessibility