Skip to main content

AutoComplete

Input with a suggestion dropdown: type to filter candidates, select to fill the input.

Basic usage​

Basic usage
Selected:—
import { useState } from 'react'
import { LhAutoComplete } from '@lh-ui/react'

const options = [
{ label: 'Ink', value: 'ink' },
{ label: 'Fine-brush', value: 'fine-brush' },
]

export default function Demo() {
const [selected, setSelected] = useState('')
return (
<LhAutoComplete
options={options}
placeholder="Type a style"
onSelect={(option) => setSelected(option.label)}
/>
)
}

Trigger & clearable​

Trigger & clearable

AutoComplete Props​

PropDescriptionTypeValuesDefault
optionsSuggestion optionsAutocompleteOption[]—[]
valueInput value (controlled)string——
defaultValueDefault input value (uncontrolled)string——
onValueChangeInput value change callback(value: string) => void——
onSelectSuggestion selection callback(option: AutocompleteOption) => void——
filterFilter customization (case / trim / custom matcher)AutocompleteFilterOptions—包含匹配,大小写不敏感
triggerOpen trigger'input' | 'focus'—'input'
clearableClear buttonboolean—false
disabledDisabledboolean—false
sizeSize'large' | 'middle' | 'small'—跟随 ConfigProvider
placementDropdown placement'bottom-start' | 'bottom-end' | 'top-start' | 'top-end'—'bottom-start'
nameNative form name (hidden input)string——
placeholder / ariaLabel / prefixIcon / sxCommon props———

AutocompleteOption: { label: string; value?: string | number; disabled?: boolean } — value falls back to label.

AutoComplete Events​

EventDescriptionCallbackVue equivalent
onValueChangeInput value change(value: string) => void@input
onSelectSuggestion selected(option: AutocompleteOption) => void@select
Keyboard interaction

ArrowUp / ArrowDown move the highlight (skipping disabled options), Enter selects, Esc closes. The trigger follows the APG combobox pattern: role="combobox" + aria-expanded + aria-controls + aria-activedescendant.

Styles​

import '@lh-ui/react/style/autocomplete'