Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Copy Button
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Form
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Page Header
- Pagination
- Panel
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Section Header
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Stat
- Stat Card
- Switch
- Table
- Tabs
- Textarea
- Theme Toggle
- Toggle
- Toggle Group
- Tooltip
- Typography
Field
Compose accessible form fields and grouped inputs.
This is your public display name.
01
Installation
Add the field component with the shadcn CLI.
bash
npx shadcn@latest add https://swiss.ui.unsanity.ai/r/field.json02
Usage
tsx
import { Field } from "@/components/ui/field"03
Examples
Field
Label + control + descriptionWe will never share your email.
import {
Field,
FieldDescription,
FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
<Field className="w-72">
<FieldLabel htmlFor="field-email">Email</FieldLabel>
<Input id="field-email" type="email" placeholder="you@example.com" />
<FieldDescription>We will never share your email.</FieldDescription>
</Field>Field Group
Stack related fieldsimport { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
<FieldGroup className="w-72">
<Field>
<FieldLabel htmlFor="fg-first">First name</FieldLabel>
<Input id="fg-first" placeholder="Jane" />
</Field>
<Field>
<FieldLabel htmlFor="fg-last">Last name</FieldLabel>
<Input id="fg-last" placeholder="Cooper" />
</Field>
</FieldGroup>Field Set + Legend
Grouped fieldsetimport {
Field,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSet,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
<FieldSet className="w-72">
<FieldLegend>Billing address</FieldLegend>
<FieldGroup>
<Field>
<FieldLabel htmlFor="fs-street">Street</FieldLabel>
<Input id="fs-street" placeholder="123 Helvetica St" />
</Field>
<Field>
<FieldLabel htmlFor="fs-city">City</FieldLabel>
<Input id="fs-city" placeholder="Zurich" />
</Field>
</FieldGroup>
</FieldSet>Horizontal Field
Control beside contentMarketing emails
Receive product updates.
import {
Field,
FieldContent,
FieldDescription,
FieldTitle,
} from "@/components/ui/field"
import { Switch } from "@/components/ui/switch"
<Field orientation="horizontal" className="w-72 items-center justify-between">
<FieldContent>
<FieldTitle>Marketing emails</FieldTitle>
<FieldDescription>Receive product updates.</FieldDescription>
</FieldContent>
<Switch defaultChecked />
</Field>Field Error
Invalid statePassword must be at least 8 characters.
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
<Field data-invalid className="w-72">
<FieldLabel htmlFor="field-pw">Password</FieldLabel>
<Input id="field-pw" type="password" aria-invalid defaultValue="123" />
<FieldError>Password must be at least 8 characters.</FieldError>
</Field>Field Separator
Divide field groupsor
import { Field, FieldGroup, FieldLabel, FieldSeparator } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
<FieldGroup className="w-72">
<Field>
<FieldLabel htmlFor="fsep-user">Username</FieldLabel>
<Input id="fsep-user" placeholder="swiss" />
</Field>
<FieldSeparator>or</FieldSeparator>
<Field>
<FieldLabel htmlFor="fsep-email">Email</FieldLabel>
<Input id="fsep-email" type="email" placeholder="you@example.com" />
</Field>
</FieldGroup>