- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Menubar
- Message
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Toolbar
- Tooltip
- Artifact
- Audio Player
- Canvas
- Chain of Thought
- Checkpoint
- Code Block
- Commit
- Connection
- Context
- Controls
- Edge
- Environment Variables
- Mic Selector
- Model Selector
- Node
- Node Toolbar
- Open in Chat
- Panel
- Plan
- Prompt Input
- Queue
- Reasoning
- Sandbox
- Schema Display
- Shimmer
- Snippet
- Sources
- Speech Input
- Stack Trace
- Suggestion
- Tool
- Transcription
- Web Preview
Field
A component that provides labelling and validation for form controls.
Visible on your profile
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<Field>
<FieldLabel>Name</FieldLabel>
<Input placeholder="Enter your name" type="text" />
<FieldDescription>Visible on your profile</FieldDescription>
</Field>
);
}
Installation
pnpm dlx shadcn@latest add @frontal-labs/field
Usage
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";<Field>
<FieldLabel>Name</FieldLabel>
<Input type="text" placeholder="Enter your name" />
<FieldDescription>Visible on your profile</FieldDescription>
<FieldError>Please enter a valid name</FieldError>
</Field>API Reference
Field
Root component. A styled div with role="group" that lays out a label, control, description, and error.
Accepts all div props, plus:
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "vertical" | "horizontal" | "responsive" | "vertical" | Layout direction of the field. |
"responsive" stacks vertically and switches to a horizontal layout at the @md breakpoint of the enclosing FieldGroup.
FieldSet
A styled fieldset element for grouping related fields.
FieldLegend
A styled legend element for a FieldSet. Accepts a variant prop of "legend" (default) or "label" to control the text size.
FieldGroup
A styled div that stacks multiple fields or field sets. It also acts as the container query context used by the responsive orientation.
FieldContent
A styled div that groups a field's title and description, typically next to a control in a horizontal field.
FieldLabel
Label for the field. A styled wrapper around the Label component.
FieldTitle
A styled div for label-like text that is not an actual label element, for example inside a FieldContent.
FieldDescription
Description text for the field. Renders a p element with muted foreground color.
FieldSeparator
A styled div that renders a Separator between fields, optionally with centered content passed as children.
FieldError
Error message for the field. Renders a div with role="alert" and destructive text color, and renders nothing when there is no content.
Accepts all div props, plus:
| Prop | Type | Default | Description |
|---|---|---|---|
errors | { message?: string }[] | - | Errors rendered when no children are provided. Deduplicated by message; multiple errors render as a list. |
Examples
Required Field
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<Field>
<FieldLabel>
Password <span className="text-destructive-foreground">*</span>
</FieldLabel>
<Input placeholder="Enter password" required type="password" />
<FieldError>Please fill out this field.</FieldError>
</Field>
);
}
Disabled Field
This field is currently disabled.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<Field>
<FieldLabel>Email</FieldLabel>
<Input disabled placeholder="Enter your email" type="email" />
<FieldDescription>This field is currently disabled.</FieldDescription>
</Field>
);
}
With Error
Enter an invalid email address and press enter to see the error.
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export default function FieldWithErrorDemo() {
return (
<Field>
<FieldLabel>Email</FieldLabel>
<Input placeholder="Enter your email" type="email" />
<FieldError>Please enter a valid email address.</FieldError>
</Field>
);
}
Input Group
import { ArrowRightIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
export default function Particle() {
return (
<Field>
<FieldLabel>Subscribe</FieldLabel>
<InputGroup>
<InputGroupInput placeholder="Your best email" type="email" />
<InputGroupAddon align="inline-end">
<Button aria-label="Subscribe" size="icon-xs" variant="ghost">
<ArrowRightIcon aria-hidden="true" />
</Button>
</InputGroupAddon>
</InputGroup>
<FieldError>Please enter a valid email address.</FieldError>
</Field>
);
}
Autocomplete Field
Select a item.
"use client";
import {
Autocomplete,
AutocompleteEmpty,
AutocompleteInput,
AutocompleteItem,
AutocompleteList,
AutocompletePopup,
} from "@/components/ui/autocomplete";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
const items = [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
{ label: "Orange", value: "orange" },
{ label: "Grape", value: "grape" },
{ label: "Strawberry", value: "strawberry" },
{ label: "Mango", value: "mango" },
{ label: "Pineapple", value: "pineapple" },
{ label: "Kiwi", value: "kiwi" },
{ label: "Peach", value: "peach" },
{ label: "Pear", value: "pear" },
];
export default function Particle() {
return (
<Field>
<FieldLabel>Fruits</FieldLabel>
<Autocomplete items={items}>
<AutocompleteInput aria-label="Search items" placeholder="Search items…" />
<AutocompletePopup>
<AutocompleteEmpty>No items found.</AutocompleteEmpty>
<AutocompleteList>
{(item) => (
<AutocompleteItem key={item.value} value={item}>
{item.label}
</AutocompleteItem>
)}
</AutocompleteList>
</AutocompletePopup>
</Autocomplete>
<FieldDescription>Select a item.</FieldDescription>
</Field>
);
}
Combobox Field
Select a item.
"use client";
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
const items = [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
{ label: "Orange", value: "orange" },
{ label: "Grape", value: "grape" },
{ label: "Strawberry", value: "strawberry" },
{ label: "Mango", value: "mango" },
{ label: "Pineapple", value: "pineapple" },
{ label: "Kiwi", value: "kiwi" },
{ label: "Peach", value: "peach" },
{ label: "Pear", value: "pear" },
];
export default function Particle() {
return (
<Field>
<FieldLabel>Fruits</FieldLabel>
<Combobox items={items}>
<ComboboxInput aria-label="Select an item" placeholder="Select an item..." />
<ComboboxContent>
<ComboboxEmpty>No results found.</ComboboxEmpty>
<ComboboxList>
{(item) => (
<ComboboxItem key={item.value} value={item}>
{item.label}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
<FieldDescription>Select a item.</FieldDescription>
</Field>
);
}
Combobox Multiple Field
Select multiple items.
"use client";
import {
Combobox,
ComboboxChip,
ComboboxChips,
ComboboxChipsInput,
ComboboxContent,
ComboboxEmpty,
ComboboxItem,
ComboboxList,
ComboboxValue,
} from "@/components/ui/combobox";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
const items = [
{ label: "Apple", value: "apple" },
{ label: "Banana", value: "banana" },
{ label: "Orange", value: "orange" },
{ label: "Grape", value: "grape" },
{ label: "Strawberry", value: "strawberry" },
{ label: "Mango", value: "mango" },
{ label: "Pineapple", value: "pineapple" },
{ label: "Kiwi", value: "kiwi" },
{ label: "Peach", value: "peach" },
{ label: "Pear", value: "pear" },
];
export default function Particle() {
return (
<Field>
<FieldLabel>Fruits</FieldLabel>
<Combobox defaultValue={[items[0], items[4]]} items={items} multiple>
<ComboboxChips>
<ComboboxValue>
{(value: { value: string; label: string }[]) => (
<>
{value?.map((item) => (
<ComboboxChip aria-label={item.label} key={item.value}>
{item.label}
</ComboboxChip>
))}
<ComboboxChipsInput
aria-label="Select items"
placeholder={value.length > 0 ? undefined : "Select items…"}
/>
</>
)}
</ComboboxValue>
</ComboboxChips>
<ComboboxContent>
<ComboboxEmpty>No items found.</ComboboxEmpty>
<ComboboxList>
{(item) => (
<ComboboxItem key={item.value} value={item}>
{item.label}
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
<FieldDescription>Select multiple items.</FieldDescription>
</Field>
);
}
Textarea Field
Write a short bio. Maximum 500 characters.
"use client";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Textarea } from "@/components/ui/textarea";
export default function Particle() {
return (
<Field>
<FieldLabel>Bio</FieldLabel>
<Textarea placeholder="Tell us about yourself…" />
<FieldDescription>Write a short bio. Maximum 500 characters.</FieldDescription>
</Field>
);
}
Select Field
This is an optional field
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
const items = [
{ label: "Select a country", value: null },
{ label: "United States", value: "us" },
{ label: "United Kingdom", value: "uk" },
{ label: "Canada", value: "ca" },
{ label: "Australia", value: "au" },
];
export default function Particle() {
return (
<Field>
<FieldLabel>Country</FieldLabel>
<Select items={items}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{items.map(({ label, value }) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
<FieldDescription>This is an optional field</FieldDescription>
</Field>
);
}
Checkbox Field
import { Checkbox } from "@/components/ui/checkbox";
import { Field, FieldLabel } from "@/components/ui/field";
export default function Particle() {
return (
<Field>
<FieldLabel>
<Checkbox />
Accept terms and conditions
</FieldLabel>
</Field>
);
}
Checkbox Group Field
"use client";
import { Checkbox } from "@/components/ui/checkbox";
import { CheckboxGroup } from "@/components/ui/checkbox-group";
import { Field, FieldLabel } from "@/components/ui/field";
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset";
export default function Particle() {
return (
<Fieldset className="gap-2">
<FieldsetLegend className="font-medium text-sm">Frameworks</FieldsetLegend>
<CheckboxGroup defaultValue={["react"]}>
<Field orientation="horizontal">
<FieldLabel>
<Checkbox value="react" /> React
</FieldLabel>
</Field>
<Field orientation="horizontal">
<FieldLabel>
<Checkbox value="vue" /> Vue
</FieldLabel>
</Field>
<Field orientation="horizontal">
<FieldLabel>
<Checkbox value="svelte" /> Svelte
</FieldLabel>
</Field>
</CheckboxGroup>
</Fieldset>
);
}
Radio Group Field
"use client";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
export default function Particle() {
return (
<Fieldset className="gap-2">
<FieldsetLegend className="font-medium text-sm">Choose Plan</FieldsetLegend>
<RadioGroup defaultValue="free">
<Field orientation="horizontal">
<FieldLabel>
<RadioGroupItem value="free" /> Free
</FieldLabel>
</Field>
<Field orientation="horizontal">
<FieldLabel>
<RadioGroupItem value="pro" /> Pro
</FieldLabel>
</Field>
<Field orientation="horizontal">
<FieldLabel>
<RadioGroupItem value="enterprise" /> Enterprise
</FieldLabel>
</Field>
</RadioGroup>
<FieldDescription>Select the plan that fits your needs.</FieldDescription>
</Fieldset>
);
}
Switch Field
import { Field, FieldLabel } from "@/components/ui/field";
import { Switch } from "@/components/ui/switch";
export default function Particle() {
return (
<Field>
<FieldLabel>
<Switch />
Email notifications
</FieldLabel>
</Field>
);
}
Slider Field
This is an optional field
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Slider } from "@/components/ui/slider";
export default function Particle() {
return (
<Field className="items-stretch gap-3">
<FieldLabel>Country</FieldLabel>
<Slider defaultValue={50} />
<FieldDescription>This is an optional field</FieldDescription>
</Field>
);
}
Number Field
Choose a value between 1 and 100.
import { Field, FieldDescription } from "@/components/ui/field";
import {
NumberField,
NumberFieldDecrement,
NumberFieldGroup,
NumberFieldIncrement,
NumberFieldInput,
NumberFieldScrubArea,
} from "@/components/ui/number-field";
export default function Particle() {
return (
<Field>
<NumberField defaultValue={1} max={100} min={1}>
<NumberFieldScrubArea label="Quantity" />
<NumberFieldGroup>
<NumberFieldDecrement />
<NumberFieldInput />
<NumberFieldIncrement />
</NumberFieldGroup>
</NumberField>
<FieldDescription>Choose a value between 1 and 100.</FieldDescription>
</Field>
);
}
Complete Form Example
"use client";
import type { FormEvent } from "react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
export default function Particle() {
const [loading, setLoading] = useState(false);
const onSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
setLoading(true);
await new Promise((r) => setTimeout(r, 800));
setLoading(false);
const data = {
email: formData.get("email"),
fullName: formData.get("fullName"),
newsletter: formData.get("newsletter"),
role: formData.get("role"),
};
alert(
`Full name: ${data.fullName || ""}\nEmail: ${data.email || ""}\nRole: ${
data.role || ""
}\nNewsletter: ${data.newsletter}`,
);
};
return (
<form className="flex w-full flex-col gap-3" onSubmit={onSubmit}>
<Field>
<FieldLabel>
Full Name <span className="text-destructive">*</span>
</FieldLabel>
<Input placeholder="John Doe" required type="text" />
<FieldError>Please enter a valid name.</FieldError>
</Field>
<Field>
<FieldLabel>
Email <span className="text-destructive">*</span>
</FieldLabel>
<Input placeholder="john@example.com" required type="email" />
<FieldError>Please enter a valid email.</FieldError>
</Field>
<Field>
<FieldLabel>Role</FieldLabel>
<Select
items={[
{ label: "Select your role", value: null },
{ label: "Developer", value: "developer" },
{ label: "Designer", value: "designer" },
{ label: "Product Manager", value: "manager" },
{ label: "Other", value: "other" },
]}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="developer">Developer</SelectItem>
<SelectItem value="designer">Designer</SelectItem>
<SelectItem value="manager">Product Manager</SelectItem>
<SelectItem value="other">Other</SelectItem>
</SelectContent>
</Select>
<FieldDescription>This is an optional field</FieldDescription>
</Field>
<Field>
<div className="flex items-center gap-2">
<Checkbox />
<FieldLabel className="cursor-pointer">Subscribe to newsletter</FieldLabel>
</div>
</Field>
<Button disabled={loading} type="submit">
{loading && <Spinner />}
Submit
</Button>
</form>
);
}
On This Page