Combobox
An autocomplete input with a list of suggestions.
Installation
npx shadcn@latest add @uqudo/comboboxInstalling it also installs Button and
Input Group, which it depends on. The behaviour
comes from the Combobox primitive in @base-ui/react.
Usage
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/uqudo/ui/combobox"const frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"]
<Combobox items={frameworks}>
<ComboboxInput placeholder="Select a framework" />
<ComboboxContent>
<ComboboxEmpty>No results.</ComboboxEmpty>
<ComboboxList>
{(item) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>Pass the options to items on the root and render each one through the
function child of ComboboxList. Base UI filters the list against the input for
you. Items can be strings or { value, label } objects; for other shapes provide
itemToStringLabel.
Examples
Multiple
Add multiple and swap the input for ComboboxChips. ComboboxValue receives
the selected values so you can render a ComboboxChip per value, and the popup
is anchored to the chips container through useComboboxAnchor.
API Reference
Combobox
The Base UI Combobox.Root, re-exported unchanged. The most used props:
Prop
Type
ComboboxInput
Renders the text input inside an Input Group with the trigger button at the end.
Prop
Type
ComboboxContent
Portal, positioner and popup in one. Positioning props are forwarded to the positioner.
Prop
Type
ComboboxList
Prop
Type
ComboboxItem
Prop
Type
ComboboxChips
Container for the selected values in a multiple combobox. Attach the ref from
useComboboxAnchor and pass the same ref to ComboboxContent's anchor.
ComboboxChip
Prop
Type
Other parts
| Component | Wraps | Notes |
|---|---|---|
ComboboxChipsInput | Combobox.Input | Bare input for use inside ComboboxChips. |
ComboboxTrigger | Combobox.Trigger | Button that opens the popup; appends a chevron icon. |
ComboboxValue | Combobox.Value | Renders the selection; accepts a function child. |
ComboboxGroup | Combobox.Group | Groups items. |
ComboboxLabel | Combobox.GroupLabel | Heading for a group. |
ComboboxCollection | Combobox.Collection | Renders a nested list of items, useful inside groups. |
ComboboxEmpty | Combobox.Empty | Only visible when no item matches. |
ComboboxSeparator | Combobox.Separator | Horizontal rule between items. |
useComboboxAnchor() | React.useRef | Returns the ref shared by ComboboxChips and the content. |