WlAutocomplete
Selection
Full example
<script setup lang="ts">
import { WlAutocomplete, WlButton } from "legato-ui";
import { onBeforeUnmount, ref } from "vue";
const value = ref<string | null>("Anna");
const suggestions = ref(["Anna", "Andrey", "Maria"]);
const loading = ref(false);
let timer: ReturnType<typeof setTimeout> | undefined;
function cancel(): void {
clearTimeout(timer);
loading.value = false;
}
function complete(event: { query: string }): void {
cancel();
loading.value = true;
// Simulate application-owned work; typing again replaces this local request.
timer = setTimeout(() => {
suggestions.value = ["Anna", "Andrey", "Maria"]
.filter((name) => name.toLowerCase().includes(event.query.toLowerCase()));
loading.value = false;
}, 600);
}
onBeforeUnmount(cancel);
</script>
<template>
<div class="wl-stack" data-space="md">
<WlAutocomplete
v-model="value"
:suggestions="suggestions"
:loading="loading"
:debounce="250"
clearable
dropdown
aria-label="Member"
@complete="complete"
/>
<WlButton v-if="loading" variant="ghost" @click="cancel">{{ "Cancel" }}</WlButton>
</div>
</template>States
Full example
<script setup lang="ts">
import { WlAutocomplete, WlButton } from "legato-ui";
import { onBeforeUnmount, ref } from "vue";
const value = ref<string | null>("Anna");
const suggestions = ref(["Anna", "Andrey", "Maria"]);
const loading = ref(false);
let timer: ReturnType<typeof setTimeout> | undefined;
function cancel(): void {
clearTimeout(timer);
loading.value = false;
}
function complete(event: { query: string }): void {
cancel();
loading.value = true;
// Simulate application-owned work; typing again replaces this local request.
timer = setTimeout(() => {
suggestions.value = ["Anna", "Andrey", "Maria"]
.filter((name) => name.toLowerCase().includes(event.query.toLowerCase()));
loading.value = false;
}, 600);
}
onBeforeUnmount(cancel);
</script>
<template>
<div class="wl-stack" data-space="md">
<WlAutocomplete
v-model="value"
:suggestions="suggestions"
:loading="loading"
:debounce="250"
clearable
dropdown
aria-label="Member"
@complete="complete"
/>
<WlButton v-if="loading" variant="ghost" @click="cancel">{{ "Cancel" }}</WlButton>
</div>
</template>Search and multiple participants
Object suggestions through complete, a prefilled dropdown, multiple, sizes and states.
Find an owner and select members
The button opens the current suggestions; the initial list is prefilled. Selecting a suggestion returns an object; typing in single mode returns a string. The label function supports both.
Sizes, compact density and states
Owner: Anna. Members: Anna.
5,000 options
Set virtual to window a large option list. Options and group headings use the same fixed height, and keyboard navigation continues through the full filtered list.
Full example
<script setup lang="ts">
import { WlAutocomplete, WlButton, WlField } from "legato-ui";
import { computed, ref } from "vue";
const people = [{ id: "anna", label: "Anna" }, { id: "boris", label: "Boris" }, { id: "dmitry", label: "Dmitry" }, { id: "elena", label: "Elena" }];
type Person = (typeof people)[number];
const person = ref<Person | string | null>(people[0]!);
const participants = ref<Person[] | null>([people[0]!]);
const singleSuggestions = ref([...people]);
const multipleSuggestions = ref([...people]);
function filter(query: string) {
return people.filter((item) => item.label.toLocaleLowerCase().includes(query.toLocaleLowerCase()));
}
function searchSingle(event: { query: string }) {
singleSuggestions.value = filter(event.query);
}
function searchMultiple(event: { query: string }) {
multipleSuggestions.value = filter(event.query);
}
function label(value: unknown): string {
return typeof value === "object" && value !== null && "label" in value ? String(value.label) : String(value ?? "");
}
const selectedNames = computed(() => Array.isArray(participants.value) ? participants.value.map(label).join(", ") : "");
function reset() {
person.value = "";
participants.value = [];
singleSuggestions.value = [...people];
multipleSuggestions.value = [...people];
}
const largeOptions = computed(() => Array.from({ length: 5000 }, (_, index) =>
["Record", index + 1].join(" ")
));
const virtualQuery = ref("");
const results = computed(() => largeOptions.value.filter((option) => option.toLocaleLowerCase().includes(virtualQuery.value.toLocaleLowerCase())));
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlAutocomplete">
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "Find an owner and select members" }}</h3>
<div class="wl-grid" data-space="lg">
<WlField
id="docs-auto-single"
v-slot="{ id, ariaDescribedby }"
label="Owner"
hint="Enter a name. The application updates suggestions on the complete event."
><WlAutocomplete
:id="id"
v-model="person"
:suggestions="singleSuggestions"
:option-label="label"
dropdown
dropdown-label="Show owners"
:aria-describedby="ariaDescribedby"
@complete="searchSingle"
/></WlField>
<WlField id="docs-auto-multiple" v-slot="{ id }" label="Members"><WlAutocomplete
:id="id"
v-model="participants"
:suggestions="multipleSuggestions"
:option-label="label"
multiple
dropdown
dropdown-label="Show members"
:min-length="0"
@complete="searchMultiple"
/></WlField>
</div>
<p class="wl-text-small wl-text-muted">{{ "The button opens the current suggestions; the initial list is prefilled. Selecting a suggestion returns an object; typing in single mode returns a string. The label function supports both." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "Sizes, compact density and states" }}</h3>
<div class="wl-grid" data-space="lg">
<WlField
v-for="size in ['sm', 'md', 'lg'] as const"
:id="`docs-auto-${size}`"
:key="size"
v-slot="{ id }"
:label="`${'Owner, '}${size}`"
><WlAutocomplete
:id="id"
v-model="person"
:size="size"
:suggestions="singleSuggestions"
:option-label="label"
@complete="searchSingle"
/></WlField>
<WlField id="docs-auto-compact" v-slot="{ id }" label="Compact suggestions"><WlAutocomplete
:id="id"
v-model="person"
density="compact"
:suggestions="singleSuggestions"
:option-label="label"
@complete="searchSingle"
/></WlField>
<WlField
id="docs-auto-invalid"
v-slot="{ id, ariaDescribedby, invalid }"
label="Suggestions with an error"
error="Confirm the owner before saving."
><WlAutocomplete
:id="id"
v-model="person"
:suggestions="singleSuggestions"
:option-label="label"
:invalid="invalid"
:aria-describedby="ariaDescribedby"
@complete="searchSingle"
/></WlField>
<WlField id="docs-auto-disabled" v-slot="{ id }" label="Unavailable suggestions"><WlAutocomplete
:id="id"
:model-value="people[0]"
:suggestions="people"
:option-label="label"
disabled
dropdown
/></WlField>
</div>
<WlButton size="sm" @click="reset">{{ "Clear selected values" }}</WlButton>
<p class="wl-text-small" role="status">{{ "Owner:" }} {{
label(person) || "not selected"
}}{{ ". Members:" }} {{ selectedNames || "none selected" }}.</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "5,000 options" }}</h3>
<WlAutocomplete
aria-label="5,000 options"
:suggestions="results"
virtual
dropdown
@complete="virtualQuery = $event.query"
/>
<p class="wl-text-small wl-text-muted">{{ "Set virtual to window a large option list. Options and group headings use the same fixed height, and keyboard navigation continues through the full filtered list." }}</p>
</section>
</div>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model: WlAutocompleteModel<For single selection, a suggestion or typed text. For multiple, an array of suggestions. No default value.
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
virtual | WlVirtualOptions | false | — |
suggestions | readonly TOption[] | [] | Readonly TOption list; determines the selected suggestion type. |
optionLabel | WlAutocompleteOptionLabel< | Not set | Label field name or (option) => string function. |
placeholder | string | Not set | Placeholder. |
invalid | boolean | false | Error state. |
disabled | boolean | false | Disables the field. |
size | WlSizeSm | "md" | Field size. |
density | WlDensity | "default" | Density. |
multiple | TMultiple & boolean | false | Multiple selection (chips). |
dropdown | boolean | false | List expansion button. |
dropdownLabel | string | Not set | Accessible list expansion button name; falls back to WlConfig.locale.showOptions (Show options in English). |
minLength | number | 1 | Minimum characters to start a search. |
motion | boolean | Inherits WlConfig.motion | Suggestion animation; defaults to WlConfig.motion (true). |
pt | WlPt< | Not set | Attributes of internal Legato UI elements. |
optionDisabled | WlOptionDisabled< | Not set | Option field or predicate identifying disabled options. |
optionKey | WlOptionKeyResolver< | Not set | Stable option field or key resolver; keeps rendered option state with its data. |
clearable | boolean | false | Show a named clear button; clears a single model to null. |
debounce | number | 300 | Delay in milliseconds before requesting completion for changed text. |
loading | boolean | false | Indicate pending work supplied by the application. |
Events
| Event | Payload | When emitted |
|---|---|---|
complete | [event: WlAutocompleteCompleteEvent] | Start search: { originalEvent, query } — update suggestions. |
update:modelValue | WlAutocompleteModel< | Emitted when the component requests a model change; the payload is the next value. |
Slots
| Slot | Type / values | Content |
|---|---|---|
option | option?(props: { option: TOption; index: number; selected: boolean; active: boolean }): unknown; | Option scope: { option, index, selected, active }. |
chip | chip?(props: { option: TOption; remove: () => void }): unknown; | Selected chip scope: { option, remove }. |
empty | empty?(props: Record< | Content shown when no options match. |
loading | loading?(props: Record< | Content displayed while consumer-provided work is pending. |
Pass-through: pt
Sections WlAutocomplete are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-autocomplete | The root section in WlConfig.pt.autocomplete configuration. |
inputMultiple | div.wl-autocomplete__multiple | The inputMultiple section in WlConfig.pt.autocomplete configuration. |
chipItem | span.wl-multiselect__chip | The chipItem section in WlConfig.pt.autocomplete configuration. |
chip.root | span.wl-multiselect__chip | Main element of the component. |
chip.label | span.wl-multiselect__chip-label | Visible component label. |
chip.removeIcon | button.wl-multiselect__chip-remove | Button that removes the associated value or file. |
input | input | The input section in WlConfig.pt.autocomplete configuration. |
inputChip | input | The inputChip section in WlConfig.pt.autocomplete configuration. |
inputText.root | input | Native input that receives focus and control attributes. |
clearButton | button.wl-autocomplete__clear | Button that clears the current value. |
dropdown | button.wl-autocomplete__dropdown | The dropdown section in WlConfig.pt.autocomplete configuration. |
dropdownIcon | span.wl-autocomplete__dropdown-icon | The dropdownIcon section in WlConfig.pt.autocomplete configuration. |
overlay | div.wl-overlay | The overlay section in WlConfig.pt.autocomplete configuration. |
listContainer | div.wl-select__list-container | The listContainer section in WlConfig.pt.autocomplete configuration. |
loadingMessage | div.wl-select__empty | Loading state inside the options list. |
option | div.wl-select__option | The option section in WlConfig.pt.autocomplete configuration. |
emptyMessage | div.wl-select__empty | The emptyMessage section in WlConfig.pt.autocomplete configuration. |
list | ul | The list section in WlConfig.pt.autocomplete configuration. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Set virtual to window a large option list. Options and group headings use the same fixed height, and keyboard navigation continues through the full filtered list.
- Label the text combobox through id/label or aria-label; give the dropdown button a distinct dropdownLabel.
- ArrowDown opens suggestions; arrows and Home/End move the active item; Enter selects; Escape closes.
- complete emits query after a delay; the application updates suggestions. Dropdown opens the current list, so provide initial options.
- In single mode, typing returns a string and selecting returns the suggestion value. For objects and typed text, use an optionLabel function that handles both types. In multiple mode, the model is an array and chip removal buttons are available; add an error description to invalid.
Keyboard and application responsibilities
| Key | Action |
|---|---|
| ↑ / ↓ | Open the list and move the active option, skipping disabled options. |
| Home / End, PageUp / PageDown | Move to an edge or a page of available options while the list is active. |
| Enter | Choose the active option once. |
| Escape | Close the list and keep focus at its trigger or input. |
| Text | Type to search or use typeahead where the control is not editable. |
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.