placeholderComboboxClearautoHighlightdisabledimport {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxInputGroup,
ComboboxItem,
ComboboxList,
ComboboxTrigger,
} from "@/components/ui/combobox"
const frameworks = ["React", "Vue", "Angular", "Svelte", "Solid", "Next.js", "Nuxt", "Remix"]
export function FrameworkCombobox() {
return (
<Combobox items={frameworks}>
<div className="space-y-2">
<label htmlFor="framework" className="block text-sm font-medium leading-none">
Framework
</label>
<ComboboxInputGroup className="flex w-[280px] max-w-full items-center gap-1 rounded-md border border-input focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<ComboboxInput id="framework" placeholder="Search frameworks..." />
<ComboboxTrigger />
</ComboboxInputGroup>
</div>
<ComboboxContent>
<ComboboxEmpty>No frameworks found.</ComboboxEmpty>
<ComboboxList>
{(fw: string) => (
<ComboboxItem key={fw} value={fw}>
{fw}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}Usage
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxInputGroup,
ComboboxItem,
ComboboxList,
ComboboxTrigger,
} from "@/components/ui/combobox"
const fruits = ["Apple", "Banana", "Cherry", "Mango"]
export function FruitPicker() {
return (
<Combobox items={fruits}>
<label htmlFor="fruit" className="text-sm font-medium">Fruit</label>
<ComboboxInputGroup className="flex w-64 items-center rounded-md border">
<ComboboxInput id="fruit" placeholder="Search fruit" />
<ComboboxTrigger />
</ComboboxInputGroup>
<ComboboxContent>
<ComboboxEmpty>No fruit found.</ComboboxEmpty>
<ComboboxList>
{(fruit: string) => (
<ComboboxItem key={fruit} value={fruit}>
{fruit}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
)
}Examples
import {
Combobox,
ComboboxInputGroup,
ComboboxInput,
ComboboxTrigger,
ComboboxContent,
ComboboxList,
ComboboxItem,
ComboboxEmpty,
} from '@/components/ui/combobox';
const frameworks = ["React", "Vue", "Angular", "Svelte", "Solid", "Next.js", "Nuxt", "Remix"];
export function Example() {
return (
<Combobox items={frameworks} openOnInputClick>
<div className="space-y-2">
<label htmlFor="combobox-framework" className="block text-sm font-medium leading-none">Framework</label>
<ComboboxInputGroup className="flex w-[280px] items-center gap-1 rounded-md border border-input focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<ComboboxInput id="combobox-framework" placeholder="Search frameworks..." />
<ComboboxTrigger />
</ComboboxInputGroup>
</div>
<ComboboxContent>
<ComboboxEmpty>No frameworks found.</ComboboxEmpty>
<ComboboxList>
{(fw: string) => (
<ComboboxItem key={fw} value={fw}>
{fw}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
);
}import {
Combobox,
ComboboxInput,
ComboboxTrigger,
ComboboxContent,
ComboboxList,
ComboboxItem,
ComboboxEmpty,
ComboboxGroup,
ComboboxGroupLabel,
} from '@/components/ui/combobox';
const languages = [
{ value: "Frontend", items: ["JavaScript", "TypeScript", "HTML", "CSS"] },
{ value: "Backend", items: ["Python", "Go", "Rust", "Java"] },
];
export function Example() {
return (
<Combobox items={languages} openOnInputClick>
<div className="flex w-[280px] items-center gap-1 rounded-md border border-input focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<ComboboxInput placeholder="Search languages..." />
<ComboboxTrigger />
</div>
<ComboboxContent>
<ComboboxEmpty>No results found.</ComboboxEmpty>
<ComboboxList>
{(group: { value: string; items: string[] }) => (
<ComboboxGroup key={group.value}>
<ComboboxGroupLabel>{group.value}</ComboboxGroupLabel>
{group.items.map((item) => (
<ComboboxItem key={item} value={item}>
{item}
</ComboboxItem>
))}
</ComboboxGroup>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
);
}import {
Combobox,
ComboboxInput,
ComboboxTrigger,
ComboboxClear,
ComboboxContent,
ComboboxList,
ComboboxItem,
ComboboxEmpty,
} from '@/components/ui/combobox';
const countries = ["United States", "United Kingdom", "Canada", "Australia", "Germany", "France", "Japan"];
export function Example() {
return (
<Combobox items={countries} openOnInputClick>
<div className="flex w-[280px] items-center gap-1 rounded-md border border-input focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<ComboboxInput placeholder="Select a country..." />
<ComboboxClear />
<ComboboxTrigger />
</div>
<ComboboxContent>
<ComboboxEmpty>No countries found.</ComboboxEmpty>
<ComboboxList>
{(country: string) => (
<ComboboxItem key={country} value={country}>
{country}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
);
}Selected ID: none
import {
Combobox,
ComboboxInput,
ComboboxClear,
ComboboxTrigger,
ComboboxContent,
ComboboxList,
ComboboxItem,
ComboboxEmpty,
createComboboxItems,
} from '@/components/ui/combobox';
import { useState } from 'react';
type User = { id: string; name: string; email: string };
const users: User[] = [
{ id: "u1", name: "Ada Lovelace", email: "ada@example.com" },
{ id: "u2", name: "Grace Hopper", email: "grace@example.com" },
{ id: "u3", name: "Katherine Johnson", email: "katherine@example.com" },
{ id: "u4", name: "Linus Torvalds", email: "linus@example.com" },
];
const userItems = createComboboxItems(users, {
getValue: (user) => user.id,
getLabel: (user) => user.name,
});
export function Example() {
const [value, setValue] = useState<string | null>(null);
return (
<div className="space-y-3">
<Combobox items={userItems} value={value} onValueChange={setValue} openOnInputClick>
<div className="flex w-[280px] items-center gap-1 rounded-md border border-input focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<ComboboxInput placeholder="Select a user..." />
<ComboboxClear />
<ComboboxTrigger />
</div>
<ComboboxContent>
<ComboboxEmpty>No users found.</ComboboxEmpty>
<ComboboxList>
{(user: User) => (
<ComboboxItem key={user.id} value={user.id}>
{user.name}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
<p className="text-sm text-muted-foreground">Selected ID: {value ?? "none"}</p>
</div>
);
}Notes
Selecting by ID
createComboboxItems derives each item's value and label, so value and onValueChange use IDs while the list receives the full object. Create the collection at module scope, or memoize it for runtime data:
const userItems = React.useMemo(
() => createComboboxItems(users, { getValue: (user) => user.id, getLabel: (user) => user.name }),
[users]
)Naming the input
ComboboxLabel names the trigger. Name the input with a <label htmlFor> on its id, or aria-label, as in the default example. The agent reads the input's name.
Rendering in place
ComboboxContent portals by default. Pass portal={false} to render inside its parent and inherit its stacking.
API
details.cancel() refuses the change.setValue.null turns filtering off.Takes the props of the element it renders.
<label htmlFor> at it. The agent reads that label.onValueChange receives.ComboboxCollection inside it.Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
onValueChange receives, such as an id.Agent
Inside an AgentProvider, it appears in agent.snapshot() as combobox.
Reads
labelThe input's label, aria-label, or placeholder.
valueThe chosen label, a list of labels when multiple, or null.
openWhether the list is showing.
itemsEvery option's label from items, or what the open list shows.
multiplePresent when the combobox holds several values.
disabledTrue when the combobox is blocked.
Actions
select("Svelte")Picks by label, then by value, open or closed. A miss lists the options.
search("sv")Types into the input and returns the labels that match.
open() / close()Whichever fits the current state.
setValue(["Vue", "Svelte"])Replaces the whole list. Only when multiple.
An agent's change runs through onValueChange, onInputValueChange and onOpenChange like anyone's. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. A disabled combobox refuses on its own, and readOnly refuses select, setValue and search.
await agent.act({
steps: [{ ref: "Framework", action: "select", args: ["Svelte"] }],
})Accessibility
- The input has role="combobox" and controls the list popup.
- Give the input a name with a
<label htmlFor>or aria-label. The agent reads the same name. ComboboxEmptyandComboboxStatusannounce changes politely.- The list is a listbox; focus stays in the input as the highlight moves.