FormGroup
FormGroup groups related form fields inside a semantic fieldset with an optional legend, description, spacing, and direction.
import { FormGroup } from "@ninna-ui/forms"pnpm add @ninna-ui/formsRequires @ninna-ui/core (auto-installed) + CSS setup.
Usage
Import and use FormGroup to semantically group related form fields inside a fieldset.
import { FormGroup, Field, Input } from "@ninna-ui/forms";
<FormGroup legend="Personal Information"> <Field label="First Name"> <Input placeholder="John" /> </Field> <Field label="Last Name"> <Input placeholder="Doe" /> </Field></FormGroup>
<FormGroup legend="Contact Details" description="Please provide your contact information." required> <Field label="Email" required> <Input type="email" placeholder="john@example.com" /> </Field></FormGroup>Basic
FormGroup with a legend and optional description.
Direction
Lay out fields vertically (default) or horizontally.
Spacing
Control the gap between fields with sm, md, or lg spacing.
States
Required and disabled states propagate to all child fields.
With Checkboxes & Radio
FormGroup works with any form control — checkboxes, radio groups, and more.
API Reference
Complete list of props for the FormGroup component.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
legend | string | - | Legend/title rendered inside the fieldset legend element |
description | string | - | Optional description text below the legend; linked via aria-describedby |
disabled | boolean | false | Disables all form controls inside the fieldset |
required | boolean | false | Marks the group as required (shows * indicator in legend) |
spacing | 'sm' | 'md' | 'lg' | 'md' | Gap between child fields |
direction | 'vertical' | 'horizontal' | 'vertical' | Layout direction of child fields |
id | string | - | ID for the fieldset element (auto-generated if not provided) |
className | string | - | Additional CSS classes |
children | ReactNode | - | Form fields to group together |
Accessibility
- Renders a native
fieldsetelement for semantic grouping of related controls - The
legendprop renders a<legend>element — the primary accessible label for the group - The
descriptionprop is linked viaaria-describedbyfor additional context - Setting
disabledon the fieldset disables all child controls natively — no JavaScript needed - Setting
requiredshows a visual indicator; pair withrequiredon individualFieldcomponents for full a11y - All HTML attributes are forwarded via
...propsspread —aria-label,role, etc. are fully overridable