shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/combobox.jsonnpx shadcn@latest add https://kit.dev/r/aria/combobox.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/combobox.jsonyarn shadcn@latest add https://kit.dev/r/aria/combobox.jsonThis component depends on Button and Input Group. Install them first if you haven't already.
Install the following dependencies:
bun add react-aria-components lucide-reactnpm install react-aria-components lucide-reactpnpm add react-aria-components lucide-reactyarn add react-aria-components lucide-reactCopy and paste the following code into your project.
"use client";
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react";
import React from "react";
import {
Button as ButtonPrimitive,
Collection,
ComboBox as ComboBoxPrimitive,
ComboBoxStateContext,
ComboBoxValue as ComboBoxValuePrimitive,
composeRenderProps,
Group,
Header as HeaderPrimitive,
Input as InputPrimitive,
ListBoxItem as ListBoxItemPrimitive,
ListBox as ListBoxPrimitive,
ListBoxSection as ListBoxSectionPrimitive,
Popover as PopoverPrimitive,Update the import paths to match your project setup.
Anatomy
ComboboxRoot
├── ComboboxClear
├── ComboboxContent
├── ComboboxControl
├── ComboboxFieldInput
├── ComboboxItem
│ ├── ComboboxGroup
│ │ └── ComboboxGroupLabel
│ ├── ComboboxItemIndicator
│ └── ComboboxItemText
├── ComboboxLabel
├── ComboboxList
├── ComboboxPositioner
└── ComboboxTriggerUsage
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
| Key | Description |
|---|---|
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.
Popup
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
AttributeType
ComboboxValue
AttributeType
ComboboxTrigger
PropType
AttributeType
ComboboxClear
PropType
AttributeType
ComboboxInput
PropType
AttributeType
ComboboxContent
PropType
AttributeType
CSS variableType
--trigger-anchor-pointstring--trigger-widthstringComboboxList
PropType
AttributeType
ComboboxItem
PropType
AttributeType
ComboboxGroup
PropType
AttributeType
ComboboxLabel
PropType
AttributeType
ComboboxEmpty
PropType
AttributeType
ComboboxSeparator
PropType
AttributeType
ComboboxChips
PropType
AttributeType
ComboboxChipList
PropType
AttributeType
ComboboxChip
PropType
AttributeType
ComboboxChipsInput
PropType
AttributeType
ComboboxCollection
AttributeType