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
| Prop | Description | Type | Values | Default |
|---|---|---|---|---|
| options | Suggestion options | AutocompleteOption[] | — | [] |
| value | Input value (controlled) | string | — | — |
| defaultValue | Default input value (uncontrolled) | string | — | — |
| onValueChange | Input value change callback | (value: string) => void | — | — |
| onSelect | Suggestion selection callback | (option: AutocompleteOption) => void | — | — |
| filter | Filter customization (case / trim / custom matcher) | AutocompleteFilterOptions | — | 包含匹配,大小写不敏感 |
| trigger | Open trigger | 'input' | 'focus' | — | 'input' |
| clearable | Clear button | boolean | — | false |
| disabled | Disabled | boolean | — | false |
| size | Size | 'large' | 'middle' | 'small' | — | 跟随 ConfigProvider |
| placement | Dropdown placement | 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end' | — | 'bottom-start' |
| name | Native form name (hidden input) | string | — | — |
| placeholder / ariaLabel / prefixIcon / sx | Common props | — | — | — |
AutocompleteOption: { label: string; value?: string | number; disabled?: boolean } — value falls back to label.
AutoComplete Events
| Event | Description | Callback | Vue equivalent |
|---|---|---|---|
| onValueChange | Input value change | (value: string) => void | @input |
| onSelect | Suggestion 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'