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';

Purpose

An autocomplete is M3's exposed dropdown menu in its editable form: type in the field and the menu below it shows the matching options. Use it when typing finds an option faster than scrolling: countries, cities, categories, or options loaded from a server. For a short list, use a Select.

Matching ignores case and accents by default ("zurich" finds "Zürich"), anywhere in the option's text; filter replaces it. For server results, control items and inputValue and set loading while they load. allowCustomValue keeps text that matches no option. Options are AutocompleteItems (and AutocompleteSections), created in a client component.

Selection, items and forms

Each of these props has its row on the API tab; here is how they work together.

  • selectionMode: "single" (default) or "multiple". value / defaultValue / onChange take a key (or null), or an array of keys when multiple.
  • defaultItems (filtered for you) or items (filtered by you) with a render function as children, or AutocompleteItems written out; disabledKeys disables options.
  • onOpenChange reports when the menu opens and closes.
  • name and form for forms; validate and validationBehavior as in Text field; autoFocus, onFocus, onBlur.
  • inputValue / defaultInputValue / onInputChange for the typed text; placeholder.
  • allowCustomValue keeps text that matches no option; menuTrigger ("input" by default, "focus" or "manual") sets when the menu opens. Pressing the field opens every option, as M3 asks, unless it is "manual".

When not to use

For a short, known list use a Select; to search content rather than choose a value, use Search.

See also

  • Autocomplete on m3.material.io: Material's own guidelines, with anatomy and specs.
  • Select: An exposed dropdown menu: a field that opens a menu of options. One or several choices, sections, a search for long lists, a sheet on phones.
  • Search: A search bar that opens a full-screen view on phones and a docked view on larger windows, and an app bar with search.
  • Chips: Assist, suggestion, filter and input chips for compact actions and entries, in a chip set.
  • Text field: Filled or outlined text input with a floating label, icons, affixes, counter, error icon and a text area.