Field
Form layout: a label, the control, a description and errors, in groups and fieldsets.
@cupertinoui/fieldRegistry JSON import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldContent, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
export default function FieldDemo() {
return (
<FieldSet className="w-full max-w-sm">
<FieldLegend>Create Apple Account</FieldLegend>
<FieldDescription>Use this account for iCloud, the App Store and more.</FieldDescription>
<FieldGroup>
<Field>
<FieldLabel htmlFor="field-name">Name</FieldLabel>
<Input id="field-name" placeholder="John Appleseed" />
</Field>
<Field data-invalid="true">
<FieldLabel htmlFor="field-email">Email</FieldLabel>
<Input id="field-email" defaultValue="john@" aria-invalid />
<FieldError>Enter a valid email address.</FieldError>
</Field>
<FieldSeparator />
<Field orientation="horizontal">
<Checkbox id="field-news" defaultChecked />
<FieldContent>
<FieldLabel htmlFor="field-news">News and announcements</FieldLabel>
<FieldDescription>Get the latest about products, services and software updates.</FieldDescription>
</FieldContent>
</Field>
</FieldGroup>
</FieldSet>
)
}Installation
pnpm dlx shadcn@latest add @cupertinoui/fieldThe first install also adds the macOS theme. See Installation to set up the registry.
Usage
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
<Field>
<FieldLabel htmlFor="name">Name</FieldLabel>
<Input id="name" />
<FieldDescription>As it appears on your Apple Account.</FieldDescription>
</Field>API Reference
Every part forwards the props of the underlying element. The props below are the ones CupertinoUI adds or changes.
Field
| Prop | Type | Description |
|---|---|---|
orientation | "vertical" | "horizontal" | "responsive"Default: "vertical" | Label above the control, beside it, or beside it on wide screens. |
data-invalid | boolean | Colors the field red. |
className | string | Extra classes, merged with the component's own. |
FieldError
| Prop | Type | Description |
|---|---|---|
errors | { message?: string }[] | Messages to list, e.g. from a form library. |
className | string | Extra classes, merged with the component's own. |
FieldSet / FieldLegend / FieldGroup / FieldContent / FieldLabel / FieldTitle / FieldDescription / FieldSeparator
| Prop | Type | Description |
|---|---|---|
className | string | Extra classes, merged with the component's own. |