Autocomplete Autocomplete
LhAutocomplete autocomplete input: filtering suggestions, keyboard navigation and combobox a11y semantics.
Basic Usage
Basic Usage
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhAutocomplete } from '@lh-ui/vue3'
const value = ref('')
const options = [
{ label: 'Vue' },
{ label: 'Vue Router' },
{ label: 'Vite' },
{ label: 'Vitest' },
]
const t1 = {
placeholder: 'Type a framework',
}
</script>
<template>
<LhAutocomplete v-model="value" :options="options" :placeholder="t1.placeholder" />
</template>vue
<script>
import { LhAutocomplete } from '@lh-ui/vue3'
export default {
components: { LhAutocomplete },
data() {
return {
value: '',
options: [
{ label: 'Vue' },
{ label: 'Vue Router' },
{ label: 'Vite' },
{ label: 'Vitest' },
],
t1: {
placeholder: 'Type a framework',
},
}
},
}
</script>
<template>
<LhAutocomplete v-model="value" :options="options" :placeholder="t1.placeholder" />
</template>Options with Values
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhAutocomplete } from '@lh-ui/vue3'
const value2 = ref('')
const members = [
{ label: 'Alice', value: 'alice' },
{ label: 'Bob', value: 'bob' },
]
const t2 = {
placeholder2: 'Type a member',
}
</script>
<template>
<LhAutocomplete v-model="value2" :options="members" :placeholder="t2.placeholder2" />
</template>vue
<script>
import { LhAutocomplete } from '@lh-ui/vue3'
export default {
components: { LhAutocomplete },
data() {
return {
value2: '',
members: [
{ label: 'Alice', value: 'alice' },
{ label: 'Bob', value: 'bob' },
],
t2: {
placeholder2: 'Type a member',
},
}
},
}
</script>
<template>
<LhAutocomplete v-model="value2" :options="members" :placeholder="t2.placeholder2" />
</template>Autocomplete API
Props
| Name | Description | Type | Default |
|---|---|---|---|
| modelValue | Input value (v-model) | string | '' |
| options | Suggestion options | [LhAutocompleteOption](#type-LhAutocompleteOption)[] | () => [] |
| caseSensitive | Case-sensitive matching | boolean | false |
| trim | Trim the query before matching | boolean | true |
| placeholder | Placeholder | string | '' |
| disabled | Disabled | boolean | false |
| openOnFocus | Open the panel on focus | boolean | true |
| ariaLabel | Accessibility name | string | — |
| sx | Quick layout props | LhSxProps | — |
Events
| Name | Description | Type |
|---|---|---|
| update:modelValue | Fired when the value changes | (value: string) |
| change | Fired when the value changes | (value: string) |
| select | Fired when a suggestion is selected | (value: string | number, option: LhAutocompleteOption) |
Slots
| Name | Description |
|---|---|
| empty | Empty state when nothing matches |
Accessibility
- Follows the APG combobox pattern with
aria-expanded,aria-controlsandaria-activedescendantsynchronized to the highlighted option
Type Definitions
The TypeScript type structures exported by this component (auto-extracted from packages/components/autocomplete/src/types.ts and @lh-ui/share/core/* sources; click each entry to expand; see the Props table above for attribute descriptions):
LhAutocompleteProps
ts
export interface LhAutocompleteProps {
modelValue?: string
options?: LhAutocompleteOption[]
caseSensitive?: boolean
trim?: boolean
placeholder?: string
disabled?: boolean
openOnFocus?: boolean
ariaLabel?: string
sx?: LhSxProps
}
