Skip to content

Autocomplete ​

A suggestion input that filters as you type: a text field (combobox) plus a dropdown suggestion list (listbox).

Basic usage ​

vue
<script setup>
import { ref } from 'vue'
const value = ref('')
const options = [
  { label: 'Ink wash' },
  { label: 'Blank space' },
  { label: 'Seal', value: 'seal' },
]
</script>

<template>
  <lh-autocomplete v-model="value" :options="options" />
</template>

When an option carries only a label, the submitted value is the label itself; add a value when a machine-readable identifier is needed. Disabled options stay in the list, grayed out and not selectable.

Filtering ​

By default, suggestions are filtered by whether the label contains the query string (case-insensitive, and leading/trailing whitespace does not participate in matching):

vue
<template>
  <lh-autocomplete v-model="value" :options="options" case-sensitive />
</template>

case-sensitive enables case-sensitive matching; pass trim as false to keep whitespace in the match.

Select callback ​

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

The select event receives the submitted value and the original option object.

Props ​

PropDescriptionTypeDefault
modelValueInput value (v-model)string''
optionsSuggestion optionsLhAutocompleteOption[][]
caseSensitiveCase-sensitive matchingbooleanfalse
trimTrim leading/trailing whitespace of the query string before matchingbooleantrue
placeholderPlaceholder hintstring—
placeholderStylePlaceholder style (replaces ::placeholder)string—
disabledDisable the componentbooleanfalse
openOnFocusOpen the suggestion panel on focusbooleantrue
ariaLabelAccessible namestring—
customClassCustom class namestring—
sxQuick layout propsLhSxProps—

Slots ​

SlotDescription
emptyEmpty state when nothing matches (default text comes from the autocomplete.noMatch locale message)

Events ​

EventDescriptionParameters
update:modelValueWrites back after input or selection(value: string)
changeInput value changed(value: string)
selectA suggestion item was selected(value: string | number, option: LhAutocompleteOption)

Methods (defineExpose) ​

MethodDescription
open / closeOpen / close the panel manually
isOpenCurrent open/closed state (read-only)

Platform differences ​

CapabilityH5Mini Program
Dropdown positioningroot-portal + two-frame measurement (same as select)Alipay uses root-portal or in-page fixed depending on the base library version; Douyin uses in-page fixed
Keyboard navigation / EscArrow keys move the highlight, Enter selects, Esc closesNo keyboard events; selection by click only
hover highlightYesNo (click selects directly)
openOnFocusOpens on focusOpens on focus