Phi
Autocomplete
@dicehub/phiv1.0.0-beta.1

Autocomplete

A free-form text input with an optional filtered suggestion list.

Preview

<script setup>
import { Autocomplete } from "@dicehub/phi/components/autocomplete";

const fruits = [
  { label: "Apple", value: "apple" },
  { label: "Banana", value: "banana" },
  { label: "Cherry", value: "cherry" },
];
</script>

<template>
  <Autocomplete :items="fruits">
    <Autocomplete.InputGroup placeholder="Search fruits..." />
    <Autocomplete.Content>
      <Autocomplete.Empty>No fruit suggestions.</Autocomplete.Empty>
      <Autocomplete.List>
        <template #default="{ item }">
          <Autocomplete.Item :item="item">
            {{ item.label }}
          </Autocomplete.Item>
        </template>
      </Autocomplete.List>
    </Autocomplete.Content>
  </Autocomplete>
</template>

Import

import { Autocomplete } from "@dicehub/phi/components/autocomplete";

Usage

<script setup>
import { Autocomplete } from "@dicehub/phi/components/autocomplete";

const fruits = [
  { label: "Apple", value: "apple" },
  { label: "Banana", value: "banana" },
  { label: "Cherry", value: "cherry" },
];
</script>

<template>
  <Autocomplete :items="fruits">
    <Autocomplete.InputGroup placeholder="Search fruits..." />
    <Autocomplete.Content>
      <Autocomplete.Empty>No fruit suggestions.</Autocomplete.Empty>
      <Autocomplete.List>
        <template #default="{ item }">
          <Autocomplete.Item :item="item">
            {{ item.label }}
          </Autocomplete.Item>
        </template>
      </Autocomplete.List>
    </Autocomplete.Content>
  </Autocomplete>
</template>

The compound API uses a scoped Vue slot for item rendering.

For the shortest default UI, pass items directly.

<Autocomplete
  :items="fruits"
  placeholder="Search fruits..."
  aria-label="Search fruits"
/>

When To Use

Use Autocomplete when suggestions are hints and the final input can be custom text. Use a stricter Select or Combobox when the value must come from a known option list.

Controlled

Control the typed value with v-model:input-value. Suggestions stay optional and do not create a separate selected-value state.

<Autocomplete
  v-model:input-value="inputValue"
  :items="fruits"
  clearable
  placeholder="Type a fruit..."
/>

With Field

Pass label and helper text when the control is part of a form.

Error State

Pass invalid to the root and pair the input with visible validation text.

Grouped

Use groupBy on the collection and render AutocompleteGroup sections from collection.group().

Sizes

Autocomplete and AutocompleteInputGroup support xs, sm, base, and lg.

Custom Filtering

Use filter for local matching rules. For async or server-backed suggestions, pass a custom collection and compose the advanced parts.

<Autocomplete
  :items="fruits"
  :filter="(item, inputValue) => item.label.startsWith(inputValue)"
  placeholder="Search fruits..."
/>

API

Autocomplete

PropTypeDefaultDescription
itemsunknown[][]Items used by the default autocomplete UI.
itemToString(item) => stringitem.label ?? String(item)Maps an item to visible text and default filtering text.
itemToValue(item) => stringitem.value ?? itemToString(item)Maps an item to the Ark option value.
filterfalse | functioncontains labelCustom item filter. Pass false to show all items for the current query.
showOnEmptybooleanfalseShows suggestions before the user enters a query.
placeholderstring-Placeholder for the default input.
labelstring-Optional label rendered above the default input.
clearablebooleanfalseRenders a clear trigger in the default input.
size"xs" | "sm" | "base" | "lg""base"Default input height and text size.
collectionAutocompleteListCollection<T>-Advanced Ark list collection used when composing custom content.
allowCustomValuebooleantrueAllows free-form input values that are not constrained to suggestions.
closeOnSelectbooleantrueCloses the popup after a suggestion is selected.
inputValuestring-Controlled text input value.
openboolean-Controlled popup state.
openOnChangeboolean | functionArk defaultControls whether input changes open the popup.
positioningobject{ placement: "bottom-start", gutter: 4 }Ark positioning options for the popup.
invalidbooleanfalseMarks the control invalid for styling and Ark state.

AutocompleteInputGroup

PropTypeDefaultDescription
size"xs" | "sm" | "base" | "lg""base"Input height and text size.
placeholderstring-Placeholder passed to the internal input.
clearablebooleanfalseRenders an Ark clear trigger inside the control.
showTriggerbooleanfalseShows or hides the optional popup trigger button.

Exports

ExportDescription
AutocompleteSimple items-driven autocomplete, with advanced compound slots when custom content is needed.
Autocomplete.InputGroupStyled input with optional clear and popup triggers.
Autocomplete.ContentPositioned suggestion popup surface.
Autocomplete.ListScrollable suggestion list with scoped-slot item rendering.
Autocomplete.ItemStyled selectable suggestion.
Autocomplete.LabelArk label wrapper for accessible field labeling.
Autocomplete.Group / Autocomplete.GroupLabelGrouped suggestion sections.
Autocomplete.EmptyEmpty state shown when the collection has no matches.
createAutocompleteCollectionAdvanced Phi alias for Ark createListCollection.
useAutocompleteCollectionAdvanced Phi alias for Ark useListCollection.