- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Message
- Message Scroller
- Native Select
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
- Typography
"use client"
import {"use client"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
] as const
export function ComboboxBasic() {
return (
<Combobox allowsEmptyCollection aria-label="Framework">
<ComboboxInput placeholder="Select a framework" />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Installation#
pnpm dlx shadcn@latest add combobox
Install the following dependencies:
pnpm add react-aria-components
Copy and paste the following code into your project.
"use client"
import * as React from "react"
import { cn } from "cn"
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-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,
Separator as SeparatorPrimitive,
TagGroup as TagGroupPrimitive,
TagList as TagListPrimitive,
Tag as TagPrimitive,
type ButtonProps,
type ComboBoxValueProps,
type GroupProps,
type HeaderProps,
type InputProps,
type ListBoxItemProps,
type ListBoxProps,
type ListBoxSectionProps,
type SeparatorProps,
type TagListProps,
type TagProps,
} from "react-aria-components"
import { Button } from "@/components/ui/button"
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupInput,
} from "@/components/ui/input-group"
function ComboboxValue<T>({ ...props }: ComboBoxValueProps<T>) {
return <ComboBoxValuePrimitive data-slot="combobox-value" {...props} />
}
function ComboboxTrigger({
className,
children,
...props
}: Omit<ButtonProps, "children"> & {
children?: React.ReactNode
}) {
return (
<ButtonPrimitive
data-slot="combobox-trigger"
className={cn("[&_svg:not([class*='size-'])]:size-4", className)}
{...props}
>
{children}
<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />
</ButtonPrimitive>
)
}
function ComboboxClear({
className,
...props
}: React.ComponentProps<typeof InputGroupButton>) {
const state = React.useContext(ComboBoxStateContext)
if (state?.inputValue === "") {
return null
}
return (
<InputGroupButton
data-slot="combobox-clear"
variant="ghost"
size="icon-xs"
aria-label="Clear"
className={cn(className)}
onPress={() => {
state?.setValue(null)
}}
slot={null}
{...props}
>
<XIcon className="pointer-events-none" />
</InputGroupButton>
)
}
function ComboboxInput({
className,
children,
disabled = false,
showTrigger = true,
showClear = false,
...props
}: React.ComponentProps<"input"> & {
showTrigger?: boolean
showClear?: boolean
}) {
return (
<InputGroup className={cn("w-auto", className)}>
<InputGroupInput disabled={disabled} {...props} />
<InputGroupAddon align="inline-end">
{showTrigger && (
<InputGroupButton
size="icon-xs"
variant="ghost"
data-slot="combobox-trigger"
className="group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent [&_svg:not([class*='size-'])]:size-4"
isDisabled={disabled}
>
<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />
</InputGroupButton>
)}
{showClear && <ComboboxClear isDisabled={disabled} />}
</InputGroupAddon>
{children}
</InputGroup>
)
}
function ComboboxContent({
className,
placement = "bottom",
offset = 6,
crossOffset = 0,
anchor,
...props
}: Omit<
React.ComponentProps<typeof PopoverPrimitive>,
"className" | "children"
> & {
className?: string
children?: React.ReactNode
anchor?: React.RefObject<HTMLDivElement | null>
}) {
return (
<PopoverPrimitive
data-slot="combobox-content"
placement={placement}
offset={offset}
crossOffset={crossOffset}
triggerRef={anchor}
className={cn("relative isolate z-50 max-h-72 w-(--trigger-width) min-w-36 origin-(--trigger-anchor-point) overflow-hidden rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-entering:animate-in data-entering:fade-in-0 data-entering:zoom-in-95 data-exiting:animate-out data-exiting:fade-out-0 data-exiting:zoom-out-95 data-[placement=bottom]:slide-in-from-top-2 data-[placement=left]:slide-in-from-right-2 data-[placement=right]:slide-in-from-left-2 data-[placement=top]:slide-in-from-bottom-2 **:data-[slot$=-item]:data-focused:bg-foreground/10 *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:border-input/30 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:shadow-none", className )}
{...props}
/>
)
}
function ComboboxList<T extends object>({
className,
...props
}: ListBoxProps<T>) {
return (
<ListBoxPrimitive
data-slot="combobox-list"
className={cn(
"group/combobox-content no-scrollbar max-h-[inherit] scroll-py-1 overflow-y-auto overscroll-contain p-1 data-empty:p-0",
className
)}
{...props}
/>
)
}
function ComboboxItem<T extends object>({
className,
children,
...props
}: ListBoxItemProps<T>) {
return (
<ListBoxItemPrimitive
data-slot="combobox-item"
textValue={typeof children === "string" ? children : undefined}
className={cn(
"relative flex w-full cursor-default items-center gap-2 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none data-focused:bg-accent data-focused:text-accent-foreground not-data-[variant=destructive]:data-focused:**:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{composeRenderProps(children, (children, { isSelected }) => (
<>
{children}
<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center">
{isSelected ? <CheckIcon className="pointer-events-none" /> : null}
</span>
</>
))}
</ListBoxItemPrimitive>
)
}
function ComboboxGroup<T extends object>({
className,
...props
}: ListBoxSectionProps<T>) {
return (
<ListBoxSectionPrimitive
data-slot="combobox-group"
className={cn(className)}
{...props}
/>
)
}
function ComboboxLabel({ className, ...props }: HeaderProps) {
return (
<HeaderPrimitive
data-slot="combobox-label"
className={cn("px-2 py-1.5 text-xs text-muted-foreground", className)}
{...props}
/>
)
}
function ComboboxEmpty({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="combobox-empty"
className={cn(
"hidden w-full justify-center py-2 text-center text-sm text-muted-foreground group-data-empty/combobox-content:flex",
className
)}
{...props}
/>
)
}
function ComboboxSeparator({ className, ...props }: SeparatorProps) {
return (
<SeparatorPrimitive
data-slot="combobox-separator"
className={cn("-mx-1 my-1 h-px bg-border", className)}
{...props}
/>
)
}
function ComboboxChips({ children, className, ...props }: GroupProps) {
return (
<Group
data-slot="combobox-chips"
className={cn(
"flex min-h-8 flex-wrap items-center gap-1 rounded-lg border border-input bg-transparent bg-clip-padding px-2.5 py-1 text-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 has-aria-invalid:border-destructive has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 has-data-[slot=combobox-chip]:px-1 dark:bg-input/30 dark:has-aria-invalid:border-destructive/50 dark:has-aria-invalid:ring-destructive/40",
className
)}
{...props}
>
{children}
</Group>
)
}
function ComboboxChipList<T extends object>({
className,
...props
}: Omit<TagListProps<T>, "className" | "items"> & {
className?: string
}) {
return (
<ComboBoxValuePrimitive<T> className="contents">
{({ selectedItems, state }) => (
<TagGroupPrimitive
data-slot="combobox-chip-list"
className={cn("contents", className)}
onRemove={(keys) => {
if (Array.isArray(state.value)) {
state.setValue(state.value.filter((k) => !keys.has(k)))
}
}}
>
<TagListPrimitive
className="contents"
items={selectedItems.filter((item) => item != null)}
{...props}
/>
</TagGroupPrimitive>
)}
</ComboBoxValuePrimitive>
)
}
function ComboboxChip({
className,
children,
showRemove = true,
...props
}: Omit<TagProps, "children"> & {
showRemove?: boolean
children?: React.ReactNode
}) {
return (
<TagPrimitive
data-slot="combobox-chip"
className={cn(
"flex h-[calc(--spacing(5.25))] w-fit items-center justify-center gap-1 rounded-sm bg-muted px-1.5 text-xs font-medium whitespace-nowrap text-foreground has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50 has-data-[slot=combobox-chip-remove]:pr-0",
className
)}
{...props}
>
{children}
{showRemove && (
<Button
slot="remove"
variant="ghost"
size="icon-xs"
className="-ml-1 opacity-50 hover:opacity-100"
data-slot="combobox-chip-remove"
>
<XIcon className="pointer-events-none" />
</Button>
)}
</TagPrimitive>
)
}
function ComboboxChipsInput({ className, ...props }: InputProps) {
const state = React.useContext(ComboBoxStateContext)
return (
<InputPrimitive
data-slot="combobox-chip-input"
className={cn("min-w-16 flex-1 outline-none", className)}
onKeyDown={(e) => {
if (
e.key === "Backspace" &&
e.currentTarget.value === "" &&
Array.isArray(state?.value) &&
state.value.length > 0
) {
e.preventDefault()
state.setValue(state.value.slice(0, -1))
}
}}
{...props}
/>
)
}
function useComboboxAnchor() {
return React.useRef<HTMLDivElement | null>(null)
}
export {
ComboBoxPrimitive as Combobox,
ComboboxInput,
ComboboxContent,
ComboboxList,
ComboboxItem,
ComboboxGroup,
ComboboxLabel,
Collection as ComboboxCollection,
ComboboxEmpty,
ComboboxSeparator,
ComboboxChips,
ComboboxChip,
ComboboxChipList,
ComboboxChipsInput,
ComboboxTrigger,
ComboboxValue,
useComboboxAnchor,
}
Update the import paths to match your project setup.
Usage#
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"const frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"]
export function ExampleCombobox() {
return (
<Combobox allowsEmptyCollection>
<ComboboxInput placeholder="Select a framework" />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}Composition#
Simple#
A single-line input and a flat list (see Basic).
Combobox
├── ComboboxInput
└── ComboboxContent
└── ComboboxList
├── ComboboxItem
└── ComboboxItemWith chips#
Multi-select with multiple, chips, and a chips input (see Multiple).
Combobox
├── ComboboxChips
│ ├── ComboboxChipList
│ │ └── ComboboxChip
│ └── ComboboxChipsInput
└── ComboboxContent
└── ComboboxList
├── ComboboxItem
└── ComboboxItemWith groups and collection#
Nested items per group using ComboboxGroup, with a separator between groups (see Groups).
Combobox
├── ComboboxInput
└── ComboboxContent
└── ComboboxList
├── ComboboxGroup
│ ├── ComboboxLabel
│ ├── ComboboxItem
│ └── ComboboxItem
├── ComboboxSeparator
└── ComboboxGroup
├── ComboboxLabel
├── ComboboxItem
└── ComboboxItemCustom Items#
Use textValue when your items render JSX children.
import * as React from "react"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
type Framework = {
label: string
value: string
}
const frameworks: Framework[] = [
{ label: "Next.js", value: "next" },
{ label: "SvelteKit", value: "sveltekit" },
{ label: "Nuxt", value: "nuxt" },
]
export function ExampleComboboxCustomItems() {
return (
<Combobox allowsEmptyCollection>
<ComboboxInput placeholder="Select a framework" />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
items={frameworks}
>
{(framework) => (
<ComboboxItem id={framework.value} textValue={framework.label}>
<span>{framework.label}</span>
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}Multiple Selection#
Use multiple with chips for multi-select behavior.
import * as React from "react"
import {
Combobox,
ComboboxChip,
ComboboxChipList,
ComboboxChips,
ComboboxChipsInput,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = ["Next.js", "SvelteKit", "Nuxt.js", "Remix", "Astro"]
export function ExampleComboboxMultiple() {
const [value, setValue] = React.useState<string[]>([])
return (
<Combobox
selectionMode="multiple"
value={value}
onChange={setValue}
allowsEmptyCollection
>
<ComboboxChips>
<ComboboxChipList<{ name: string }>>
{(value) => <ComboboxChip id={value.name}>{value.name}</ComboboxChip>}
</ComboboxChipList>
<ComboboxChipsInput placeholder="Add framework" />
</ComboboxChips>
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}Basic#
A simple combobox with a list of frameworks.
"use client"
import {"use client"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
] as const
export function ComboboxBasic() {
return (
<Combobox allowsEmptyCollection aria-label="Framework">
<ComboboxInput placeholder="Select a framework" />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Multiple#
A combobox with multiple selection using multiple and ComboboxChips.
"use client"
import * as React from "react""use client"
import * as React from "react"
import {
Combobox,
ComboboxChip,
ComboboxChipList,
ComboboxChips,
ComboboxChipsInput,
ComboboxContent,
ComboboxEmpty,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
] as const
export function ComboboxMultiple() {
return (
<Combobox
aria-label="Frameworks"
selectionMode="multiple"
defaultValue={[frameworks[0]]}
allowsEmptyCollection
className="w-[250px] max-w-full"
>
<ComboboxChips>
<ComboboxChipList<{ name: string }>>
{(value) => <ComboboxChip id={value.name}>{value.name}</ComboboxChip>}
</ComboboxChipList>
<ComboboxChipsInput />
</ComboboxChips>
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item} value={{ name: item }}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Clear Button#
Use the showClear prop to show a clear button.
"use client"
import {"use client"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
] as const
export function ComboboxWithClear() {
return (
<Combobox
defaultValue={frameworks[0]}
allowsEmptyCollection
aria-label="Framework"
>
<ComboboxInput placeholder="Select a framework" showClear />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Groups#
Use ComboboxGroup and ComboboxSeparator to group items.
"use client"
import {"use client"
import {
Combobox,
ComboboxCollection,
ComboboxContent,
ComboboxEmpty,
ComboboxGroup,
ComboboxInput,
ComboboxItem,
ComboboxLabel,
ComboboxList,
ComboboxSeparator,
} from "@/components/ui/combobox"
const timezones = [
{
value: "Americas",
items: [
"(GMT-5) New York",
"(GMT-8) Los Angeles",
"(GMT-6) Chicago",
"(GMT-5) Toronto",
"(GMT-8) Vancouver",
"(GMT-3) São Paulo",
],
},
{
value: "Europe",
items: [
"(GMT+0) London",
"(GMT+1) Paris",
"(GMT+1) Berlin",
"(GMT+1) Rome",
"(GMT+1) Madrid",
"(GMT+1) Amsterdam",
],
},
{
value: "Asia/Pacific",
items: [
"(GMT+9) Tokyo",
"(GMT+8) Shanghai",
"(GMT+8) Singapore",
"(GMT+4) Dubai",
"(GMT+11) Sydney",
"(GMT+9) Seoul",
],
},
] as const
export function ComboboxWithGroupsAndSeparator() {
return (
<Combobox allowsEmptyCollection aria-label="Timezone">
<ComboboxInput placeholder="Select a timezone" />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No timezones found.</ComboboxEmpty>
)}
>
{timezones.map((group, index) => (
<ComboboxGroup key={group.value} id={group.value}>
<ComboboxLabel>{group.value}</ComboboxLabel>
{group.items.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
{index < timezones.length - 1 && <ComboboxSeparator />}
</ComboboxGroup>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Custom Items#
You can render custom component inside ComboboxItem.
"use client"
import {"use client"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
import {
Item,
ItemContent,
ItemDescription,
ItemTitle,
} from "@/components/ui/item"
const countries = [
{
code: "ar",
value: "argentina",
label: "Argentina",
continent: "South America",
},
{ code: "au", value: "australia", label: "Australia", continent: "Oceania" },
{ code: "br", value: "brazil", label: "Brazil", continent: "South America" },
{ code: "ca", value: "canada", label: "Canada", continent: "North America" },
{ code: "cn", value: "china", label: "China", continent: "Asia" },
{
code: "co",
value: "colombia",
label: "Colombia",
continent: "South America",
},
{ code: "eg", value: "egypt", label: "Egypt", continent: "Africa" },
{ code: "fr", value: "france", label: "France", continent: "Europe" },
{ code: "de", value: "germany", label: "Germany", continent: "Europe" },
{ code: "it", value: "italy", label: "Italy", continent: "Europe" },
{ code: "jp", value: "japan", label: "Japan", continent: "Asia" },
{ code: "ke", value: "kenya", label: "Kenya", continent: "Africa" },
{ code: "mx", value: "mexico", label: "Mexico", continent: "North America" },
{
code: "nz",
value: "new-zealand",
label: "New Zealand",
continent: "Oceania",
},
{ code: "ng", value: "nigeria", label: "Nigeria", continent: "Africa" },
{
code: "za",
value: "south-africa",
label: "South Africa",
continent: "Africa",
},
{ code: "kr", value: "south-korea", label: "South Korea", continent: "Asia" },
{
code: "gb",
value: "united-kingdom",
label: "United Kingdom",
continent: "Europe",
},
{
code: "us",
value: "united-states",
label: "United States",
continent: "North America",
},
]
export function ComboboxWithCustomItems() {
return (
<Combobox allowsEmptyCollection aria-label="Country">
<ComboboxInput placeholder="Search countries..." />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No countries found.</ComboboxEmpty>
)}
>
{countries
.filter((country) => country.code !== "")
.map((country) => (
<ComboboxItem
key={country.code}
id={country.code}
textValue={country.label}
>
<Item size="xs" className="p-0">
<ItemContent>
<ItemTitle className="whitespace-nowrap">
{country.label}
</ItemTitle>
<ItemDescription>
{country.continent} ({country.code})
</ItemDescription>
</ItemContent>
</Item>
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Invalid#
Use the isInvalid prop to make the combobox invalid.
"use client"
import {"use client"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
] as const
export function ComboboxInvalid() {
return (
<Combobox allowsEmptyCollection isInvalid aria-label="Framework">
<ComboboxInput placeholder="Select a framework" />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Disabled#
Use the isDisabled prop to disable the combobox.
"use client"
import {"use client"
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
const frameworks = [
"Next.js",
"SvelteKit",
"Nuxt.js",
"Remix",
"Astro",
] as const
export function ComboboxDisabled() {
return (
<Combobox allowsEmptyCollection aria-label="Framework">
<ComboboxInput placeholder="Select a framework" disabled />
<ComboboxContent>
<ComboboxList
renderEmptyState={() => (
<ComboboxEmpty>No items found.</ComboboxEmpty>
)}
>
{frameworks.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
Input Group#
You can add an addon to the combobox by using the InputGroupAddon component inside the ComboboxInput.
"use client"
import { GlobeIcon } from "lucide-react""use client"
import { GlobeIcon } from "lucide-react"
import {
Combobox,
ComboboxCollection,
ComboboxContent,
ComboboxEmpty,
ComboboxGroup,
ComboboxInput,
ComboboxItem,
ComboboxLabel,
ComboboxList,
} from "@/components/ui/combobox"
import { InputGroupAddon } from "@/components/ui/input-group"
const timezones = [
{
value: "Americas",
items: [
"(GMT-5) New York",
"(GMT-8) Los Angeles",
"(GMT-6) Chicago",
"(GMT-5) Toronto",
"(GMT-8) Vancouver",
"(GMT-3) São Paulo",
],
},
{
value: "Europe",
items: [
"(GMT+0) London",
"(GMT+1) Paris",
"(GMT+1) Berlin",
"(GMT+1) Rome",
"(GMT+1) Madrid",
"(GMT+1) Amsterdam",
],
},
{
value: "Asia/Pacific",
items: [
"(GMT+9) Tokyo",
"(GMT+8) Shanghai",
"(GMT+8) Singapore",
"(GMT+4) Dubai",
"(GMT+11) Sydney",
"(GMT+9) Seoul",
],
},
] as const
export function ComboxboxInputGroup() {
return (
<Combobox allowsEmptyCollection aria-label="Timezone">
<ComboboxInput placeholder="Select a timezone">
<InputGroupAddon>
<GlobeIcon />
</InputGroupAddon>
</ComboboxInput>
<ComboboxContent crossOffset={-28} className="w-60">
<ComboboxList
items={timezones}
renderEmptyState={() => (
<ComboboxEmpty>No timezones found.</ComboboxEmpty>
)}
>
{(group) => (
<ComboboxGroup id={group.value}>
<ComboboxLabel>{group.value}</ComboboxLabel>
{group.items.map((item) => (
<ComboboxItem key={item} id={item}>
{item}
</ComboboxItem>
))}
</ComboboxGroup>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}
RTL#
To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"// You will notice this example uses dir and data-lang attributes. // This is because this site is not RTL by default. // In your application, you won't need these.// See the RTL guide for more information.
"use client"
import * as React from "react"
import {
useTranslation,
type Translations,
} from "@/components/language-selector"
import {
Combobox,
ComboboxChip,
ComboboxChipList,
ComboboxChips,
ComboboxChipsInput,
ComboboxContent,
ComboboxEmpty,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox"
import { Field, FieldLabel } from "@/components/ui/field"
const categories = [
"technology",
"design",
"business",
"marketing",
"education",
"health",
] as const
const translations: Translations = {
en: {
dir: "ltr",
values: {
label: "Categories",
placeholder: "Add categories",
empty: "No categories found.",
technology: "Technology",
design: "Design",
business: "Business",
marketing: "Marketing",
education: "Education",
health: "Health",
},
},
ar: {
dir: "rtl",
values: {
label: "الفئات",
placeholder: "أضف فئات",
empty: "لم يتم العثور على فئات.",
technology: "التكنولوجيا",
design: "التصميم",
business: "الأعمال",
marketing: "التسويق",
education: "التعليم",
health: "الصحة",
},
},
he: {
dir: "rtl",
values: {
label: "קטגוריות",
placeholder: "הוסף קטגוריות",
empty: "לא נמצאו קטגוריות.",
technology: "טכנולוגיה",
design: "עיצוב",
business: "עסקים",
marketing: "שיווק",
education: "חינוך",
health: "בריאות",
},
},
}
export function ComboboxRtl() {
const { dir, t, language } = useTranslation(translations, "ar")
const categoryLabels: Record<string, string> = {
technology: t.technology,
design: t.design,
business: t.business,
marketing: t.marketing,
education: t.education,
health: t.health,
}
return (
<Field className="mx-auto w-full max-w-xs">
<FieldLabel>{t.label}</FieldLabel>
<Combobox
aria-label={t.label}
selectionMode="multiple"
defaultValue={[categories[0]]}
allowsEmptyCollection
>
<ComboboxChips>
<ComboboxChipList<{ name: string }>>
{(value) => (
<ComboboxChip id={value.name}>
{categoryLabels[value.name] || value.name}
</ComboboxChip>
)}
</ComboboxChipList>
<ComboboxChipsInput placeholder={t.placeholder} />
</ComboboxChips>
<ComboboxContent
dir={dir}
data-lang={dir === "rtl" ? language : undefined}
>
<ComboboxList
renderEmptyState={() => <ComboboxEmpty>{t.empty}</ComboboxEmpty>}
>
{categories.map((item) => (
<ComboboxItem key={item} id={item} value={{ name: item }}>
{categoryLabels[item] || item}
</ComboboxItem>
))}
</ComboboxList>
</ComboboxContent>
</Combobox>
</Field>
)
}
API Reference#
See the React Aria documentation for more information.