Skip to content

Autocomplete

An input that suggests options as you type.

API Reference

Installation

pnpm dlx shadcn@latest add @frontal-labs/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

Autocomplete

The root autocomplete component. Manages the autocomplete state and provides context to child components.

AutocompleteInput

The input field component with extended features for size variants and addon support.

AutocompletePopup

The popup container that displays the autocomplete suggestions. The surface is elevated with shadow-menu and surface-ring.

About dark: the popup renders with the dark palette by default. Pass dark={false} when it should follow the ambient theme instead — next-themes sets dark on <html> and the portal lands in document.body, inside it, so the popup can pick up the ambient theme once dark is turned off. For a popup opened from a .dark region scoped mid-page, which a portal does escape, portalProps.container is usually the better tool: it renders into the scoped node and keeps inheritance intact in both directions without needing this prop. dark applies .dark to the positioner inside the portal, so the tokens inherit down to the popup and everything within it.

AutocompleteList

A scrollable container for autocomplete items.

AutocompleteItem

An individual selectable autocomplete item.

AutocompleteEmpty

Displays a message when no results are found.

AutocompleteGroup

Groups related autocomplete items together.

AutocompleteGroupLabel

Displays a label for an autocomplete group.

AutocompleteCollection

Used to wrap items within a group for rendering.

Examples

Disabled

Small Size

Large Size

With Label

Inline Autocomplete

Autofill the input with the highlighted item while navigating with arrow keys.

Auto Highlight

Automatically highlight the first matching option.

With Clear Button

With Trigger and Clear Buttons

With Start Addon

Display an icon or other element at the start of the input using the startAddon prop.

With Groups

With Limit Results

Form Integration