Components

Autocomplete

An input that suggests values as you type while still accepting any text.

Source code

Click to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.

Installation

To use the autocomplete inside a Vee-Validate form, see VeeAutocomplete.

Autocomplete vs. Combobox

The autocomplete is built on Reka UI's Autocomplete primitive. It looks like UiCombobox but behaves differently:

AutocompleteCombobox
v-modelThe text in the input (string)The selected item(s)
Free-form textYes, any text is a valid valueNo, the value must be one of the items
Selecting an itemFills the input with the item's textSets the model to the item's value
On blurKeeps the typed textResets the input to the selection
multiple / object valuesNot supportedSupported

Use the autocomplete when suggestions are only a convenience (search boxes, emails, addresses, tags, job titles). Use a combobox when the user has to pick from a fixed list, or when you need objects or multiple selection.

Usage

Basic

The value of the autocomplete is the text in the input. Selecting a suggestion fills the input with that suggestion, but any other text is a perfectly valid value too. Suggestions are filtered as the user types.

Value: (empty)

Open on focus or click

By default the suggestions open once the user starts typing or presses the arrow keys. Use open-on-focus or open-on-click to open them as soon as the input is focused or clicked.

Clearable

Use UiAutocompleteCancel to render a button that clears the input.

Groups

Use UiAutocompleteGroup and UiAutocompleteLabel to organise the suggestions. Visible groups are divided by a line automatically, and groups that do not match the search are hidden along with their divider. Individual items can be disabled. UiAutocompleteSeparator is still available for manual dividers outside of groups.

Custom item content

Items accept any content, such as flags, avatars or descriptions.

Set hide-when-empty on UiAutocompleteContent to keep the popup hidden until at least one suggestion matches. This makes the autocomplete behave like a search box with suggestions.

Email suggestions

Suggestions do not have to come from a static list. Here they are derived from what the user typed. Because the suggestions already match the input, built-in filtering is turned off with ignore-filter.

Type a name followed by @ to see domain suggestions.

Async

Fetch suggestions from your API as the user types. Use ignore-filter so the results returned from the server are not filtered a second time on the client.

Form

Pass a name to include the typed text when the surrounding <form> is submitted.

Disabled

Set disabled on the root to prevent interaction.

Props

Autocomplete

PropTypeDefaultDescription
v-modelstring""The text in the input.
default-valuestringInitial text when uncontrolled.
v-model:openbooleanControls whether the suggestions are open.
default-openbooleanInitial open state when uncontrolled.
open-on-focusbooleanfalseOpen the suggestions when the input is focused.
open-on-clickbooleanfalseOpen the suggestions when the input is clicked.
ignore-filterbooleanfalseDisable the built-in filtering. Use it when you filter the items yourself, for example with data from an API.
reset-search-term-on-blurbooleanfalseReset the search term to the current value when the input loses focus.
highlight-on-hoverbooleantrueHighlight items on hover.
loopbooleanfalseWrap keyboard navigation from the last item to the first and vice versa.
namestringName used when the input is part of a native form.
requiredbooleanMarks the field as required.
disabledbooleanPrevents interaction.
dir"ltr" | "rtl"Reading direction.

The root emits update:modelValue, update:open and highlight.

AutocompleteContent

Accepts all of the Reka UI popper content props. The ones used most often are:

PropTypeDefaultDescription
hide-when-emptybooleanfalseHide the popup while no item matches.
side"top" | "right" | "bottom" | "left""bottom"Preferred side of the input.
side-offsetnumber8Distance in pixels from the input.
position"inline" | "popper""popper"Positioning strategy.

AutocompleteItem

PropTypeDescription
valuestringThe text that fills the input when the item is selected. Also used for filtering.
disabledbooleanPrevents the item from being selected.

Accessibility

The input has the combobox role with aria-autocomplete="list", and the suggestions are exposed as a listbox. Focus stays in the input while you move through the suggestions.

KeyDescription
ArrowDown / ArrowUpOpens the suggestions, then moves the highlight.
EnterFills the input with the highlighted suggestion.
EscCloses the suggestions and keeps focus in the input.
TabMoves focus away. The typed text is kept.