Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Combobox for React

Displays a searchable list of options.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/radix/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 frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"];

const ComboboxDemo = () => {
  const { contains } = useFilter({ sensitivity: "base" });
  const { collection, filter } = useListCollection({
    filter: contains,
    initialItems: frameworks,
  });

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

  return (
    <Combobox
      collection={collection}
      onInputValueChange={handleInputValueChange}
    >
      <ComboboxInput placeholder="Select a framework" />
      <ComboboxContent>
        <ComboboxEmpty>No items found.</ComboboxEmpty>
        <ComboboxList>
          {collection.items.map((item) => (
            <ComboboxItem item={item} key={item}>
              {item}
            </ComboboxItem>
          ))}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  );
};

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

Basic

A simple combobox with a list of frameworks.

Multiple

A combobox with multiple selection using multiple and ComboboxChips.

Clear

Use the showClear prop to show a clear button.

Groups

Use ComboboxGroup and ComboboxSeparator to group items.

Custom

You can render a custom component inside ComboboxItem.

Invalid

Use the aria-invalid prop to make the combobox invalid.

Disabled

Use the disabled prop to disable the combobox.

Auto Highlight

Use inputBehavior="autohighlight" to automatically highlight the first item on filter.

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

Input Group

Add an addon to the combobox with InputGroupAddon inside ComboboxInput.

Rtl

Right-to-left combobox. See the RTL configuration guide for document direction.

API Reference

Combobox

PropType

ComboboxValue

PropType
AttributeType

ComboboxTrigger

PropType
AttributeType

ComboboxClear

PropType
AttributeType

ComboboxInput

PropType

ComboboxContent

PropType
AttributeType
data-chips?string
CSS variableType
--anchor-widthstring
--available-heightstring
--available-widthstring
--transform-originstring

ComboboxList

PropType
AttributeType

ComboboxItem

PropType
AttributeType

ComboboxGroup

PropType
AttributeType

ComboboxLabel

PropType
AttributeType

ComboboxCollection

PropType
AttributeType

ComboboxEmpty

PropType
AttributeType

ComboboxSeparator

PropType
AttributeType

ComboboxChips

PropType
AttributeType

ComboboxChip

PropType
AttributeType

ComboboxChipsInput

PropType
AttributeType