Field
The standard form unit. A label above the control, optional help text or an error below, with the spacing built in.
Usage
pnpm dlx shadcn@latest add fieldThen replace components/ui/field.tsx, label.tsx and separator.tsx with the Matrix versions. They keep shadcn's parts and add the Matrix type, colors and spacing.
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field';
import { Input } from '@/components/ui/input';
<Field>
<FieldLabel htmlFor="email">Email</FieldLabel>
<Input id="email" type="email" placeholder="name@example.com" />
<FieldDescription>We'll send the invite here.</FieldDescription>
</Field>The spacing is part of the component: the label sits 2px above its control, help text and errors 8px below it, 16px between fields and 24px between sections. Validation timing and error copy follow the Input behavior.
Field
We'll send the invite here.
Group
Grid
Use a grid only for short, related pairs (first and last name, city and postcode). It stacks on narrow screens.
Required
required on the label adds the asterisk; set required on the control too, so browsers and screen readers know. The asterisk is neutral, not coral: coral means an error.
Error
Set aria-invalid on the control (coral border) and put the message in FieldError, linked with aria-describedby. The label stays neutral. FieldError also accepts an errors array from form libraries and shows each message once.
Disabled
Only owners can rename the workspace.
Disable the control and the field softens its own label and help text. Use the help text to say why it's disabled.
Inline
The default sizes already line up (Input md and Button md are both 36px), with 8px between them.
Complete form
API reference
Field is a set of small parts. Put a real control (Input, Input group, Textarea) inside; Field adds the label, help text, error and spacing.
Prop
Type
Guidelines
- Link every label to its control with
htmlForandid. - Pair
FieldErrorwitharia-invalidon the control; never show an error with color alone. - Use help text for what people need before they type (format, why it's needed), and the error for what went wrong.
- Mark required fields only when most fields are optional; if most are required, mark the optional ones instead.
- Just disable the control; the field softens its own label and help text.
- Don't add your own margins between fields; FieldGroup and FieldSet already space them.