Form
react-hook-form wiring for Nelumbo, with the same parts as shadcn's Form. Nelumbo's text fields keep one floating label, errors open with a spring and are announced, and a failed submit shakes what needs fixing.
Install
npx shadcn@latest add @nelumbo/form @nelumbo/labelSign-up form
Press Create account with nothing filled in: every problem shows at once, the invalid fields shake once and the first one takes focus. Fix a field and its message closes. Validation is a zod schema; the button shows its loading state while the (pretend) request runs.
One label, not two
Input, Textarea, Select, Combobox, Date Picker and Time Picker draw their own floating label. Inside a FormItem the FormLabel text feeds that label instead of being drawn a second time, so shadcn forms port over without doubled labels. A FormLabel next to Checkbox, Switch, Radio Group or Slider is a normal label.
<FormItem> <FormLabel>Email</FormLabel> {/* becomes the field's floating label */} <FormControl><Input type="email" {...field} /></FormControl> <FormDescription>We send the receipt here.</FormDescription> <FormMessage /></FormItem>{/* keep a separate label above a field: */}<FormItem field={false}>...</FormItem>{/* the control is a Nelumbo field inside your own component: */}<FormItem field>...</FormItem>Accessibility
FormControl gives the control its id, aria-invalid and an aria-describedby that lists the description and, while there is an error, the message. FormMessage is a polite live region, so a screen reader reads the error as it opens. A radio group is named through aria-labelledby and a slider through aria-label. Fields that expose a ref get focus from react-hook-form after a failed submit; the date and time pickers are focused by Nelumbo.
<input id="…-form-item" aria-invalid="true" aria-describedby="…-form-item-description …-form-item-message"><div id="…-form-item-message" aria-live="polite">Enter your email.</div>Label
The plain label for controls that have no floating label of their own. It follows its control: put it after a peer control and it dims when that control is disabled and turns red when it is invalid.
With a checkbox, switch and radio
Disabled and invalid, from the control
Usage
import { Form, FormField, FormItem, FormLabel, FormControl, FormDescription, FormMessage } from "@/components/ui/form"import { Label } from "@/components/ui/label"const form = useForm<z.infer<typeof schema>>({ resolver: zodResolver(schema) })<Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} noValidate> <FormField control={form.control} name="role" render={({ field }) => ( <FormItem> <FormLabel>Role</FormLabel> <Select value={field.value} onValueChange={field.onChange}> <FormControl><SelectTrigger ref={field.ref}><SelectValue /></SelectTrigger></FormControl> <SelectContent>...</SelectContent> </Select> <FormMessage /> </FormItem> )} /> <Button type="submit" loading={form.formState.isSubmitting}>Save</Button> </form></Form>Props
| Prop | Type | Default | Everything else matches shadcn's Form |
|---|---|---|---|
FormItem field | boolean | auto | true: treat the control as a Nelumbo field; false: keep a separate FormLabel |
FormLabel | Label props | Hidden when a Nelumbo field shows its text as the floating label | |
FormControl | Slot props | Adds id, aria-invalid, aria-describedby (and aria-labelledby or aria-label where needed) | |
FormMessage | div props | Error text or children. Always mounted, polite live region, spring open and close | |
FormDescription | p props | Help text, linked through aria-describedby | |
Label | Radix Label props | type-label-lg; follows peer disabled and aria-invalid, group data-disabled, data-error |