Combobox
Finds one thing in a known set as you type, from a list that opens under the field.
Configurations
Supported configurations for this component.
Configurations
3 examplesAdd to your project
One command adds this component to your project.
Run the following command. New project? Run npx shadcn@latest init first to set up Tailwind and path aliases.
npx shadcn@latest add @aicanvas/••••••••••••Light and dark both come with the install and follow the dark class on <html>, the shadcn dark mode setup (next-themes with attribute="class").
Props
Every prop this component accepts. Any other prop is forwarded to the underlying element.
ComboboxOption
| Prop | Type | Default | Description |
|---|---|---|---|
| idreq | string | - | Stable key; also what the caller matches on in `onSelect`. |
| labelreq | string | - | The row's title, and what the default filter searches. |
| icon | React.ComponentType | - | Phosphor icon shown as the row's plain leading glyph, sized by the row's rung. |
| meta | React.ReactNode | - | Trailing metadata, read not clicked (a value, a date): 10px on text.muted. |
| keywords | string[] | - | Extra words the default filter matches besides the label. |
Combobox
| Prop | Type | Default | Description |
|---|---|---|---|
| optionsreq | ComboboxOption[] | - | Everything the field can find. The list shows the ones `filter` keeps for the typed query. |
| onSelectreq | (option: ComboboxOption) => void | - | Called with the picked option, by Enter on the cursor row or a click. |
| value | string | - | Controlled query (the typed text). Pair with `onValueChange`. |
| defaultValue | string | '' | Initial query of an uncontrolled field. |
| defaultOpen | boolean | false | Show the results list at mount, without taking focus, when the field starts with a query. From then on it closes and opens as usual. For a page that documents the list. |
| onValueChange | (query: string) => void | - | Called on every keystroke, and with '' when a pick clears the field. |
| filter | (option: ComboboxOption, query: string) => boolean | - | Which options match the trimmed query. Defaults to a case-insensitive "includes" over the label and the keywords. |
| size | 'sm'|'md' | 'md' | Rung of the field (28 or 32px tall), and of the result rows unless `listSize` says otherwise. |
| listSize | 'sm'|'md' | - | Rung of the result rows: 12px title and 16px glyph, or 14px and 18px. Defaults to `size`. A compact field in a top bar keeps md rows, so the results stay readable under a small field. |
| placeholder | string | 'Search anything' | Text shown in the empty field. |
| ariaLabel | string | - | Accessible name of the input. Defaults to the placeholder. |
| shortcut | string|null | '⌘ K' | The field's keycap. Pass null to hide it. The caller binds the key itself, to the forwarded ref. |
| emptyText | (query: string) => React.ReactNode | - | The line shown when nothing matches, given the trimmed query. Defaults to Nothing matches “query”. |
| clearOnSelect | boolean | true | Empty the field after a pick. Set false to leave the query in place. |
| width | string|number | '100%' | Width of the field, any CSS length. The list matches it. |
| className | string | - | Class on the outer wrapper. |
| style | React.CSSProperties | - | Inline styles merged onto the outer wrapper. |