--- title: Autocomplete description: An input that suggests matching options as you type. links: doc: https://base-ui.com/react/components/autocomplete#api-reference --- ## Preview ## Installation CLI Manual ```bash npx @olyx/cli@latest add autocomplete ``` Install the following dependencies: ```bash npm install @base-ui/react ``` Copy and paste the following code into your project. Update the import paths to match your project setup. ## Usage ```tsx import { Autocomplete, AutocompleteEmpty, AutocompleteInput, AutocompleteItem, AutocompleteList, AutocompletePopup, AutocompleteGroup, AutocompleteGroupLabel, AutocompleteSeparator, } from "@/components/ui/autocomplete" ``` ```tsx const items = [ { value: "apple", label: "Apple" }, { value: "banana", label: "Banana" }, { value: "orange", label: "Orange" }, ] No results found. {(item) => ( {item.label} )} ``` ## API Reference ### Autocomplete Root component managing state and providing context to child components. | Prop | Type | Description | | ---------------- | -------------------------- | ------------------------------------ | | `items` | `readonly unknown[]` | Array of items to display | | `open` | `boolean` | Controls popup open state | | `disabled` | `boolean` | Disables the autocomplete | | `autoHighlight` | `boolean` | Auto-highlight first match | | `inlineAutocompletion` | `boolean` | Inline suggestion while typing | | `value` | `unknown` | Currently selected value | | `...props` | Base UI Autocomplete props | All standard autocomplete attributes are supported | ### AutocompleteInput Input field with support for icons and action buttons. | Prop | Type | Default | Description | | ------------- | --------------------------- | ----------- | ------------------------------------- | | `startAddon` | `React.ReactNode` | - | Icon or element at input start | | `showTrigger` | `boolean` | `false` | Display trigger (chevron) button | | `showClear` | `boolean` | `false` | Display clear (X) button | | `...props` | Base UI Autocomplete Input props | - | All standard autocomplete input attributes are supported | ### AutocompletePopup Popup container for suggestions and results. | Prop | Type | Description | | ----- | ------ | ------------------------------- | | `children` | `React.ReactNode` | Content inside popup | | `side` | `string` | Popup placement side | | `...props` | Base UI Autocomplete Popup props | All standard autocomplete popup attributes are supported | ### AutocompleteList Scrollable container for autocomplete items. | Prop | Type | Description | | ---------- | ----------------- | ------------------------ | | `children` | `React.ReactNode` | List item elements | | `...props` | Base UI Autocomplete List props | All standard autocomplete list attributes are supported | ### AutocompleteItem Individual selectable item in the list. | Prop | Type | Description | | ------- | --------- | -------------------- | | `value` | `unknown` | Item value | | `children` | `React.ReactNode` | Item label/content | | `...props` | Base UI Autocomplete Item props | All standard autocomplete item attributes are supported | ### AutocompleteEmpty Message displayed when no results match. | Prop | Type | Description | | ---------- | ----------------- | ----------------- | | `children` | `React.ReactNode` | Empty state text | | `...props` | Base UI Autocomplete Empty props | All standard autocomplete empty attributes are supported | ### AutocompleteGroup Container for grouped items. | Prop | Type | Description | | ------- | ----------------- | ---------------- | | `children` | `React.ReactNode` | Group items | | `...props` | Base UI Autocomplete Group props | All standard autocomplete group attributes are supported | ### AutocompleteGroupLabel Label for an item group. | Prop | Type | Description | | ---------- | ----------------- | ------------- | | `children` | `React.ReactNode` | Group title | | `...props` | Base UI Autocomplete Group Label props | All standard autocomplete group label attributes are supported | ### AutocompleteSeparator Visual separator between groups. Renders a horizontal line divider without additional props. ## Examples ### Disabled ### With Label ### Inline Autocomplete Autofill the input with the highlighted item while navigating with arrow keys. ### Auto Highlight Automatically highlight the first matching option when results appear. ### With Clear Button ### With Trigger and Clear Buttons ### With Groups Organize items into categorized sections for better organization. ### Limit Results Restrict displayed results and show only a set number of matches. ### Async Search Load suggestions dynamically based on user input. ### Form Integration Use autocomplete within forms for controlled selection handling. ### With Start Addon Display an icon at the input start for visual context.