Skip to content

ErrorText

Inline error message paragraph for a form control; announces itself via role="alert" the moment it renders.

  • stable
  • since v0.1.0
  • 0.4 kB
  • forms
  • feedback

Renders a <p> with role="alert" by default so newly mounted text is announced to assistive tech.

Preview
Open
tsx

Render ErrorText conditionally below a field and reference it via aria-describedby. Set invalid on the field so the visual treatment stays in sync.

Preview
Open
tsx

Inside a FormField, prefer FormMessage — it auto-wires aria-describedby and renders an ErrorText only when the field is invalid.

Preview
Open
tsx
PropTypeDefaultDescription
  • Defaults to role="alert" — assistive tech reads the message as soon as the element appears in the DOM.
  • Associate the error with its field by adding aria-describedby={errorId} on the input and a matching id on the ErrorText.
  • Keep messages short, specific, and actionable — “Email is required” beats “Invalid input”.
  • Avoid mounting an empty ErrorText; render the element only while there’s a message to announce.
  • Render conditionally — mounting it is what triggers the announcement.
  • Pair with HelperText to keep persistent guidance separate from transient validation.
  • When using FormField, switch to FormMessage for automatic wiring.