Autocomplete

An input that suggests options as you type.

API Reference
Loading...
Loading code...

Installation

pnpm dlx shadcn@latest add @uitopia/autocomplete

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:

PropTypeDefaultDescription
size"sm" | "default" | "lg""default"The size variant of the input field.
showTriggerbooleanfalseWhether to display a trigger button (chevron icon) on the right side of the input.
showClearbooleanfalseWhether 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...
Loading...
Loading code...

Form Integration

Loading...
Loading code...