Skip to main content

Form field

Label, help and error layout for a slotted control.

<mm-form-field label="Owning team" help="The team paged when this asset fails a freshness check.">
<my-team-picker name="team"></my-team-picker>
</mm-form-field>

Guidance​

A layout wrapper that gives any slotted control the Marmot field furniture: a label above, then the control, then an error line and help text. Use it when composing a custom control; the built-in controls (mm-text-field, mm-select and so on) render their own.

The label and messages live in the shadow root, so the field names the slotted control with aria-label and describes it with aria-description, and sets aria-invalid and aria-required. Elements slotted into label, help and error stay in the light DOM and are wired with aria-labelledby and aria-describedby instead. Attributes the author set are never overwritten. Clicking the label focuses the control.

Properties​

PropertyAttributeTypeDefaultDescription
labellabelstring''Field label; the accessible name of the slotted control.
helphelpstring''Help text under the control.
errorerrorstring''Error text: a sentence saying what to fix.
requiredrequiredbooleanfalseShows "Required" beside the label and sets aria-required on the control.
optionaloptionalbooleanfalseShows "Optional" beside the label.
hideLabelhide-labelbooleanfalseHides the label visually; it stays the accessible name.
controlHTMLElement | nullThe slotted control that receives the label and description.

Slots​

SlotDescription
DefaultThe control.
labelA rich label, in place of the label attribute.
helpRich help text, in place of the help attribute.
errorRich error text, in place of the error attribute.

CSS parts​

PartDescription
labelThe label.
controlThe wrapper around the slotted control.
helpThe help line.
errorThe error line.

Examples​

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