Forms
Field
A labelled wrapper that lays out the label, control and a hint or error message, wiring aria-describedby and aria-invalid to the control for you.
Purpose
Field is the standard way to build a form row. It owns the label, the required marker and the
hint or error text, and wires the control for you: a single element child gets aria-describedby
pointing at the message, plus aria-invalid while error is set — so the message is announced
with the input rather than orphaned beside it. Composed controls (a wrapped input with an icon, a
Select) need the wiring by hand; the message ids are always {htmlFor}-hint / {htmlFor}-error.
Example
We will send claim updates to this address.
This policy number was not recognised.
Structure
| Property | Value |
|---|---|
| Layout | Vertical stack, 6px gap (space-y-1.5) |
| Label | 14px / Inter 600, --secondary-foreground |
| Required marker | Asterisk in --destructive, appended to the label |
| Hint | 12px --muted-foreground |
| Error | 12px / Inter 500, --destructive — replaces the hint |
Best practices
Do
- Always set
htmlForto the control'sid— the label pairing and the message ids both derive from it. - Let
Fielddo the wiring: a direct control child getsaria-describedbyandaria-invalidautomatically. - Wire composed controls by hand — a wrapped input or a Select needs
aria-describedby="{id}-hint"on the control itself. - Put format guidance in the hint; write errors as what to do next.
Don't
- Hand-roll a label and message around a control — the wiring is the point of
Field. - Expect a hint and an error together:
errorreplaces the hint by design. - Rely on the red border alone —
erroralways carries a written message.
Accessibility & keyboard
- The label is linked through
htmlFor, which names the control and makes clicking the label focus it. - A single element child is wired automatically:
aria-describedbypoints at the hint or error (ids{htmlFor}-hint/{htmlFor}-error), andaria-invalidis set whileerroris present — which also triggers the control's error styling. The child's own attributes always win. - Composed controls (a wrapper with an icon, a Radix Select) cannot be reached into — set
aria-describedbyandaria-invalidon the control yourself; the derived ids exist for exactly that. - The error state is conveyed by the written message, never by colour alone.
- Keyboard: none of its own —
Fieldis layout; Tab order belongs to the wrapped control.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | React.ReactNode | — | Label text rendered above the control. |
htmlFor | string | undefined | — | `id` of the wrapped control; links the label and derives the hint/error `id`s. |
required | boolean | undefined | false | Appends a required marker (a destructive-coloured asterisk) to the label. |
hint | React.ReactNode | — | Helper text shown under the control; hidden while `error` is present. |
error | React.ReactNode | — | Error message; when set, it replaces the hint and the field renders in its error state. |
className | string | undefined | — | Extra classes for the field wrapper. |
childrenrequired | React.ReactNode | — | The form control (and any adornments) the field wraps. A single element child is wired to the hint/error automatically (`aria-describedby`, plus `aria-invalid` while `error` is set); composed children — a wrapper with an icon, a Radix Select — need `aria-describedby` set on the control by hand. |