Skip to main content

Text field

One line of text with a label, help and error.

<mm-text-field name="owner" type="email" label="Owner email" required
help="We send freshness alerts here."></mm-text-field>
<mm-text-field name="mrn" label="Asset MRN" mono value="mrn://postgresql/table/shop.public.orders"></mm-text-field>

Guidance​

Text fields take one line of text: a label above, the field, then help or error text. Use mono for machine strings such as MRNs, asset IDs and connection strings, and never for prose. Passwords get a show and hide toggle, maxlength adds a character counter, and clearable adds a clear button once there is a value.

Form-associated: submits value under name with a native form or a SvelteKit form action, takes part in constraint validation (required, pattern, minlength, maxlength, and the email and URL types), resets with the form and is disabled by a disabled fieldset. Enter submits the owning form, as a native input does.

Properties​

PropertyAttributeTypeDefaultDescription
typetype'text' | 'email' | 'url' | 'password' | 'tel''text'text (default), email, url, password or tel.
valuevaluestring''The current value. The value attribute is the default the form resets to.
placeholderplaceholderstring''
patternpatternstring''A regular expression the whole value must match.
minlengthminlengthnumber | undefined
maxlengthmaxlengthnumber | undefinedMaximum length; also shows a counter.
autocompleteautocompletestring | undefined
inputmodeinputmodestring | undefined
readonlyreadonlybooleanfalse
monomonobooleanfalseSets the value in mono, for machine strings (IDs, MRNs, keys).
clearableclearablebooleanfalseShows a clear button when there is a value.
labellabelstring''Field label. Rendered above the control unless hide-label, and always the accessible name.
helphelpstring''Help text under the control.
errorerrorstring''Error text: a sentence saying what to fix. Shows the crimson border, an icon and sets aria-invalid.
hideLabelhide-labelbooleanfalseHides the label visually; it stays the accessible name.
optionaloptionalbooleanfalseMarks the field as optional, in words.
namenamestring''Name submitted with the form.
disableddisabledbooleanfalseDisables the control and excludes it from submission.
requiredrequiredbooleanfalseRequires a value before the form submits.
formHTMLFormElement | null
validityValidityState
validationMessagestring
willValidateboolean
isDisabledbooleanTrue when disabled directly or by a disabled ancestor fieldset.

Methods​

MethodDescription
select()Selects all text in the field.
formResetCallback()Restore the initial value when the owning form resets.

Events​

EventDetailDescription
mm-inputCustomEvent<MmValueDetail>On every edit.
mm-changeCustomEvent<MmValueDetail>When the value is committed (blur after editing, or clearing).
inputInputEventNative, composed; on every edit.
changeEventNative, re-dispatched on the host when the value is committed.

Slots​

SlotDescription
prefixContent before the input, such as an icon or a fixed scheme like mrn://.
suffixContent after the input, such as a unit or a domain.

CSS parts​

PartDescription
labelThe label.
controlThe bordered input box.
inputThe native input.
helpThe help line.
errorThe error line.
counterThe character counter.

Examples​

Every state of mm-text-field in Storybook, with keyboard and screen reader tests.