docs/components/autocomplete
Sections
Components
Utilities
Forms
Hooks
Copy Markdown
Displays a searchable list of options.
PreviewCode
Search fruits
CLIManual
pnpmbunnpmyarn
pnpm dlx shadcn@latest add @shark/autocomplete
Autocomplete
├── AutocompleteInput
└── AutocompleteContent
├── AutocompleteEmpty
└── AutocompleteList
└── AutocompleteGroup
├── AutocompleteGroupLabel
└── AutocompleteItem
import { useFilter, useListCollection } from "@ark-ui/react";
import {
Autocomplete,
AutocompleteContent,
AutocompleteEmpty,
AutocompleteGroup,
AutocompleteInput,
AutocompleteItem,
AutocompleteList,
} from "@/components/ui/autocomplete";
const { contains } = useFilter({ sensitivity: "base" });
const { collection, filter } = useListCollection({
initialItems: [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
],
filter: contains,
});
<Autocomplete
collection={collection}
onInputValueChange={({ inputValue }) => filter(inputValue)}
>
<AutocompleteInput placeholder="Select an option" />
<AutocompleteContent>
<AutocompleteEmpty />
<AutocompleteList>
{items.map((item) => (
<AutocompleteItem item={item} key={item.value}>
{item.label}
</AutocompleteItem>
))}
</AutocompleteList>
</AutocompleteContent>
</Autocomplete>
Control the selected value with value and onValueChange props.
PreviewCode
Selected: banana
PreviewCode
PreviewCode
PreviewCode
PreviewCode
PreviewCode
PreviewCode
Use Field components to style with the field components.
PreviewCode
Country
We'll use this for shipping estimates
Pass showClear to AutocompleteInput to show a clear button.
PreviewCode
Pass showTrigger to AutocompleteInput to show the dropdown trigger button.
PreviewCode
Use InputGroupAddon to add a start icon to the input.
PreviewCode
Root component.
| Prop | Type | Default |
|---|---|---|
collection | ListCollection<T> | required |
value | string[] | - |
defaultValue | string[] | - |
onValueChange | (details: ValueChangeDetails<T>) => void | - |
onInputValueChange | (details: InputValueChangeDetails) => void | - |
disabled | boolean | - |
openOnClick | boolean | true |
lazyMount | boolean | true |
unmountOnExit | boolean | true |
className | string | - |
Input with dropdown trigger and clear button.
| Prop | Type | Default |
|---|---|---|
size | `"sm" | "md" |
showTrigger | boolean | false |
showClear | boolean | false |
disabled | boolean | - |
className | string | - |
Holds the dropdown options. Displayed in a portal.
| Prop | Type | Default |
|---|---|---|
className | string | - |
asChild | boolean | - |
Groups related items. Use with groupBy on the collection.
| Prop | Type | Default |
|---|---|---|
heading | `string | ReactNode` |
className | string | - |
Label for a group of options. Use inside AutocompleteGroup.
| Prop | Type | Default |
|---|---|---|
className | string | - |
asChild | boolean | - |
Single selectable option in the dropdown list.
| Prop | Type | Default |
|---|---|---|
item | T | required |
className | string | - |
asChild | boolean | - |
Shown when no options match the current filter. Use for empty state.
| Prop | Type | Default |
|---|---|---|
className | string | - |
asChild | boolean | - |
For a complete list of props, see the Ark UI documentation.
[
Previous page
Aspect Ratio ](/docs/components/aspect-ratio)[
Next page
Avatar ](/docs/components/avatar)
On This Page
InstallationAnatomyUsageControlledStatesInvalidDisabledSizesSmallMediumLargeExamplesGroupWith FieldWith clear buttonWith triggerWith start iconAPI ReferenceAutocompleteAutocompleteInputAutocompleteContentAutocompleteGroupAutocompleteGroupLabelAutocompleteItemAutocompleteEmpty