Autocomplete
An input that suggests options as you type.
Loading...
Loading code...
Installation
Usage
import {
Autocomplete,
AutocompleteEmpty,
AutocompleteInput,
AutocompleteItem,
AutocompleteList,
AutocompletePopup,
} from "@/components/ui/autocomplete"const items = [
{ value: "apple", label: "Apple" },
{ value: "banana", label: "Banana" },
{ value: "orange", label: "Orange" },
{ value: "grape", label: "Grape" },
]
<Autocomplete items={items}>
<AutocompleteInput placeholder="Search..." />
<AutocompletePopup>
<AutocompleteEmpty>No results found.</AutocompleteEmpty>
<AutocompleteList>
{(item) => <AutocompleteItem key={item.value} value={item}>{item.label}</AutocompleteItem>}
</AutocompleteList>
</AutocompletePopup>
</Autocomplete>API Reference
The AutocompleteInput component extends the original Base UI component with a few extra props:
| Prop | Type | Default | Description |
|---|---|---|---|
size | "sm" | "default" | "lg" | "default" | The size variant of the input field. |
showTrigger | boolean | false | Whether to display a trigger button (chevron icon) on the right side of the input. |
showClear | boolean | false | Whether to display a clear button (X icon) on the right side of the input when there is a value. |
Examples
Disabled
Loading...
Loading code...
Small Size
Loading...
Loading code...
Large Size
Loading...
Loading code...
With Label
Loading...
Loading code...
Inline Autocomplete
Autofill the input with the highlighted item while navigating with arrow keys.
Loading...
Loading code...
Auto Highlight
Automatically highlight the first matching option.
Loading...
Loading code...
With Clear Button
Loading...
Loading code...
With Trigger and Clear Buttons
Loading...
Loading code...
With Groups
Loading...
Loading code...
With Limit Results
Loading...
Loading code...
Async Search
Loading...
Loading code...
Form Integration
Loading...
Loading code...