Combobox

Autocomplete input and command palette with a list of suggestions.

Installation

pnpm dlx cubix@latest add combobox --base aria

Usage

Import
import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@/components/cubix/combobox"
Example
const frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"]

export function ExampleCombobox() {
  return (
    <Combobox items={frameworks}>
      <ComboboxInput placeholder="Select a framework" />
      <ComboboxContent>
        <ComboboxEmpty>No items found.</ComboboxEmpty>
        <ComboboxList>
          {(item) => (
            <ComboboxItem key={item} value={item}>
              {item}
            </ComboboxItem>
          )}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  )
}

Composition

Simple

A single-line input and a flat list.

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

With chips

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

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

With groups and collection

Nested items per group using ComboboxCollection inside each ComboboxGroup.

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

Examples

Basic

A simple combobox with a list of frameworks.

Multiple

Use multiple with chips for multi-select behavior.

Clear Button

Use the showClear prop to show a clear button.

Groups

Use ComboboxGroup and ComboboxSeparator to group items.

Custom Items

Use itemToStringValue when your items are objects, and render custom item content.

Invalid

Use the aria-invalid prop to mark the combobox as invalid.

Disabled

Use the disabled prop to disable the combobox.

Auto Highlight

Use the autoHighlight prop to automatically highlight the first item on filter.

Popup

Trigger the combobox from a button. Move ComboboxInput inside ComboboxContent.

Input Group

Add an addon inside ComboboxInput with InputGroupAddon.

API Reference

Note: See the Base UI Combobox docs for the full primitive API.

Combobox

The root that holds items, value, and filter state.

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.
autoHighlightbooleanfalseAutomatically highlight the first matching item while filtering.
itemToStringValue(item: T) => string-Map an object item to the string used for filtering and display.
disabledbooleanfalseDisable the combobox.

ComboboxInput

PropTypeDefaultDescription
showTriggerbooleantrueShow the dropdown trigger inside the input group.
showClearbooleanfalseShow a button that clears the selected value.
placeholderstring-Placeholder text for the input.
disabledboolean-Disable the input.
classNamestring-Additional Tailwind classes merged with the component 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.
sideOffsetnumber6Distance in pixels from the anchor.
anchorRefObject<HTMLElement>-Custom anchor, used with chips for multi-select.