Skip to content

Autocomplete

Autocomplete input with dropdown suggestions and keyboard navigation. Supports custom option rendering, filtering, and various data formats.

Import

typescript
import { Autocomplete } from 'vuiii'

Basic Usage

vue
// Basic usage with string array import { Autocomplete } from 'vuiii'

<Autocomplete v-model="search" :options="['Apple', 'Banana', 'Cherry']" />

Props

PropTypeDefaultDescription
modelValuestring''Input text value (v-model)
optionsT[] | Record<string, any>-Options to display in the dropdown
optionLabelstring | ((item) => any)-Key or function to extract the display label
optionValuestring | ((item) => any)-Key or function to extract the option value
optionDisabledstring | ((item) => any)-Key or function to mark an option as disabled
optionDescriptionstring | ((item) => any)-Key or function to extract description text
optionIconstring | ((item) => any)-Key or function to extract the icon name
groupLabelstring | ((item) => any)-Key or function to extract a group's label
groupOptionsstring | ((item) => any)-Key or function to extract a group's options
placeholderstring-Input placeholder text
disabledbooleanfalseDisables the input
size'small' | 'normal' | 'large''normal'Input size
invalidbooleanfalseShows the invalid/error styling
pillbooleanfalseRounded pill shape
prefixIconstring-Icon name to show before the input
suffixIconstring-Icon name to show after the input
filter(option: Option, query: string) => boolean-Custom filter function
dropdownPlacement'left' | 'right' | 'center'-Dropdown alignment relative to the input
inputClassany-Class(es) applied to the native input element

Slots

SlotDescription
prefixContent before the input (replaces prefixIcon)
suffixContent after the input (replaces suffixIcon)
optionCustom option rendering. Props: { option, index, isHighlighted }

Events

EventPayloadDescription
selectOption<T>When an option is selected
prefix-icon-click-When the prefix icon is clicked
suffix-icon-click-When the suffix icon is clicked

More Examples

vue
// With object options and extractors const users = [ { id: 1, name: 'John Doe', email: 'john@example.com' }, { id: 2,
name: 'Jane Smith', email: 'jane@example.com' } ]

<Autocomplete
  v-model="search"
  :options="users"
  option-label="name"
  option-value="id"
  option-description="email"
  @select="(option) => (selectedUser = option.data)"
/>
vue
// With custom filter function const customFilter = (option, query) => { return option.label.startsWith(query) }

<Autocomplete v-model="search" :options="options" :filter="customFilter" />
vue
// With custom option rendering
<Autocomplete v-model="search" :options="users" option-label="name">
  <template #option="{ option, isHighlighted }">
    <div :class="{ highlighted: isHighlighted }">
      <strong>{{ option.label }}</strong>
      <small>{{ option.description }}</small>
    </div>
  </template>
</Autocomplete>

Storybook

For interactive examples with all variants, see Autocomplete in Storybook.

Released under the MIT License.