Skip to content

Autocomplete ​

Input with suggestions dropdown. Filters options as you type with keyboard navigation.

vue
<script setup>
import { ref } from 'vue'

const value = ref('')
const options = ['Apple', 'Banana', 'Cherry', 'Date', 'Grape', 'Mango', 'Orange']
</script>

<template>
  <VxAutocomplete v-model="value" :options="options" placeholder="Search fruits..." clearable />
</template>

Object Options ​

Pass objects with value and label fields.

vue
<script setup>
const countries = [
  { value: 'us', label: 'United States' },
  { value: 'gb', label: 'United Kingdom' },
  { value: 'de', label: 'Germany' },
]
</script>

<template>
  <VxAutocomplete v-model="value" :options="countries" placeholder="Search countries..." />
</template>

Select Event ​

Listen to @select to get the full selected item.

vue
<template>
  <VxAutocomplete v-model="value" :options="countries" @select="onSelect" />
</template>

Sizes ​

vue
<template>
  <VxAutocomplete size="sm" placeholder="Small" />
  <VxAutocomplete placeholder="Default" />
  <VxAutocomplete size="lg" placeholder="Large" />
</template>

Disabled Options ​

vue
<script setup>
const options = [
  { value: 'active', label: 'Active option' },
  { value: 'disabled', label: 'Disabled option', disabled: true },
]
</script>

<template>
  <VxAutocomplete :options="options" trigger-on-focus />
</template>

Trigger on Focus ​

Show all suggestions when the input is focused, even without typing.

vue
<template>
  <VxAutocomplete :options="options" trigger-on-focus placeholder="Click to see all..." />
</template>

Remote / Async ​

Use fetch-suggestions for async data fetching. Pairs well with debounce.

vue
<script setup>
async function fetchUsers(query) {
  const res = await fetch(`/api/users?q=${query}`)
  return res.json()
}
</script>

<template>
  <VxAutocomplete :fetch-suggestions="fetchUsers" :debounce="300" placeholder="Search users..." />
</template>

Disabled ​

vue
<template>
  <VxAutocomplete :options="options" disabled />
</template>

Custom Option Slot ​

vue
<template>
  <VxAutocomplete :options="countries" trigger-on-focus>
    <template #option="{ item, highlight }">
      <span class="flag">{{ item.value.toUpperCase() }}</span>
      <span v-html="highlight(item.label)" />
    </template>
  </VxAutocomplete>
</template>

Props ​

PropTypeDefaultDescription
modelValuestring''Input value (v-model)
optionsstring[] | AutocompleteOption[][]Static options list
placeholderstring''Placeholder text
disabledbooleanfalseDisable input
clearablebooleanfalseShow clear button
size'sm' | 'default' | 'lg''default'Input size
debouncenumber0Debounce delay in ms
highlightbooleantrueHighlight matched text
emptyTextstring'No results'Text when no matches
fetchSuggestions(query: string) => Option[] | Promise<Option[]>—Async fetch function
triggerOnFocusbooleanfalseShow suggestions on focus
valueKeystring'value'Key to use as value from option object

Events ​

EventTypeDescription
update:modelValue(value: string) => voidInput value changed
select(item: AutocompleteOption) => voidOption selected
focus(e: FocusEvent) => voidInput focused
blur(e: FocusEvent) => voidInput blurred
clear() => voidInput cleared

Slots ​

SlotPropsDescription
option{ item, index, highlight }Custom option rendering
prefix—Custom prefix icon