Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Forms

Form field

Wraps one control with its label, hint text and error message.

Selector: mui-form-field

Import
import { FormField } from '@mushilu-san/ui/forms';
PreviewCode

Loading example…

Overview

Form field renders the label, the projected control, an optional hint and an optional error. The label is linked to the control with controlId, so give the control the same id.

The error message has role="alert", so it is announced as soon as it appears. Show it only after the user has interacted with the field.

When to use

  • Every standalone input, select or textarea that needs a label and a message.
  • Forms where the same label, hint and error layout should repeat.

When not to use

  • A control that already has a visible label from its parent, such as a checkbox inside a sentence.

Guidelines

Do

  • Write the error so it says how to fix the problem.
  • Use the hint for format rules, such as "8 characters or more".

Don't

  • Do not show an error before the user has typed anything.
  • Do not set error for a warning. Use a hint.

Accessibility

Roles and attributes

ElementRoleNotes
label—Linked to the control with for.
erroralertAnnounced when it appears.
  • Set required on the control, not only the marker, so the requirement is announced.
  • Connect the control to the hint and error with aria-describedby when the form field does not do it for you.

API

FormField

Selector: mui-form-field

NameTypeDefaultDescription
labelstring | undefined— Visible label text, linked to the control through `controlId`.
hintstring | undefined— Helper text shown under the control, for format rules or guidance.
errorstring | undefined— Error message shown under the control. Announced when it appears.
requiredbooleanfalse Shows the required marker on the label. Accepts attribute presence, e.g. <… required>.
disabledbooleanfalse Dims the label and hint to match a disabled control. Accepts attribute presence, e.g. <… disabled>.
controlIdstring'' Pass the id of the control inside so the label `for` wires correctly.

CSS parts

  • ::part(root)

Tokens

  • --mui-space-1
  • --mui-space-2
  • --mui-color-text-muted
  • --mui-color-danger