Autocomplete

A text input that suggests values while you type. Unlike Combobox, the user can keep any text, so use it for free fields like a city, a tag or a search term.

General

Pass the suggestions in data and name the field with aria-label, or with a visible label.

Controlled

onChange receives the text on every keystroke and when a suggestion is picked.

Suggestions with labels

Use { value, label, disabled } objects. The input receives the value; the list shows the label.

Variants

Use filled, light, ghost or subtle with a type, as in Combobox.

APIs

Autocomplete.Props

AttributeDescriptionTypeAccepted valuesDefault
datathe suggestionsArray<string / ComboboxOption>ComboboxOption-
valuetext of the input, to control itstring--
initialValuetext at the startstring-''
onChangecalled with the text(value: string) => void--
filterdecides which suggestions match the text(option, text) => boolean-contains, case insensitive
placeholdertext shown when the input is emptystring--
disableddisable the componentboolean-false
typecolor of the fieldNormalTypes'default', 'primary', 'secondary', 'success', 'warning', 'error', 'info'default
roundedround the cornersboolean-false
filledfilled variantboolean-false
lightlight variantboolean-false
ghostoutline variantboolean-false
subtlesubtle variantboolean-false
...native props, passed to the inputInputHTMLAttributes'aria-label', 'name', 'id', ...-

Ref

The ref points at the input.

Accessibility

The input has role="combobox" and points at the highlighted suggestion with aria-activedescendant. The list is a listbox of option elements.

KeyAction
Arrow Down and UpOpen the list, and move between the suggestions
EnterUse the highlighted suggestion. Without one, keeps the text
EscapeClose the list
TabClose the list and keep the text

A screen reader hears how many suggestions match while the user types. Give the input a name with aria-label or aria-labelledby.

Edit this page on GitHub