Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Combobox for React and Tailwind

Displays a searchable list of options.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/combobox.json

Anatomy

ComboboxRoot
├── ComboboxClear
├── ComboboxContent
├── ComboboxControl
├── ComboboxFieldInput
├── ComboboxItem
│   ├── ComboboxGroup
│   │   └── ComboboxGroupLabel
│   ├── ComboboxItemIndicator
│   └── ComboboxItemText
├── ComboboxLabel
├── ComboboxList
├── ComboboxPositioner
└── ComboboxTrigger

Usage

import { useListCollection } from "@ark-ui/react/collection";
import { useFilter } from "@ark-ui/react/locale";
import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@/components/ui/combobox";
const ComboboxDemo = () => {
  const { contains } = useFilter({ sensitivity: "base" });

  const { collection, filter } = useListCollection({
    filter: contains,
    initialItems,
  });

  const handleInputValueChange = ({ inputValue }: { inputValue: string }) => {
    filter(inputValue);
  };

  return (
    <Combobox
      className="max-w-xs"
      collection={collection}
      onInputValueChange={handleInputValueChange}
    >
      <ComboboxInput placeholder="Select an option" />
      <ComboboxContent>
        <ComboboxEmpty />
        <ComboboxList>
          {collection.items.map((item) => (
            <ComboboxItem item={item} key={item.value}>
              {item.label}
            </ComboboxItem>
          ))}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  );
};

const initialItems = [
  { label: "Apple", value: "apple" },
  { label: "Banana", value: "banana" },
  { label: "Cherry", value: "cherry" },
  { label: "Date", value: "date" },
];

Accessibility

KeyDescription
ArrowDown
Move down.
ArrowUp
Move up.
Home
Go to the start.
End
Go to the end.
Enter
Activate the focused item.
Escape
Dismiss.
Space
Activate the focused control.

Demos

Async

Autohighlight

Context

Controlled

Creatable

Custom Object

Disabled

Dynamic

Group

Highlight

Inline

Invalid

Limit Results

Multiple

Rehydrate

Root Provider

Size Lg

Size Md

Size Sm

With Clear Button

With Field

With Scroll

With Start Icon

API Reference

ComboboxClear

button

PropType
AttributeType

ComboboxContent

div

PropType
AttributeType
CSS variableType

ComboboxControl

div

PropType
AttributeType

ComboboxFieldInput

input

PropType
AttributeType

ComboboxItem

div

PropType
AttributeType

ComboboxGroup

div

PropType
AttributeType

ComboboxGroupLabel

div

PropType
AttributeType

ComboboxItemIndicator

div

PropType

ComboboxLabel

label

PropType
AttributeType

ComboboxList

div

PropType
AttributeType

ComboboxPositioner

div

PropType
AttributeType

ComboboxTrigger

button

PropType
AttributeType

ComboboxInput

input

PropType
AttributeType

ComboboxEmpty

div

PropType
AttributeType

useCombobox

PropType