Autocomplete

Material Design 3 autocomplete web component (lit-material-autocomplete): a text field with a filtered option list.

  • 4.4 KB gzipped
  • @lit-material/autocomplete 0.0.3
  • Renders on the server

Example

Install

npm install @lit-material/autocomplete @lit-material/tokens
import "@lit-material/autocomplete";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-autocomplete>

Material Design 3-styled autocomplete — a text field that filters a data-driven options list as the user types, following the WAI-ARIA "Editable Combobox With List Autocomplete" pattern (https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-list/).

Properties

PropertyAttributeTypeDefaultDescription
optionsoptionsAutocompleteOption[][]
variantvariantAutocompleteVariant"filled"
labellabelstring""
valuevaluestring""
placeholderplaceholderstring""
namenamestring""
requiredrequiredbooleanfalse
disableddisabledbooleanfalse
errorerrorbooleanfalse
errorTexterror-textstring""
supportingTextsupporting-textstring""
openopenbooleanfalse
freeTextfree-textbooleanfalseWhen set, typed text with no matching option is committed as-is instead of being reverted.
formformstring | undefinednone

Events

EventDescription
changeFires when the committed value changes (option picked, or free text committed when free-text is set).

CSS parts

PartDescription
containerThe field container (background/border).
labelThe floating label element.
inputThe native <input> element.
popoverThe popover surface wrapping the listbox.
listboxThe listbox of filtered options.
optionA single option row.
supportingThe supporting-text row.

Source on GitHub npm