āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/cosscom/coss/components/autocomplete ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
title: Autocomplete description: An input that suggests options as you type.
<ComponentPreview name="autocomplete-demo" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
npx shadcn@latest add @coss/autocomplete
</TabsPanel>
<TabsPanel value="manual">
<Steps>
<Step>Install the following dependencies:</Step>
npm install @base-ui-components/react
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="autocomplete" title="components/ui/autocomplete.tsx" /><Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsPanel> </CodeTabs>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>
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. |
<ComponentPreview name="autocomplete-disabled" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-sm" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-lg" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-with-label" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
Autofill the input with the highlighted item while navigating with arrow keys.
<ComponentPreview name="autocomplete-inline" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
Automatically highlight the first matching option.
<ComponentPreview name="autocomplete-autohighlight" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-with-clear" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-with-trigger-clear" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-grouped" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-limit" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-async" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
<ComponentPreview name="autocomplete-form" className="[&_.preview>*]:w-full [&_.preview>*]:max-w-64" />
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā