Skip to content

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

By name or description, across the 59 props below

Autocomplete 51 props

  • placeholdertype string

    Shown in the empty input. With a label, it appears once the label floats (on focus).

  • idtype string

    The <input>'s id, for a <label for> or an error summary's link.

  • varianttype "filled" | "outlined"default "filled"

    The container style, as TextField's: a filled surface or an outline.

  • allowCustomValuetype booleandefault false

    Free text: whatever is typed stays as the field's text when no option matches, instead of returning to the chosen option's.

  • densitytype 0 | -1 | -2 | -3default 0

    Web density, 0 to -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 nearest ThemeProvider or ThemeScope. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there, from a setting.

  • labeltype ReactNode

    The field's label. Give aria-label instead when there's no visible label.

  • supportingTexttype ReactNode

    Helper text below the field. Replaced visually by the error when invalid, and shown in the error colour while the field is invalid.

  • invalidtype boolean

    Marks the field invalid (in addition to validate and required).

  • requiredtype boolean

    A value is required: adds the * to the label and validates on submit.

  • disabledtype booleandefault false

    Disables the field: it can't be focused or edited.

  • readOnlytype booleandefault false

    The value can be read and copied but not changed; the menu doesn't open.

  • aria-invalidtype boolean | "true" | "false" | "grammar" | "spelling"

    Read as invalid when that's left out, for a form library that sets the attribute, so the field shows its error state as well as announcing it.

  • aria-requiredtype Booleanish

    Read as required when that's left out, for a form library that sets the attribute.

  • aria-readonlytype Booleanish

    Read as readOnly when that's left out, for a form library that sets the attribute.

  • leadingIcontype ReactNode

    Decorative icon at the start, in a 48px box.

  • errorIcontype ReactNode

    The icon shown before the arrow while the field is invalid (M3 strongly recommends one). Defaults to Material Symbols error, named by labels.error; false turns it off.

  • clearabletype booleandefault false

    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.

  • maxSelectionstype number

    With selectionMode="multiple", the most options that can be chosen; the rest show as disabled until one is removed.

  • loadingtype boolean

    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.

  • filtertype ((textValue: string, inputValue: string) => boolean)

    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.

  • reftype Ref<HTMLDivElement>

    Ref to the root <div> element. Use inputRef for the input itself.

  • inputReftype Ref<HTMLInputElement>

    Ref to the text <input>, e.g. for form libraries.

Text

  • aria-labeltype string

    Accessible name when there's no visible label.

  • labelstype Partial<AutocompleteLabels>

    Words the Autocomplete shows or announces, for other languages. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

AutocompleteItem 6 props

  • childrentype ReactNodeRequired

    The label.

  • textValuetype string

    Plain-text label for typeahead, filtering and the field, when children isn't a string.

  • leadingIcontype ReactNode

    Icon (or avatar, flag…) before the label.

  • descriptiontype ReactNode

    Second line of text.

  • trailingtype ReactNode

    Short text at the end, e.g. a dialling code or a count.

Text

  • aria-labeltype string

    Accessible name when the label isn't plain text.

AutocompleteSection 2 props

  • titletype ReactNode

    Heading shown above the options.

Text

  • aria-labeltype string

    Accessible name for the group when it has no title.

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.

  • 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.

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 kB
  • AutocompleteItem, AutocompleteSection: 22.0 kB

M3 Expressive specs

Shape
rounded-corner-extra-small
Variants
filled, outlined
Elevation
level2

Differences from Compose

  • Compose's ExposedDropdownMenuBox with a PrimaryEditable anchor 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.