Docs
Form Control
Form Control
A versatile form field wrapper component that handles labels, validation messages, and layout.
We'll never share your email with anyone else.
Username is already taken
Password strength: Strong
Password is weak
Checking availability...
Installation
Usage
import { FormControl } from "@/components/ui/form-control";
import { Input } from "@/components/ui/input";
export function FormControlExample() {
return (
<FormControl
name="email"
label="Email"
caption="We'll never share your email with anyone else."
>
<Input
id="email"
placeholder="Enter your email"
type="email"
/>
</FormControl>
);
}Props
FormControl
| Prop | Type | Description |
|---|---|---|
name | string | Unique identifier for the form control. |
label | ReactNode | The label text for the form control. |
labelRight | ReactNode | Optional content to display at the right side of the label. |
error | ReactNode | Error message to display below the form control. |
success | ReactNode | Success message to display below the form control. |
warning | ReactNode | Warning message to display below the form control. |
loading | ReactNode | Loading message to display below the form control. |
caption | ReactNode | Helper text to display below the form control. |
controlLeft | ReactNode | Optional content to display on the left side below the form control. |
children | ReactNode | The form input component(s) to wrap. |
className | string | Additional classes to apply to the form control container. |
validationPosition | "left" | "right" | Position of validation messages. Defaults to "left". |
validationClassName | string | Additional classes to apply to validation messages. |
captionClassName | string | Additional classes to apply to the caption. |
labelClassName | string | Additional classes to apply to the label. |
Examples
With Error Message
<FormControl
name="username"
label="Username"
error="Username is already taken"
>
<Input
id="username"
placeholder="Enter a username"
/>
</FormControl>With Success Message
<FormControl
name="password"
label="Password"
success="Password strength: Strong"
>
<Input
id="password"
placeholder="Enter a password"
type="password"
/>
</FormControl>With Warning Message
<FormControl
name="password"
label="Password"
warning="Password is weak"
>
<Input
id="password"
placeholder="Enter a password"
type="password"
/>
</FormControl>With Loading State
<FormControl
name="username"
label="Username"
loading="Checking availability..."
>
<Input
id="username"
placeholder="Enter a username"
/>
</FormControl>With Right Aligned Validation
<FormControl
name="email"
label="Email"
error="Please enter a valid email address"
validationPosition="right"
>
<Input
id="email"
placeholder="Enter your email"
type="email"
/>
</FormControl>