- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Installation#
pnpm dlx shadcn@latest add @zui/comboboxThe CLI writes components/ui/combobox.tsx, installs Button,
Command, Popover,
Icon, Text, Text children and Utils, and adds
lucide-react-native. The list draws in the app's PortalHost; see Add a
portal host.
Usage#
import {
Combobox,
ComboboxChip,
ComboboxChips,
ComboboxChipsInput,
ComboboxClear,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
ComboboxTrigger,
ComboboxValue,
} from '@/components/ui/combobox';const frameworks = ['Next.js', 'SvelteKit', 'Nuxt.js'];
<Combobox items={frameworks} value={framework} onValueChange={setFramework}>
<ComboboxTrigger aria-label="Framework" className="w-64">
<ComboboxValue placeholder="Select a framework" />
</ComboboxTrigger>
<ComboboxContent className="w-64">
<ComboboxInput placeholder="Search framework..." />
<ComboboxEmpty>No items found.</ComboboxEmpty>
<ComboboxList>
{(item) => (
<ComboboxItem key={item.value} value={item.value}>
{item.label}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>;Multiple#
<Combobox multiple items={frameworks} value={chosen} onValueChange={setChosen}>
<ComboboxChips className="w-72">
<ComboboxValue>{(values) => values.map((value) => <ComboboxChip key={value}>{value}</ComboboxChip>)}</ComboboxValue>
<ComboboxChipsInput aria-label="Frameworks" placeholder="Add framework" />
</ComboboxChips>
<ComboboxContent className="w-72">
<ComboboxInput placeholder="Search framework..." />
<ComboboxEmpty>No items found.</ComboboxEmpty>
<ComboboxList>
{(item) => (
<ComboboxItem key={item.value} value={item.value}>
{item.label}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>Clear#
<Combobox items={frameworks} value={framework} onValueChange={setFramework}>
<View className="flex-row items-center gap-1">
<ComboboxTrigger aria-label="Framework" className="w-64">
<ComboboxValue placeholder="Select a framework" />
</ComboboxTrigger>
<ComboboxClear onPress={() => setFramework(null)} />
</View>
{/* ComboboxContent as above */}
</Combobox>API reference#
Combobox#
| Prop | Type | Default |
|---|---|---|
items | string[] | { label: string; value: string }[] | - |
multiple | boolean | false |
value | string | null, or string[] with multiple | - |
defaultValue | string | null, or string[] with multiple | - |
onValueChange | (value: string) => void, or (value: string[]) => void with multiple | - |
open | boolean | - |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void | - |
Without value the Combobox holds the chosen value, starting from defaultValue; null is nothing chosen.
With multiple it holds a list of values, and a press on an item chooses it or lets go of it, leaving the list
open. items gives each value its
label, so the trigger shows it before the list has first been opened, and gives a function child of ComboboxList
its items; a string is its own label and value.
ComboboxTrigger#
Takes every prop of Button. It is an outline Button with a chevron at its
end, announced as a combobox, expanded while the list is open; name it with aria-label.
ComboboxValue#
Takes every prop of Text, plus placeholder, shown muted while nothing is
chosen. With multiple it shows the chosen labels, each after a comma. A function child gets the chosen values
as a list and draws what it returns in place of the Text, such as a ComboboxChip for each.
ComboboxChips#
Takes every prop of React Native's View, plus aria-invalid. The field of a multiple Combobox in place of a
ComboboxTrigger: a wrapping row of chips with a ComboboxChipsInput at its end. A press on it opens the list below
it. It takes the focus border while the list is open, and the destructive border while aria-invalid.
ComboboxChip#
Takes every prop of View, plus value and showRemove (true). Text children are its label. Its remove
button, a ghost icon button named Remove and the label, lets go of value; without value, the chosen value
whose value or label is its text.
ComboboxChipsInput#
Takes every prop of React Native's Pressable, plus placeholder, shown muted. It opens and closes the list,
and is announced as a combobox, expanded while the list is open; name it with aria-label.
ComboboxClear#
Takes every prop of Button. A ghost icon button named Clear, drawn while
something is chosen, that lets go of every chosen item. A multiple Combobox reports the empty list through
onValueChange. A single Combobox does not call onValueChange, so the owner of its value sets it to null
in the button's onPress.
ComboboxContent#
Takes every prop of PopoverContent, with align
('start') and sideOffset (6). It holds a Command, so its parts
filter and are run as a Command's are. It opens with the chosen item highlighted.
ComboboxInput#
Takes every prop of CommandInput. It is focused as the list opens, which raises the keyboard on a device.
ComboboxList#
Takes every prop of CommandList. Its children may be a function
of each of the Combobox's items, given as { label, value }.
ComboboxItem#
Takes every prop of CommandItem but onSelect, checked and
keywords, plus value and label. Text children are its label; give label when the children draw something
else. It is announced as selected while chosen, with a check mark at its end. A press, or the return key while it
is highlighted, chooses it and closes the list.
ComboboxGroup, ComboboxLabel, ComboboxEmpty and ComboboxSeparator#
The group holds items that belong together and is hidden while none of them match; the label is the muted heading over it. The empty message shows while the typed text matches no item, and the separator is a hairline between groups.
Differences from upstream#
- Upstream builds on Base UI's Combobox, which draws only on the web. The native one is a Popover holding a Command, as upstream's popup example lays it out: the input sits in the list's panel, not in the field.
- The input draws a search icon at its start, as a Command's does.
showTriggerandshowClearare left out. - A function child of ComboboxList gets each item as
{ label, value }, a string item included. - ComboboxChipsInput is a button that opens the list, not a text field: the search is typed into the
ComboboxInput in the list's panel, as in a single Combobox, since a field outside the panel would sit under the
layer that closes it on a press. ComboboxChips anchors the list itself, so
useComboboxAnchoris left out. - A single Combobox's
onValueChangeis never called withnull, which would change its type for every app holding the value as a string; a ComboboxClear'sonPressreports the clear instead. - A function child of ComboboxValue gets the chosen values as a list in a single Combobox too, one at most.
- ComboboxClear stands on its own, beside the trigger or in the chips, where upstream's sits in its
ComboboxInput's
showClear.