Combobox
Web/MobileAutocomplete input and command palette with a list of suggestions.
Installation
pnpm dlx cubix-ui@latest add combobox --base ariaUsage
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/cubix/combobox"
const cities = ["تهران", "مشهد", "اصفهان", "شیراز", "تبریز"]
<Combobox dir="rtl" lang="fa" items={cities}>
<ComboboxInput placeholder="انتخاب شهر" className="w-56" />
<ComboboxContent>
<ComboboxEmpty>شهری یافت نشد.</ComboboxEmpty>
<ComboboxList>
{(item: string) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
Composition
Simple
A single-line input and a flat list. The popup reads dir and lang from the closest ancestor and aligns to the start edge of the input (the right edge in RTL).
Combobox
├── ComboboxInput
└── ComboboxContent
├── ComboboxEmpty
└── ComboboxList
└── ComboboxItemWith chips
Multi-select with multiple, chips, and a chips input.
Combobox
├── ComboboxChips
│ └── ComboboxValue
│ ├── ComboboxChip
│ └── ComboboxChipsInput
└── ComboboxContent
├── ComboboxEmpty
└── ComboboxList
└── ComboboxItemWith groups
Nested items per group using ComboboxCollection inside each ComboboxGroup.
Combobox
├── ComboboxInput
└── ComboboxContent
├── ComboboxEmpty
└── ComboboxList
└── ComboboxGroup
├── ComboboxLabel
├── ComboboxCollection
│ └── ComboboxItem
└── ComboboxSeparatorAccessibility
The input is a combobox with aria-expanded, aria-controls, and aria-autocomplete. The list is a listbox; selected items announce as selected. Give the field an accessible name through a label or aria-label.
| Key | Action |
|---|---|
| ArrowDown | Opens the list if closed, then moves highlight to the next item. |
| ArrowUp | Opens the list if closed, then moves highlight to the previous item. |
| Enter | Selects the highlighted item. With autoHighlight, selects the first match. |
| Escape | Closes the list and clears the highlight. |
| Home / End | Moves the caret in the input, or the highlight to the first or last item when the list is open. |
Examples
Basic
Type to filter the list, or press ArrowDown to open it. The selected item shows a check at the end.
Sizes
Set size to default (40px) or lg (48px), matching Text Field. ComboboxChips takes the same prop. The popup list is the same for both sizes.
Multiple
Use multiple with ComboboxChips for multi-select. Pass the chips ref from useComboboxAnchor as the popup anchor.
Clear button
Set showClear to show a clear button while a value is selected. It takes the place of the chevron.
Groups
Use ComboboxGroup, ComboboxLabel and ComboboxSeparator to group items.
Disabled items
Set disabled on a ComboboxItem to keep it visible but not selectable. Keyboard navigation skips it.
Custom items
When items are objects, use itemToStringLabel to choose the text shown in the input and used for filtering, and render any content inside ComboboxItem.
Invalid
Set aria-invalid on ComboboxInput to mark the combobox as invalid.
Disabled
Set disabled on Combobox to disable the input and its trigger.
Auto highlight
Set autoHighlight to highlight the first match while typing, so Enter selects it.
Popup
Open the combobox from a button with ComboboxTrigger and move ComboboxInput inside ComboboxContent. The input there has no chevron.
Input group
Add an InputGroupAddon inside ComboboxInput. The whole group is the popup anchor.
Custom styling
Every part accepts a className merged with the shipped cn helper. Here the field uses a filled surface instead of the default outline, and the popup and its items use larger rounding.
API Reference
Note: Parts render data-slot attributes (combobox-trigger, combobox-content, combobox-list, combobox-item, combobox-group, combobox-label, combobox-empty, combobox-separator, combobox-clear, combobox-chips, combobox-chip, combobox-chip-remove, combobox-chip-input) for targeting in tests and parent selectors. The field is an input group (input-group, input-group-control). Use the same props on Base UI, React Aria, and Radix.
Combobox
| Prop | Type | Default | Description |
|---|---|---|---|
| items | T[] | - | The collection used to render and filter the list. |
| value | T | T[] | null | - | Controlled selected value. Use an array when multiple is set. |
| defaultValue | T | T[] | null | - | Initial selected value when uncontrolled. |
| onValueChange | (value: T | T[] | null) => void | - | Called when the selected value changes. |
| multiple | boolean | false | Allow more than one selected item. |
| autoHighlight | boolean | false | Highlight the first matching item while filtering. |
| itemToStringLabel | (item: T) => string | - | Text for an object item, shown in the input and used for filtering. Objects shaped { value, label } use label automatically. |
| itemToStringValue | (item: T) => string | - | String submitted with a form for an object item. Objects shaped { value, label } use value automatically. |
| disabled | boolean | false | Disable the combobox. |
| dir | "ltr" | "rtl" | - | Text direction of the popup. Defaults to the closest dir on the page. |
| lang | string | - | Language of the popup. Defaults to the closest lang on the page. |
ComboboxInput
| Prop | Type | Default | Description |
|---|---|---|---|
| showTrigger | boolean | true | Show the chevron button at the end of the input. Defaults to false inside ComboboxContent. |
| showClear | boolean | false | Show a button that clears the selected value. |
| size | "default" | "lg" | "default" | Height and inline padding, matching Text Field: default 40px, lg 48px. ComboboxChips takes the same prop for its minimum height. Use className for other heights. |
| placeholder | string | - | Placeholder text for the input. |
| disabled | boolean | false | Disable the input and its buttons. |
| aria-invalid | boolean | "true" | "false" | - | Show the invalid state. |
| className | string | - | Additional Tailwind classes merged with the input group styles (last one wins). |
ComboboxContent
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | "bottom" | Preferred side of the popup. |
| align | "start" | "center" | "end" | "start" | Alignment of the popup relative to the anchor. |
| sideOffset | number | 4 | Distance in pixels from the anchor. |
| alignOffset | number | 0 | Offset in pixels along the alignment axis. |
| anchor | RefObject<HTMLElement> | - | Custom anchor, used with chips for multi-select. Defaults to the input group, or the trigger when the input is inside the popup. |
ComboboxItem
| Prop | Type | Default | Description |
|---|---|---|---|
| value | T | - | The item value. Required. |
| disabled | boolean | false | Keep the item visible but not selectable. |
ComboboxList, ComboboxGroup, ComboboxLabel, ComboboxEmpty and ComboboxSeparator take className and children (ComboboxSeparator has no children).