# Autocomplete

A suggestion input that filters as you type. The input carries the combobox semantics and the dropdown is a listbox; on selection the label is filled back in. Full keyboard navigation (arrow keys / Enter / ESC). By default the dropdown is appended to the body (fixed positioning so it follows the input).

Autocomplete
<template>
  <div class="demo-col" style="gap: 18px">
    <div class="demo-row" style="gap: 12px; flex-wrap: wrap">
      <LhAutocomplete
        v-model="value"
        :options="options"
        placeholder="Type a keyword (matches shown by default)"
        @select="onSelect"
      />
      <LhAutocomplete v-model="value" :options="options" disabled />
    </div>
    <div class="demo-row" style="gap: 12px; flex-wrap: wrap">
      <LhAutocomplete v-model="emptyValue" :options="[]">
        <template #empty>
          <span class="demo-note">Slot empty: no matching themes</span>
        </template>
      </LhAutocomplete>
      <LhAutocomplete
        v-model="readonlyValue"
        :options="options"
        :open-on-focus="false"
        placeholder="No panel on focus; filters once you type"
      />
    </div>
    <p class="demo-note">Current value: {{ value || '(empty)' }}{{ selected }}</p>
  </div>
</template>

<script>
export default {
  data: () => ({
    value: '',
    selected: '',
    emptyValue: '',
    readonlyValue: '',
    options: [
      { label: 'Ink' },
      { label: 'Rice paper' },
      { label: 'Seal' },
      { label: 'Negative space' },
      { label: 'Gongbi (disabled)', disabled: true },
    ],
  }),
  methods: {
    onSelect(value) {
      this.selected = `, selected: ${value}`
    },
  },
}
</script>

# Props

Prop Description Type Default
v-model / modelValue Input value (controlled two-way binding; Vue 2 uses the modelValue prop + input event) string ''
options Suggestion options (label is both the display and fill-back text, value is the submitted value; defaults to the label) LhAutocompleteOption[] []
caseSensitive Case-sensitive matching boolean false
trim Trim the query string before matching boolean true
placeholder Placeholder hint string ''
disabled Disabled boolean false
openOnFocus Open the suggestion panel on focus boolean true
ariaLabel Accessibility name (falls back to the locale message autocomplete.label when not passed) string —
sx sx shorthand layout props — —

# Events

Event Description Callback args
input v-model event (emitted on selection / input) (value: string)
change Emitted when the value changes (value: string)
select Emitted when a suggestion item is selected (value: string \| number, option: LhAutocompleteOption)

# Slots

Slot Description
empty Custom content when nothing matches (defaults to the locale message autocomplete.noMatch)

# Methods

Method Description
open() Open the suggestion panel
close() Close the panel

# Accessibility

  • The input has role="combobox" + aria-expanded / aria-controls / aria-activedescendant (APG combobox pattern, same structure as Select)
  • Options have role="option" + aria-selected; disabled options get aria-disabled="true"
Last Updated: 12/4/2026, 12:49:57 AM

Copyright © 2024-2026 FengMo WenXue