Typeahead input that filters suggestions as you search.
npx shadcn@latest add @iconiq/b-autocomplete"use client";
import { useState } from "react";
import {
Autocomplete,
AutocompleteContent,
AutocompleteEmpty,
AutocompleteInput,
AutocompleteItem,
AutocompleteList,
} from "@/components/ui/b-autocomplete";
type Country = {
code: string;
name: string;
region: string;
};
const countries: Country[] = [
{ code: "CA", name: "Canada", region: "North America" },
{ code: "FR", name: "France", region: "Europe" },
{ code: "JP", name: "Japan", region: "Asia" },
{ code: "MX", name: "Mexico", region: "North America" },
{ code: "US", name: "United States", region: "North America" },
];
export function AutocompletePreview() {
const [query, setQuery] = useState("");
return (
<div className="w-full max-w-xl">
<Autocomplete
itemToStringValue={(country) => country.name}
items={countries}
onValueChange={setQuery}
value={query}
>
<AutocompleteInput
label="Search countries"
placeholder="e.g. Canada"
/>
<AutocompleteContent>
<AutocompleteList>
{(country: Country, index: number) => (
<AutocompleteItem
description={country.region}
index={index}
key={country.code}
value={country}
>
{country.name}
</AutocompleteItem>
)}
</AutocompleteList>
<AutocompleteEmpty>No country matches that query.</AutocompleteEmpty>
</AutocompleteContent>
</Autocomplete>
</div>
);
}itemsItem collection used for list filtering. Pass a flat array or grouped items for sectioned results.
Type readonly Item[]
valueControlled input text shown in the field.
Type string
defaultValueInitial input text for uncontrolled usage.
Type string
onValueChangeCalled when the input text changes from typing or when a suggestion is accepted.
Type (value: string, eventDetails) => void
itemToStringValueMaps each item to the string used for filtering and the committed input value.
Type (item: Item) => string
autoHighlightAutomatically highlights the first matching item while typing.
Type boolean | "always"·Default true
keepHighlightWhen true, keeps the highlighted item when the pointer leaves the list.
Type boolean·Default false
openControlled popup state. Pair with onOpenChange.
Type boolean
onOpenChangeCalled when the suggestion panel opens or closes. Use with open for controlled popup state.
Type (open: boolean, eventDetails) => void
onItemHighlightedCalled when the highlighted suggestion changes from keyboard, pointer, or programmatic updates.
Type (item: Item | undefined, eventDetails) => void
openOnInputClickWhen true, clicking the input opens the suggestion panel even before typing.
Type boolean·Default false
submitOnItemClickWhen true, selecting an item submits the owning form. Useful for search inputs.
Type boolean·Default false
modalWhen true, traps focus inside the popup. Pair with AutocompleteBackdrop for a dimmed overlay.
Type boolean·Default false
isItemEqualToValueCustom equality for object items. Use when items are recreated on each render.
Type (item: Item, value: Item) => boolean
labelOptional field label rendered above the input and linked with htmlFor.
Type React.ReactNode
labelClassNameOptional class names merged onto the field label.
Type string
placeholderShown when the input is empty.
Type string
showClearControls whether AutocompleteClear is rendered.
Type boolean·Default true
showTriggerWhen true, renders a chevron trigger that toggles the suggestion panel.
Type boolean·Default false
disabledDisables the input, clear button, and trigger.
Type boolean·Default false
aria-invalidWhen true, applies destructive border and ring styling to the input shell.
Type boolean | 'true' | 'false'
disabledDisables the clear button.
Type boolean·Default false
classNameMerged onto the clear button.
Type string
disabledDisables the trigger button.
Type boolean·Default false
sidePreferred side for the popup.
Type "top" | "right" | "bottom" | "left"·Default "bottom"
alignPopup alignment relative to the input anchor.
Type "start" | "center" | "end"·Default "start"
sideOffsetDistance between the input and the popup.
Type number·Default 6
classNameMerged onto the animated popup panel.
Type string
childrenRender explicit AutocompleteItem children or a render function when using the root items prop.
Type ReactNode | ((item, index) => ReactNode)
classNameMerged with the default list spacing and scroll classes.
Type string
valueItem value passed to Base UI for selection handling.
Type Item
descriptionOptional secondary line below the primary label.
Type ReactNode
childrenMessage shown when the filtered list is empty.
Type ReactNode·Default "No results found."
childrenStatus text announced politely to screen readers, such as Loading or No matches.
Type ReactNode
itemsItems rendered inside this group when using grouped root items.
Type readonly Item[]
childrenGroup heading text.
Type ReactNode
Horizontal divider between suggestion groups or rows.
Renders the current filtered collection when not using AutocompleteList render props.
Reads the current input value from context for custom display layouts.
Leading icon slot rendered inside AutocompleteInput.
Dimmed overlay for modal autocomplete usage. Render as a sibling of AutocompleteContent when modal is true.
Row wrapper for multi-column or complex suggestion layouts.
Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together.
Dependencies: @base-ui/react, motion, lucide-react.
This page documents the Base UI install only. Radix UI does not ship a dedicated autocomplete primitive.
Install into components/ui/b-autocomplete.tsx so imports match the usage examples.
The generated registry file is /r/b-autocomplete.json.
Contact
Additionally, if you find any bug or issue, feel free to raise an issue.
Type to filter suggestions