Text Field

Material Design 3 text field web components: lit-material-text-field (single-line) and lit-material-textarea (multi-line) — filled + outlined, validation states.

  • 7.8 KB gzipped
  • @lit-material/text-field 0.4.0
  • Renders on the server

Example

Install

npm install @lit-material/text-field @lit-material/tokens
import "@lit-material/text-field";

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

API

<lit-material-input-group>

Joins fields and buttons into one control: a protocol select in front of a URL, a field with a "Generate" button after it, a value and its unit. Inner corners are squared and the pieces sit edge to edge.

Slots

SlotDescription
defaultThe fields and buttons, in order.

<lit-material-number-field>

A number with − and + buttons beside it: replicas, cores, gigabytes. Typing works too; ArrowUp/ArrowDown step, PageUp/PageDown step by ten, Home/End jump to min/max when set.

Properties

PropertyAttributeTypeDefaultDescription
valuevaluenumber | nullnullThe number, or null when empty.
minminnumber | undefinednone
maxmaxnumber | undefinednone
stepstepnumber1Amount per step; typed values aren't snapped to it.
labellabelstring""
unitunitstring""Shown after the number inside the field, e.g. "GiB".
variantvariantTextFieldVariant"outlined"
supportingTextsupporting-textstring""
errorTexterror-textstring""An error of your own; the field's own range and number checks come first.
namenamestring""
requiredrequiredbooleanfalse
disableddisabledbooleanfalse
readonlyreadonlybooleanfalse
validationMessageproperty onlystring""The field's own problem with the text, "" when none.

Events

EventDescription
changeAfter a step, or when a typed value is committed.
inputWhile typing, once the text is a number (or empty).

CSS parts

PartDescription
fieldThe text field.
decrementThe − button.
incrementThe + button.

CSS custom properties

PropertyDescription
--lit-material-number-field-widthThe field's smallest width (default 8ch).

<lit-material-text-field>

Material Design 3 text field.

Properties

PropertyAttributeTypeDefaultDescription
variantvariantTextFieldVariant"filled"
typetypestring"text"
valuevaluestring""
labellabelstring""
placeholderplaceholderstring""
supportingTextsupporting-textstring""
errorTexterror-textstring""
errorerrorbooleanfalse
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadonlybooleanfalse
prefixprefixstring""
suffixsuffixstring""
minminnumber | undefinednone
maxmaxnumber | undefinednone
minlengthminlengthnumber | undefinednone
maxlengthmaxlengthnumber | undefinednone
stepstepstring""
patternpatternstring""
autocompleteautocompletestring""
inputmodeinputmodestring""
namenamestring""
formformstring | undefinednone

Events

EventDescription
changeBubbles on committed edits (blur/Enter).
inputBubbles when the value changes (like a native input).

Slots

SlotDescription
leading-iconAn optional icon before the input.
trailing-iconAn optional icon after the input.

CSS parts

PartDescription
containerThe outer field container (background/border).
inputThe native <input> element.
labelThe floating label element.
supportingThe supporting-text / character-counter row.

CSS custom properties

PropertyDescription
--lit-material-text-field-min-widthSmallest width (default 210px); 0 lets a grid or flex cell narrow it.
--lit-material-text-field-shapeCorner radius (default --md-sys-shape-corner-extra-small; filled rounds the top only).
--lit-material-text-field-shape-startStart-side corners; lit-material-input-group squares inner ones.
--lit-material-text-field-shape-endEnd-side corners.
--lit-material-text-field-notch-colorBehind the outlined variant's floating label; match the surface the field sits on (default --md-sys-color-surface; dialogs set it for you).

<lit-material-textarea>

Material Design 3 multi-line text field — lit-material-text-field's sibling for body-length text (a comment, a description, an address). Shares its floating-label/filled/outlined/error-state/character-counter design, minus the parts that don't make sense for multiple rows: no leading/trailing icon slots, no prefix/suffix, and a resting label that sits near the top (roughly where the first typed line would go) instead of vertically centering the way a single-line input's does — there's no sensible "middle" to center it in once the box is several rows tall.

Properties

PropertyAttributeTypeDefaultDescription
variantvariantTextareaVariant"filled"
valuevaluestring""
labellabelstring""
placeholderplaceholderstring""
supportingTextsupporting-textstring""
errorTexterror-textstring""
errorerrorbooleanfalse
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadonlybooleanfalse
minlengthminlengthnumber | undefinednone
maxlengthmaxlengthnumber | undefinednone
rowsrowsnumber4
resizeresizeTextareaResize"vertical"
autocompleteautocompletestring""
namenamestring""
formformstring | undefinednone

Events

EventDescription
changeBubbles on committed edits (blur).
inputBubbles when the value changes (like a native textarea).

CSS parts

PartDescription
containerThe outer field container (background/border).
textareaThe native <textarea> element.
labelThe floating label element.
supportingThe supporting-text / character-counter row.

CSS custom properties

PropertyDescription
--lit-material-text-field-min-widthSmallest width (default 210px); 0 lets a grid or flex cell narrow it.
--lit-material-text-field-notch-colorBehind the outlined variant's floating label; match the surface the field sits on (default --md-sys-color-surface; dialogs set it for you).

Source on GitHub npm