Autocomplete
A field you type into, with a menu of matching options. Accent-insensitive filtering, input chips for several choices, server results.
import { Autocomplete, AutocompleteItem, AutocompleteSection } from '@windmorph/react';Props
Autocomplete 51 props
Shown in the empty input. With a
label, it appears once the label floats (on focus).The
<input>'s id, for a<label for>or an error summary's link.The container style, as
TextField's: a filled surface or an outline.Free text: whatever is typed stays as the field's text when no option matches, instead of returning to the chosen option's.
Web density,
0to-3: each step takes 4px off the field (56px at 0, 44px at -3) and off its menu's options (44px at 0, 32px at -3). Left out, it takes the density of the nearestThemeProviderorThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.The field's label. Give
aria-labelinstead when there's no visible label.Helper text below the field. Replaced visually by the error when invalid, and shown in the error colour while the field is invalid.
Marks the field invalid (in addition to
validateandrequired).A value is required: adds the
*to the label and validates on submit.Disables the field: it can't be focused or edited.
The value can be read and copied but not changed; the menu doesn't open.
Read as
invalidwhen that's left out, for a form library that sets the attribute, so the field shows its error state as well as announcing it.Read as
requiredwhen that's left out, for a form library that sets the attribute.Read as
readOnlywhen that's left out, for a form library that sets the attribute.Decorative icon at the start, in a 48px box.
The icon shown before the arrow while the field is invalid (M3 strongly recommends one). Defaults to Material Symbols
error, named bylabels.error;falseturns it off.A clear button (M3's clear icon) that appears while there's typed text and empties it, and a single choice with it. It's skipped by Tab, since the text can be deleted from the keyboard.
With
selectionMode="multiple", the most options that can be chosen; the rest show as disabled until one is removed.Shows a loading indicator in the list, e.g. while options load for what was typed. The indicator's code loads when it first shows, and ahead of that when the field is hovered or focused while this prop is set at all, so pass
loading={false}(rather than leaving it out) on a field that loads options.Whether an option matches what was typed. Defaults to a match anywhere in its text, ignoring case and accents ("zurich" finds "Zürich"). Not used with controlled
items.Ref to the root
<div>element. UseinputReffor the input itself.Ref to the text
<input>, e.g. for form libraries.
Text
Accessible name when there's no visible label.
Words the Autocomplete shows or announces, for other languages. A
LabelsProvidersets them for the whole app.Shown when no option matches what was typed.
The loading indicator's name.
The arrow button's name.
A chip's remove button; the chip's text follows it ("Remove London").
With
clearable: the clear button's name.The error icon's name (M3: "Error").
Classes for the root element, merged with
classNames.root; consumer classes win.Classes for each part, by slot.
The text
<input>.With
selectionMode="multiple": each chosen option's input chip.With
clearable: the clear button.The root element, merged with
className.The filled or outlined container around the label, value and icons.
The floating label.
The row holding the field's value (the button, or the chips and input).
The leading icon's 48px box.
The trailing box holding the arrow (and the error icon).
The helper text below the field.
The error message below the field.
The built-in error icon.
The outlined field's border (a
<fieldset>, notched for the floated label).The filled field's active indicator, the line along the container's bottom.
The list's surface.
Each option.
Each option's leading icon, or the check shown on a chosen option.
Each option's
descriptionline.Each option's
trailingtext.Each section's heading.
The divider between sections.
The text shown when no option matches.
Inline styles for the root element.
The list of items (uncontrolled).
The list of items (controlled).
Method that is called when the open state of the menu changes. Returns the new open state and the action that caused the opening of the menu.
Whether single or multiple selection is enabled.
The value of the input (controlled).
The default value of the input (uncontrolled).
Handler that is called when the input value changes.
The contents of the collection.
The keys of the items that can't be selected or pressed. They stay focusable, so keyboard and screen reader users still find them.
The current value (controlled).
The default value (uncontrolled).
Handler that is called when the value changes.
Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.
A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if
validationBehavior="native". For realtime validation, use theinvalidprop instead.Whether the element should receive focus on render.
Handler that is called when the element receives focus.
Handler that is called when the element loses focus.
Handler that is called when the element's focus status changes.
Handler that is called when a key is pressed.
Handler that is called when a key is released.
An error message for the field.
The name of the input element, used when submitting an HTML form. See MDN.
The
<form>element to associate the input with. The value of this attribute must be the id of a<form>in the same document. See MDN.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
AutocompleteItem 6 props
The label.
Plain-text label for typeahead, filtering and the field, when
childrenisn't a string.Icon (or avatar, flag…) before the label.
Second line of text.
Short text at the end, e.g. a dialling code or a count.
Spec status
Built to the M3 Expressive autocomplete spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Vertical menu | Built | Variant · Basic |
| Color: standard | Built | Configuration · Basic |
| Layout: grouped | Built | Configuration · Sections |
| Filled and outlined fields | Built | Configuration · Basic, Multiple |
| Type to filter the options | Built | Use case · Basic, Sections |
| Options loaded for what was typed | Built | Use case · Async |
| Density | Extension | M3 gives text fields and menus web density; density (0 to -3, or the theme's) takes 4px a step off the field, its first row of chips and its options. |
| Built-in filtering | Extension | Matches anywhere, ignoring case and accents ("zurich" finds "Zürich"); filter replaces it. |
| Multiple selection as input chips | Extension | selectionMode="multiple" shows the choices as InputChips in the field, with maxSelections. |
allowCustomValue and loading | Extension | Keeps text that matches no option, and shows a loading indicator in the list. |
| Color: vibrant | Not built | The options list always uses the standard menu colours; the vibrant style is on Menu (variant="vibrant") for action menus. |
Vertical menu
BuiltVariant · Basic
Color: standard
BuiltConfiguration · Basic
Layout: grouped
BuiltConfiguration · Sections
Options loaded for what was typed
BuiltUse case · Async
Density
ExtensionM3 gives text fields and menus web density;
density(0 to -3, or the theme's) takes 4px a step off the field, its first row of chips and its options.Built-in filtering
ExtensionMatches anywhere, ignoring case and accents ("zurich" finds "Zürich");
filterreplaces it.Multiple selection as input chips
ExtensionselectionMode="multiple"shows the choices asInputChips in the field, withmaxSelections.
ExtensionallowCustomValueandloadingKeeps text that matches no option, and shows a loading indicator in the list.
Color: vibrant
Not builtThe options list always uses the standard menu colours; the vibrant style is on
Menu(variant="vibrant") for action menus.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
Autocomplete: 45.0 kBAutocompleteItem,AutocompleteSection: 22.0 kB
M3 Expressive specs
- Shape
rounded-corner-extra-small- Variants
filled, outlined- Elevation
level2
Differences from Compose
- Compose's
ExposedDropdownMenuBoxwith aPrimaryEditableanchor leaves filtering to the app; here it's built in, accent-insensitive, and replaceable. - The menu always opens under the field (above it when there's no room), never in a sheet, so the text being typed stays visible.
- Multiple selection as M3 input chips, with
maxSelections, which Compose's exposed dropdown doesn't have.