Combobox

An input combined with a list of predefined items to select.

API Reference
Loading...
Loading code...

Installation

pnpm dlx shadcn@latest add @uitopia/combobox

Usage

Single Selection

import {
  Combobox,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  ComboboxPopup,
} from "@/components/ui/combobox"
const items = [
  { value: "apple", label: "Apple" },
  { value: "banana", label: "Banana" },
  { value: "orange", label: "Orange" },
  { value: "grape", label: "Grape" },
]

<Combobox items={items}>
  <ComboboxInput placeholder="Select an item..." />
  <ComboboxPopup>
    <ComboboxEmpty>No results found.</ComboboxEmpty>
    <ComboboxList>
      {(item) => <ComboboxItem key={item.value} value={item}>{item.label}</ComboboxItem>}
    </ComboboxList>
  </ComboboxPopup>
</Combobox>

Multiple Selection

import {
  Combobox,
  ComboboxChip,
  ComboboxChips,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  ComboboxPopup,
  ComboboxValue,
} from "@/components/ui/combobox"
const items = [
  { value: "apple", label: "Apple" },
  { value: "banana", label: "Banana" },
  { value: "orange", label: "Orange" },
  { value: "grape", label: "Grape" },
]

<Combobox items={items} multiple>
  <ComboboxChips>
    <ComboboxValue>
      {(value: { value: string; label: string }[]) => (
        <>
          {value?.map((item) => (
            <ComboboxChip key={item.value} aria-label={item.value}>
              {item.label}
            </ComboboxChip>
          ))}
          <ComboboxInput
            placeholder={value.length > 0 ? undefined : "Select a Select an item..."}
            aria-label="Select an item"
          />
        </>
      )}
    </ComboboxValue>
  </ComboboxChips>
  <ComboboxPopup>
    <ComboboxEmpty>No results found.</ComboboxEmpty>
    <ComboboxList>
      {(item) => <ComboboxItem value={item}>{item.label}</ComboboxItem>}
    </ComboboxList>
  </ComboboxPopup>
</Combobox>

API Reference

The ComboboxInput component extends the original Base UI component with a few extra props:

PropTypeDefaultDescription
size"sm" | "default" | "lg""default"The size variant of the input field.
showTriggerbooleantrueWhether to display a trigger button (chevron icon) on the right side of the input.
showClearbooleanfalseWhether to display a clear button (X icon) on the right side of the input when there is a value.

Examples

Disabled

Loading...
Loading code...

Small Size

Loading...
Loading code...

Large Size

Loading...
Loading code...

With Label

Loading...
Loading code...

Auto Highlight

Automatically highlight the first matching option.

Loading...
Loading code...

With Clear Button

Loading...
Loading code...

With Groups

Loading...
Loading code...

With Multiple Selection

Loading...
Loading code...

With Input Inside Popup

Loading...
Loading code...

Form Integration

Loading...
Loading code...

Form Integration - Multiple

Loading...
Loading code...