Field
Puts a label, a hint and any error around a control.
Example
Lowercase and dashes.
Install
npx shadcn@latest add https://design.how/r/quartz/field.json
import {Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle, Form, FormActions, FormStatus, Label, LabelHint, fieldBoxVariants, fieldControlVariants, labelClasses, useFieldDisabled} from '@/components/quartz/ui/field'Use when
- Any control the person fills: Input, Textarea, Combobox, Date picker, Select.
- A Switch or Checkbox that needs a sentence of explanation beside it.
- A set of fields that submit together, wrapped in Form.
Don't use when
- A search box in a toolbar names itself with aria-label. Use Input.
- A row of filters, not a form. Use Filter bar.
- A message about the whole page or account. Use Alert.
Minimal example
<Field name="name">
<FieldLabel>Agent name</FieldLabel>
<Input placeholder="support-agent"/>
<FieldDescription>Lowercase and dashes.</FieldDescription>
<FieldError/>
</Field>
Rules
Ordered by priority. MUST and NEVER break the system if skipped. SHOULD is style.
- field-error-timing MUST Leave validationMode unset so a field checks on blur, then on change while invalid. Because onChange flags the value as wrong on the first keystroke, before the person has finished typing it.
- Correct:
<Field validate={slug}> - Wrong:
<Field validationMode="onChange" validate={slug}>
- Correct:
- field-form-submit MUST Wrap fields that submit together in Form with a type="submit" Button, and pass pending to both. Because without Form, Enter in a field submits nothing and a second press sends the request twice.
- Correct:
<Form pending={saving} onFormSubmit={save}> <Field name="name">...</Field> <Button type="submit" pending={saving}>Save</Button> </Form> - Wrong:
<div><Field>...</Field><Button onClick={save}>Save</Button></div>
- Correct:
- field-server-errors MUST Pass server rejections to Form errors keyed by field name, not to a toast. Because a toast disappears and is tied to no control, while Form errors mark the field invalid under its own label.
- Correct:
<Form errors={{name: "An agent with this name already exists."}}> - Wrong:
toast.error("Name taken")
- Correct:
- field-label-bound MUST Name a control with FieldLabel inside a Field, or Label htmlFor outside one, never a styled p. Because a p is not a label, so the control has no accessible name and a click on the text does not focus it.
- Correct:
<Field><FieldLabel>Agent name</FieldLabel><Input/></Field> - Wrong:
<p className="type-label">Agent name</p><Input/>
- Correct:
- field-error-fix SHOULD Write an error as what to do, in a sentence with a period.
- Correct:
<FieldError>Use lowercase letters, digits and dashes.</FieldError> - Wrong:
<FieldError>Invalid name</FieldError>
- Correct:
- field-mark-optional SHOULD Mark the few optional fields with optional and mark nothing else.
- Correct:
<FieldLabel optional>Team</FieldLabel> - Wrong:
<FieldLabel>Name *</FieldLabel>
- Correct:
- field-error-component NEVER Style an error as raw red text; use FieldError. Because a loose p is not in the control's aria-describedby, so a screen reader never reads it, and red-600 is not the fail text step.
- Correct:
<FieldError>An agent with this name already exists.</FieldError> - Wrong:
<p className="text-red-600">Name taken</p>
- Correct:
- field-description-length SHOULD Keep a FieldDescription to one sentence under 120 characters.
- Correct:
<FieldDescription>Lowercase letters, digits and dashes.</FieldDescription>
- Correct:
API
| Prop | Type | Default | Note |
|---|---|---|---|
Field | name, invalid, validate, validationMode, disabled, orientation | validationMode defaults to blur, then change while invalid. | |
FieldLabel | optional | Bound by Base UI. | |
FieldError | errors, match, children | Children or errors always show. | |
FieldSet, FieldLegend | disabled; variant | FieldLegend variant: 'legend' | 'label'. | |
Form | pending, errors, onFormSubmit | Drops submits while pending. | |
FormStatus | status: 'ok' | 'fail' | A status region, always rendered. | |
Label, LabelHint | optional, htmlFor | For a control outside a Field. | |
| Other props pass through to the root element. |
Variants and states
- orientation: vertical, horizontal, responsive
- states: rest, optional, invalid, several-errors, disabled, form-pending, form-result
Accessibility
- FieldLabel is a native label bound to the control; a click on it focuses the control.
- FieldDescription and FieldError link by aria-describedby; the control gets aria-invalid.
- Tab leaves the control and validates it; Enter in a Form submits, and does nothing while pending.
- Form sets aria-busy while pending; FormStatus is a polite status region.
- The error is text, so it survives forced colors.
Edge cases
- Long label and error -> Both wrap; nothing has a fixed height.
- Right to left -> Label, hint and error align to the inline start; FieldSeparator centres logically.
- Inside a disabled FieldSet -> Every Field and the buttons in its controls take the disabled state.
- 120px wide -> Label, control and error stack; responsive stays vertical.
- No FieldLabel -> The control is unnamed; add the label or aria-label.
- Disabled and invalid -> Disabled wins; validation is skipped and the error hides.
- Server and client error -> FieldError dedupes and lists both.
- Enter three times while pending -> One request is sent; Form drops the rest.
- Failed submit -> Values stay and the first invalid field takes focus.
- Zoom 200% -> Label, hint and error wrap and grow.
Tokens
--type-label, --text-1, --text-disabled, --type-body-sm, --text-2, --fail-text, --line-control, --line-frame, --accent-wash, --line-focus, --border-focus
Related
- Input: One line of text. Variants: text, password, secret, copy, search, number and OTP, with prefix and suffix slots.
- Textarea: Several lines of text that grow.
- Combobox: A searchable choice, single, multiple or creatable.
- Checkbox: One option on or off, with a mixed state.
- Filter bar: Search plus filter chips and clear-all.