FormControl
FormControl, FormLabel, and FormMessage components for building accessible forms with validation states.
import { FormLabel, FormMessage } from "@ninna-ui/forms"pnpm add @ninna-ui/formsRequires @ninna-ui/core (auto-installed) + CSS setup.
Usage
FormControl provides context for form fields, managing required, invalid, and disabled states.
import { FormControl, FormLabel, FormMessage, Input } from "@ninna-ui/forms";
<FormControl isRequired> <FormLabel>Email</FormLabel> <Input type="email" placeholder="you@example.com" /> <FormMessage type="hint">We'll never share your email.</FormMessage></FormControl>
<FormControl isInvalid> <FormLabel>Password</FormLabel> <Input type="password" /> <FormMessage>Password must be at least 8 characters.</FormMessage></FormControl>Basic
FormControl with FormLabel and FormMessage for validation feedback.
We'll never share your email.
Password must be at least 8 characters.
With Different Sizes
FormControl works with inputs of any size.
Small size input
Medium size input
Large size input
API Reference
Complete list of props for FormControl, FormLabel, and FormMessage.
FormControl Props
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | Unique ID for the form field (auto-generated if not provided) |
isRequired | boolean | false | Whether the field is required |
isInvalid | boolean | false | Whether the field is in an invalid state |
isDisabled | boolean | false | Whether the field is disabled |
isReadOnly | boolean | false | Whether the field is read-only |
FormLabel Props
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Label text content |
className | string | - | Additional CSS classes |
FormMessage Props
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'error' | 'success' | 'warning' | 'hint' | 'error' | Message type determines styling |
children | ReactNode | - | Message content |
Accessibility
FormLabelis automatically associated with the input viahtmlForaria-requiredis set whenisRequiredis truearia-invalidis set whenisInvalidis truearia-disabledis set whenisDisabledis trueFormMessageis linked viaaria-describedby