Autocomplete

A Base UI autocomplete composed with Notion-style menu groups, items, labels, and separators.

Installation

pnpm add @notion-kit/ui

Examples


Popover Menu

Use AutocompleteContent variant="inline" when another primitive owns the overlay positioning. This keeps existing popover menus as Popover + Autocomplete.

Anatomy

<Autocomplete>
  <AutocompleteInput />
  <AutocompleteContent>
    <AutocompleteEmpty />
    <AutocompleteList>
      <AutocompleteGroup>
        <AutocompleteLabel />
        <AutocompleteCollection>
          <AutocompleteItem />
        </AutocompleteCollection>
      </AutocompleteGroup>
    </AutocompleteList>
  </AutocompleteContent>
</Autocomplete>

For grouped root items, render groups from AutocompleteList:

<Autocomplete items={groups}>
  <AutocompleteInput />
  <AutocompleteContent>
    <AutocompleteEmpty />
    <AutocompleteList>
      {(group) => (
        <AutocompleteGroup items={group.items}>
          <AutocompleteLabel title={group.label} />
          <AutocompleteCollection>
            {(item) => <AutocompleteItem value={item} label={item} />}
          </AutocompleteCollection>
        </AutocompleteGroup>
      )}
    </AutocompleteList>
  </AutocompleteContent>
</Autocomplete>

API Reference

Autocomplete

The Base UI autocomplete root. It owns the input value, filtering, highlight state, and item collection.

PropTypeDefaultDescription
itemsItem[] | { items: Item[] }[]-Items to filter and render through AutocompleteCollection.
itemToStringValue(item: Item) => string-Converts object items to searchable text.
valuestring-Controlled input value.
onValueChange(value: string) => void-Handler called when the input value changes.
filterBase UI filter function-Optional custom filter. Prefer the internal filter by default.
filteredItemsItem[] | { items: Item[] }[]-Controlled filtered result set.
openboolean-Whether the autocomplete popup/list is open.
autoHighlight"always" | "input" | "none" | boolean-How Base UI highlights a matching item.
openOnInputClickboolean-Opens the list when the input is clicked.

AutocompleteInput

The search input. It renders the shared Input primitive and supports the same visual affordances.

PropTypeDefaultDescription
searchboolean-Shows the search icon.
clearboolean-Shows the clear affordance when there is text.
placeholderstring-Placeholder text for the input.
onCancel() => void-Handler passed to the underlying input.
classNames{ wrapper?: string }-Classes for the input wrapper.

AutocompleteContent

The popup surface. Floating content is positioned by Base UI; inline content renders in-flow for composed menus.

PropTypeDefaultDescription
variant"floating" | "inline""floating"Whether to render a positioned popup or in-flow content.
side"top" | "right" | "bottom" | "left""bottom"Preferred side for floating content.
align"start" | "center" | "end""start"Preferred alignment for floating content.
sideOffsetnumber4Distance from the anchor for floating content.
alignOffsetnumber-Alignment offset for floating content.
collisionPaddingnumber | Padding-Padding used when avoiding viewport collisions.
anchorBase UI anchor-Custom anchor for floating content.

AutocompleteList

The scrollable list viewport. When the root receives grouped items, pass a render function as children and render one AutocompleteGroup per group.

PropTypeDefaultDescription
childrenReact.ReactNode | ((item, index) => ReactNode)-Static content or a Base UI item/group renderer.

AutocompleteCollection

Renders the filtered items from the nearest root or group.

PropTypeDefaultDescription
children(item, index) => ReactNode-Renderer for each filtered item.

AutocompleteGroup

Groups related autocomplete items with menu spacing.

PropTypeDefaultDescription
itemsItem[]-Group items. Use only when rendering a grouped root item from AutocompleteList.

For flat root items, keep the visual group item-less and let AutocompleteCollection read the root filtered items.

AutocompleteLabel

A non-interactive label used to title a group of items.

PropTypeDefaultDescription
titleReact.ReactNode-The group label content.

AutocompleteItem

A single selectable autocomplete row. Extends the shared MenuItem visual props.

PropTypeDefaultDescription
valueItem-The item value selected by Base UI.
labelReact.ReactNodeString(value)The main item label.
iconReact.ReactNode-An optional leading icon.
descstring-An optional description below the label.
variant"default" | "secondary" | "sidebar" | "warning" | "error""default"The visual style of the item.
disabledboolean-Whether the item is disabled.
onClickReact.MouseEventHandler<HTMLElement>-Handler called when the item is clicked.

Use MenuItemAction as trailing content for metadata, status, or shortcuts.

AutocompleteEmpty

Content shown only when Base UI reports an empty filtered result set.

AutocompleteSeparator

A visual divider between autocomplete groups.

AutocompleteTrigger

Optional trigger for autocomplete compositions that need a trigger affordance.

AutocompleteClear

Clears the current autocomplete input value.

AutocompleteStatus

Displays Base UI autocomplete status text.