Prototyper UI

Autocomplete

A text input with suggestions that allows free-form input built on Base UI

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/autocomplete.json
npx shadcn@latest add https://prototyper-ui.com/r/autocomplete.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/autocomplete.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/autocomplete.json

This will add the following files to your project:

  • components/ui/autocomplete.tsx

Usage

import {
  Autocomplete,
  AutocompleteInput,
  AutocompleteContent,
  AutocompleteList,
  AutocompleteItem,
  AutocompleteEmpty,
} from "@/components/ui/autocomplete"

<Autocomplete items={items}>
  <AutocompleteInput placeholder="Search..." />
  <AutocompleteContent>
    <AutocompleteEmpty>No results found.</AutocompleteEmpty>
    <AutocompleteList>
      {(item) => (
        <AutocompleteItem key={item} value={item}>
          {item}
        </AutocompleteItem>
      )}
    </AutocompleteList>
  </AutocompleteContent>
</Autocomplete>

Anatomy

<Autocomplete>
  <AutocompleteInput />
  <AutocompleteContent>
    <AutocompleteEmpty />
    <AutocompleteGroup>
      <AutocompleteGroupLabel />
      <AutocompleteList>
        <AutocompleteItem />
      </AutocompleteList>
    </AutocompleteGroup>
  </AutocompleteContent>
</Autocomplete>
Sub-componentdata-slotPurposeRequired
Autocomplete-Root provider, manages state and filteringYes
AutocompleteInputinput-group-controlText input with optional trigger buttonYes
AutocompleteTriggerautocomplete-triggerButton that toggles the popup open/closedNo
AutocompleteValueautocomplete-valueDisplays the current valueNo
AutocompleteContentautocomplete-contentPositioned popup containing the listYes
AutocompleteListautocomplete-listScrollable list of itemsYes
AutocompleteItemautocomplete-itemIndividual suggestion optionYes
AutocompleteEmptyautocomplete-emptyShown when no items match the filterNo
AutocompleteGroupautocomplete-groupGroups related items togetherNo
AutocompleteGroupLabelautocomplete-group-labelLabel for a group of itemsNo
AutocompleteSeparatorautocomplete-separatorVisual separator between groupsNo
AutocompleteIconautocomplete-iconIcon elementNo
AutocompleteStatusautocomplete-statusScreen-reader-only status messageNo
AutocompleteArrowautocomplete-arrowArrow pointing from popup to triggerNo
AutocompleteBackdropautocomplete-backdropFull-screen backdrop behind the popupNo

Autocomplete vs Combobox

FeatureAutocompleteCombobox
Free-form text inputYesNo (must select an item)
Selection trackingNoYes (value/onValueChange)
Multi-select / chipsNoYes
Item check indicatorNoYes
Trigger buttonOptional (showTrigger)Default
mode propYes (list, both, inline, none)No

Examples

Modes

Loading...

Sections

Loading...

Disabled

Loading...

With Trigger

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the autocomplete:

Slot nameElement
input-group-controlThe text input element
autocomplete-triggerDropdown trigger button
autocomplete-contentPositioned popup panel
autocomplete-listScrollable list container
autocomplete-itemIndividual suggestion
autocomplete-emptyEmpty state message
autocomplete-groupGroup container
autocomplete-group-labelGroup label
autocomplete-separatorSeparator line between groups
autocomplete-valueValue display
autocomplete-iconIcon element
autocomplete-statusScreen-reader status (visually hidden)
autocomplete-arrowPopup arrow
autocomplete-backdropFull-screen backdrop

Customization Examples

/* Widen the popup */
[data-slot="autocomplete-content"] {
  @apply min-w-[20rem];
}

/* Custom highlighted item style */
[data-slot="autocomplete-item"][data-highlighted] {
  @apply bg-primary text-primary-foreground;
}
{/* Override popup alignment */}
<AutocompleteContent align="center" sideOffset={8}>
  {/* ... */}
</AutocompleteContent>

API Reference

Autocomplete

Root component that manages filtering, suggestions, and open/close state.

Prop

Type

All Base UI Autocomplete.Root props are forwarded via ...props.

AutocompleteInput

Text input with optional trigger button, wrapped in an InputGroup.

Prop

Type

All Base UI Autocomplete.Input props are forwarded via ...props.

AutocompleteTrigger

Button that toggles the popup open or closed. Renders a chevron-down icon by default.

Prop

Type

All Base UI Autocomplete.Trigger props are forwarded via ...props.

AutocompleteValue

Displays the current input value.

All Base UI Autocomplete.Value props are forwarded via ...props.

AutocompleteContent

Positioned popup that contains the list. Wraps Autocomplete.Portal, Autocomplete.Positioner, and Autocomplete.Popup.

Prop

Type

All Base UI Autocomplete.Popup props are forwarded via ...props.

AutocompleteList

Scrollable list container for autocomplete items.

Prop

Type

All Base UI Autocomplete.List props are forwarded via ...props.

AutocompleteItem

Individual suggestion option. Unlike ComboboxItem, does not include a check-mark indicator.

Prop

Type

All Base UI Autocomplete.Item props are forwarded via ...props.

AutocompleteEmpty

Message shown when no items match the current filter.

Prop

Type

All Base UI Autocomplete.Empty props are forwarded via ...props.

AutocompleteGroup

Groups related autocomplete items together.

Prop

Type

All Base UI Autocomplete.Group props are forwarded via ...props.

AutocompleteGroupLabel

Label for a group of items.

Prop

Type

All Base UI Autocomplete.GroupLabel props are forwarded via ...props.

AutocompleteSeparator

Visual separator between groups.

Prop

Type

All Base UI Autocomplete.Separator props are forwarded via ...props.

AutocompleteIcon

Icon element within the autocomplete.

Prop

Type

All Base UI Autocomplete.Icon props are forwarded via ...props.

AutocompleteStatus

Screen-reader-only status message that announces changes.

Prop

Type

All Base UI Autocomplete.Status props are forwarded via ...props.

AutocompleteArrow

Arrow element pointing from the popup to the trigger.

Prop

Type

All Base UI Autocomplete.Arrow props are forwarded via ...props.

AutocompleteBackdrop

Full-screen backdrop rendered behind the popup.

Prop

Type

All Base UI Autocomplete.Backdrop props are forwarded via ...props.

AutocompleteCollection

Re-export of AutocompletePrimitive.Collection for defining static item collections.

useAutocompleteFilter

Re-export of AutocompletePrimitive.useFilter hook for custom filtering logic.

Accessibility

Keyboard Interactions

KeyAction
ArrowDownOpens the popup (if closed) or moves to the next item
ArrowUpOpens the popup (if closed) or moves to the previous item
EnterAccepts the highlighted item's value into the input
EscapeCloses the popup
HomeMoves to the first item in the list
EndMoves to the last item in the list
TabCloses the popup and moves focus to the next element

ARIA Attributes

  • The input has role="combobox" with aria-expanded indicating popup state.
  • aria-activedescendant tracks the currently highlighted item.
  • aria-autocomplete reflects the mode prop behavior.
  • AutocompleteContent has role="listbox" for the list of suggestions.
  • AutocompleteItem has role="option" with aria-disabled for disabled items.
  • AutocompleteGroup uses role="group" with aria-labelledby linked to the group label.
  • AutocompleteStatus provides a live region for screen reader announcements.

On this page