Autocomplete

A text input with a list of suggested values. The input stays free-form; picking a suggestion fills the text. Use Combobox instead if the chosen item should be remembered and the value cannot be custom. The input has no border and rests on the color wash unless inline, which also keeps the list in place. Hover and focus only shift lightness. A highlighted row shows the accent dot. Empty, status, and group labels are Light.

Anatomy

<UiAutocompleteRoot :items="items">
  <UiAutocompleteInputGroup>
    <UiAutocompleteIcon />
    <UiAutocompleteInput />
    <UiAutocompleteClear />
    <UiAutocompleteTrigger />
    <UiAutocompleteValue />
  </UiAutocompleteInputGroup>
  <UiAutocompletePortal>
    <UiAutocompletePositioner>
      <UiAutocompletePopup>
        <UiAutocompleteStatus />
        <UiAutocompleteEmpty>No matches.</UiAutocompleteEmpty>
        <UiAutocompleteList v-slot="{ items }">
          <UiAutocompleteGroup v-for="group in items" :key="group.value" :items="group.items">
            <UiAutocompleteGroupLabel>{{ group.value }}</UiAutocompleteGroupLabel>
            <UiAutocompleteCollection v-slot="{ items: groupItems }">
              <UiAutocompleteRow>
                <UiAutocompleteItem v-for="item in groupItems" :key="item.id" :value="item" />
              </UiAutocompleteRow>
            </UiAutocompleteCollection>
          </UiAutocompleteGroup>
        </UiAutocompleteList>
      </UiAutocompletePopup>
    </UiAutocompletePositioner>
  </UiAutocompletePortal>
</UiAutocompleteRoot>

Item values

Pass the item itself as value on each UiAutocompleteItem. itemToStringValue (or label / value / title on the object) is used for the input text and the default filter.

Examples

Drive items yourself (filter null) and put loading, error, or result counts in UiAutocompleteStatus. Hide the portal until there is a status.

Inline autocomplete

mode="both" filters the list and temporarily fills the input with the highlighted item (the rest of the match is selected). mode also accepts list (default), inline, and none.

Grouped

Pass groups as { value, items }[]. Render UiAutocompleteGroup, GroupLabel, and Collection inside the list.

Fuzzy matching

Replace the default includes filter with a filter function so typos and scattered characters still match.

Limit results

limit caps visible rows. Root’s slot exposes hiddenCount for UiAutocompleteStatus.

Auto highlight

autoHighlight highlights the first match after the user types. Use "always" when the list is shown inline (for example inside a dialog).

Command palette

inline plus a controlled open list inside a Dialog. Items run an action on click instead of only filling the field.

Grid layout

grid lets arrow keys move across UiAutocompleteRow cells. This demo inserts the emoji into a neighboring text field.

Virtualized

virtualized skips automatic scrollIntoView so a large list can own scrolling. This demo renders 1000 items with native overflow (no extra virtualization library).

API reference

Root

Groups all parts. Renders a <div>. Default slot also receives { items, query, matchCount, hiddenCount }.

PropTypeDefaultDescription
itemsunknown[] | Group[][]Flat items or groups with an items array.
itemToStringValue(item) => stringlabel / value / titleString used for the input and the default filter.
filter((item, query, itemToString?) => boolean) | nullincludesCustom matcher. null disables internal filtering.
defaultValuestring''Uncontrolled input value.
valuestring—Controlled input (v-model:value).
defaultOpenbooleanfalseUncontrolled popup.
openboolean—Controlled popup (v-model:open).
autoHighlightboolean | 'always'—Highlight the first match while typing, or always.
keepHighlightboolean—Keep the highlighted item when the pointer leaves the list.
highlightItemOnHoverbooleantrueHighlight on pointer move.
loopFocusbooleantrueArrow keys wrap between the input and the ends of the list.
limitnumber-1Max visible items. -1 is unlimited.
mode'list' | 'both' | 'inline' | 'none''list'Filtering and inline autocompletion.
inlineboolean—Render the list in-place; skip outside-press dismiss.
gridboolean—Arrow keys move by row/column.
virtualizedboolean—Do not auto-scroll the highlighted item into view.
openOnInputClickboolean—Open the popup when the input is clicked.
disabledboolean—Ignore interaction. Sets data-disabled.

Emits select with the chosen item and itemHighlighted when the highlight moves.

AttributeDescription
data-openPresent when the popup is open.
data-disabledPresent when the autocomplete is disabled.
data-inlinePresent when inline is set.

Input

Combobox field. Renders an <input>. Arrow keys move the highlight, Enter selects, Escape closes.

PropTypeDefaultDescription
placeholderstring—Placeholder text.
idstring—Native id.
AttributeDescription
data-popup-openPresent when the popup is open.
data-list-emptyPresent when there are no visible items.
data-disabledPresent when disabled.

InputGroup

Lays out the field with icon, clear, and trigger. Registers as the popup anchor.

AttributeDescription
data-popup-openPresent when the popup is open.

Trigger

Button that opens and closes the popup. Renders a <button>.

AttributeDescription
data-popup-openPresent when the popup is open.
data-disabledPresent when disabled.

Clear

Clears the input. Hidden when the value is empty.

Icon

Decorative icon next to the input.

Value

Current input text. Default slot is the string; scoped slot receives { value }.

Portal

Teleports to body while the popup is present.

PropTypeDefaultDescription
hiddenboolean—Skip rendering even while present.
AttributeDescription
data-openPresent when the popup is open.
data-closedPresent while present but not open.
data-starting-stylePresent while animating in.
data-ending-stylePresent while animating out.

Positioner

Pins the popup to the input or trigger with position: fixed. Sets --anchor-width, --available-width, and --available-height.

PropTypeDefaultDescription
sideOffsetnumber4Gap below the anchor.
align'start' | 'end''start'Align to the start or end of the anchor.

Popup surface. Enter and leave use data-starting-style / data-ending-style (scale 0.98, 100ms). No animation library. No drop-shadow.

AttributeDescription
data-openPresent when open.
data-closedPresent when closed.
data-emptyPresent when the list is empty.
data-starting-stylePresent while animating in.
data-ending-stylePresent while animating out.

List

Listbox. Scoped slot exposes the filtered items (flat or grouped).

AttributeDescription
data-emptyPresent when there are no visible items.

Item

One option. Renders a role="option" element. data-highlighted for the active row.

Group

Section of items. Renders role="group".

PropTypeDefaultDescription
itemsunknown[]—Items for Collection.

GroupLabel

Heading for a group.

Collection

Passes the current group’s items to its scoped slot.

Row

A grid row (role="row") for grid keyboard movement.

Status

Live region for loading, errors, or “hiding N results”.

Empty

Shown when the filter matches nothing.

Separator

Visual divider inside the popup.