Combobox

Web/Mobile

Autocomplete input and command palette with a list of suggestions.

Installation

pnpm dlx cubix-ui@latest add combobox

Usage

Import
import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@/components/cubix/combobox"

const cities = ["تهران", "مشهد", "اصفهان", "شیراز", "تبریز"]
Example
<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).

Structure
Combobox
├── ComboboxInput
└── ComboboxContent
    ├── ComboboxEmpty
    └── ComboboxList
        └── ComboboxItem

With chips

Multi-select with multiple, chips, and a chips input.

Structure
Combobox
├── ComboboxChips
│   └── ComboboxValue
│       ├── ComboboxChip
│       └── ComboboxChipsInput
└── ComboboxContent
    ├── ComboboxEmpty
    └── ComboboxList
        └── ComboboxItem

With groups

Nested items per group using ComboboxCollection inside each ComboboxGroup.

Structure
Combobox
├── ComboboxInput
└── ComboboxContent
    ├── ComboboxEmpty
    └── ComboboxList
        └── ComboboxGroup
            ├── ComboboxLabel
            ├── ComboboxCollection
            │   └── ComboboxItem
            └── ComboboxSeparator

Accessibility

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.

KeyAction
ArrowDownOpens the list if closed, then moves highlight to the next item.
ArrowUpOpens the list if closed, then moves highlight to the previous item.
EnterSelects the highlighted item. With autoHighlight, selects the first match.
EscapeCloses the list and clears the highlight.
Home / EndMoves 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

PropTypeDefaultDescription
itemsT[]-The collection used to render and filter the list.
valueT | T[] | null-Controlled selected value. Use an array when multiple is set.
defaultValueT | T[] | null-Initial selected value when uncontrolled.
onValueChange(value: T | T[] | null) => void-Called when the selected value changes.
multiplebooleanfalseAllow more than one selected item.
autoHighlightbooleanfalseHighlight 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.
disabledbooleanfalseDisable the combobox.
dir"ltr" | "rtl"-Text direction of the popup. Defaults to the closest dir on the page.
langstring-Language of the popup. Defaults to the closest lang on the page.

ComboboxInput

PropTypeDefaultDescription
showTriggerbooleantrueShow the chevron button at the end of the input. Defaults to false inside ComboboxContent.
showClearbooleanfalseShow 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.
placeholderstring-Placeholder text for the input.
disabledbooleanfalseDisable the input and its buttons.
aria-invalidboolean | "true" | "false"-Show the invalid state.
classNamestring-Additional Tailwind classes merged with the input group styles (last one wins).

ComboboxContent

PropTypeDefaultDescription
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.
sideOffsetnumber4Distance in pixels from the anchor.
alignOffsetnumber0Offset in pixels along the alignment axis.
anchorRefObject<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

PropTypeDefaultDescription
valueT-The item value. Required.
disabledbooleanfalseKeep the item visible but not selectable.

ComboboxList, ComboboxGroup, ComboboxLabel, ComboboxEmpty and ComboboxSeparator take className and children (ComboboxSeparator has no children).