Chip

Material Design 3 chip web component (assist, filter, input, suggestion variants).

  • 4.1 KB gzipped
  • @lit-material/chip 0.2.0
  • Renders on the server

Example

Install

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

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

API

<lit-material-chip-input>

A field that turns what you type into chips: tags, labels, email addresses, allowed hosts. Enter or a comma adds the typed value; pasting several values separated by commas, spaces or new lines adds them all. Each chip has a remove button, and Backspace in the empty field removes the last one.

Properties

PropertyAttributeTypeDefaultDescription
valuesvaluesstring[][]The chips' values.
labellabelstring""Visible label above the field; also names the input.
placeholderplaceholderstring""
supportingTextsupporting-textstring""Help under the field, replaced by an error while there is one.
validatorproperty only(value: string) => string | undefinednoneRefuses a value: return a message, or "" to accept.
allowDuplicatesallow-duplicatesbooleanfalse
maxmaxnumber0Most chips allowed; 0 for no limit.
disableddisabledbooleanfalse
invalidinvalidbooleanfalseSet while the typed value was refused; reflected.

Events

EventDescription
changeAfter a value is added or removed; detail: { values }.

CSS parts

PartDescription
fieldThe box holding the chips and the input.
inputThe text input.

<lit-material-chip>

Material Design 3 chip.

Properties

PropertyAttributeTypeDefaultDescription
variantvariantChipVariant"assist"
selectedselectedbooleanfalse
disableddisabledbooleanfalse
elevatedelevatedbooleanfalse
removableremovablebooleanfalse
removeLabelremove-labelstring"Remove"Accessible name of the remove button, e.g. "Remove app=web".
hrefhrefstring""If set, renders the main action as a link (<a>) instead of a <button>.
targettargetstring""

Events

EventDescription
changeBubbles when a filter chip's selected state toggles via user interaction.
removeCancelable; fires when the remove button is activated. Unless event.preventDefault() is called, the chip removes itself from the DOM afterward.

Slots

SlotDescription
defaultThe chip's label.
leading-iconAn optional icon before the label. Ignored on a selected filter chip, which shows a checkmark in its place.

CSS parts

PartDescription
chipThe outer container (background/border/elevation).
actionThe main clickable <button> or <a> (icon + label).
remove-buttonThe trailing remove <button>, when removable.
rippleThe state-layer element the hover/press feedback is drawn on.

Source on GitHub npm