UI.MD

Field

A label, its control, a help line and an error line stacked as one form field, linked for screen readers with no ids to write.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/field.json

Usage

import { Field, FieldLabel, FieldDescription, FieldError } from "@/components/ui/field"

Examples

Default

Put the label, the control and an optional help line inside Field. It links them and spaces them on the label and help rungs, so the control needs no id.

Used for sign-in and billing receipts.

Invalid

Pass invalid and the control turns red and FieldError appears under it. Type a space to see it. Without invalid, the control's own checks (required, type="email") decide.

Shown on your public profile.

Use letters, numbers and dashes, with no spaces.

A form

Space one field from the next with Stack gap="field". Field works with Input, Textarea, Select and Slider; a checkbox or switch with its label beside it stays a Label in a row.

A sentence or two for your profile.

API Reference

PropTypeDefaultDescription
invalidFieldboolean-Marks the control invalid and shows FieldError. Leave it unset to let the control's own validation decide.
disabledFieldboolean-Disables the control and dims the field.
nameFieldstring-The control's form name, for a Base UI Form.
matchFieldErrorboolean | keyof ValidityState-Shows the error only for one failed check ("valueMissing"), or always with true.
invalidFieldbooleanMarks the control invalid and shows FieldError. Leave it unset to let the control's own validation decide.
disabledFieldbooleanDisables the control and dims the field.
nameFieldstringThe control's form name, for a Base UI Form.
matchFieldErrorboolean | keyof ValidityStateShows the error only for one failed check ("valueMissing"), or always with true.