Field
The layout of a form: a label, a control, a description and an error, stacked or in a row, grouped into fieldsets. Drop-in for shadcn's Field. Nelumbo text fields keep their floating label, and checkbox, radio and switch rows can become selectable cards.
Install
npx shadcn@latest add @nelumbo/fieldPayment form
FieldSet and FieldLegend name a group, FieldGroup spaces the fields. A FieldLabel beside a Nelumbo Input or Select becomes its floating label, so nothing is drawn twice, while the id, aria-invalid and aria-describedby are wired for you.
Choice cards
A FieldLabel that wraps a Field is a card. The whole card is the target for its radio, checkbox or switch; selecting it fills it with the secondary color and its corners spring from round to squarer.
Horizontal
orientation="horizontal" puts the control beside its text, for settings rows. A FieldContent holds the title and description; a switch centers on the row, a checkbox lines up with the first line.
Responsive
orientation="responsive" stacks until its FieldGroup is 28rem wide (a container query, not the window), then sits in a row. Drag the right edge of the frame to try it.
Shown on your public profile.
A line or two.
Errors
Put data-invalid on the Field: the label, the control and a choice card turn red and the Nelumbo field gets aria-invalid. FieldError is always mounted, so screen readers hear it, and it opens with a spring. Give it an errors array (react-hook-form, Zod; duplicates are merged) or children.
We send the receipt here.
- At least 8 characters.
- Add a number.
Separator
FieldSeparator is spacing, not a line. With text, the text sits centered in the gap.
Usage
import { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, FieldTitle } from "@/components/ui/field"<FieldSet> <FieldLegend>Account</FieldLegend> <FieldGroup> <Field data-invalid={!!errors.email}> <FieldLabel htmlFor="email">Email</FieldLabel> {/* becomes the Input's floating label */} <Input id="email" type="email" /> <FieldDescription>We send the receipt here.</FieldDescription> <FieldError errors={[errors.email]} /> </Field> {/* a choice card */} <FieldLabel htmlFor="news"> <Field orientation="horizontal"> <FieldContent> <FieldTitle>Newsletter</FieldTitle> <FieldDescription>One email a month.</FieldDescription> </FieldContent> <Checkbox id="news" /> </Field> </FieldLabel> </FieldGroup></FieldSet>Props
| Prop | Type | Default | Notes |
|---|---|---|---|
Field orientation | "vertical" | "horizontal" | "responsive" | "vertical" | Responsive switches at 28rem of the enclosing FieldGroup. |
Field data-invalid | boolean | false | Red label, aria-invalid on a Nelumbo field, error state on cards. |
Field data-disabled | boolean | false | Dims the label and description. |
Field floating | boolean | true | false keeps a separate FieldLabel beside a Nelumbo text field. |
FieldLabel | Label props | Wrapping a Field makes it a choice card. Beside a Nelumbo text field with a string child, it becomes that field's label. | |
FieldError errors | Array<{ message?: string }> | Deduplicated; several messages become a list. Or pass children. | |
FieldLegend variant | "legend" | "label" | "legend" | Legend is a title, label is a small label. |
FieldSeparator | div props | Spacing; children are centered text. No line. | |
FieldGroup / FieldSet / FieldContent / FieldTitle / FieldDescription | Layout parts; same as shadcn. |