Field
Form field wrapper for labels, descriptions, errors, and validity state.
Examples
Choice card
FieldLabel variant="card" turns a label around a Radio or Checkbox into a selectable tile. The whole card selects the control, its border and fill follow the checked state, one focus ring wraps the card, and a disabled control disables the card. Wrap each card in FieldItem so every label targets its own control inside one Field; in a grid, every card fills its row to the tallest one.
Composition
Labeled control
FieldLegend names the set: a label-size semibold title by default, or variant="section" for a list title.
- <FieldSet>
- <FieldLegend />
- <FieldGroup>
- <Field>
- <FieldLabel />
- <FieldControl>
- render prop
- <Input />
- render prop
- <FieldDescription />
- <FieldError />
- <FieldSeparator />
- <Field>
Choice card
FieldLabel variant="card" paints the selectable tile: the whole card selects its control, the checked control colors its border and fill, and one focus ring wraps the card. FieldItem gives each label its own control inside the shared Field; FieldItem disabled disables one option. A Checkbox takes the Radio's place for multiple choice.
- <Field>
- <RadioGroup>
- <FieldItem>
- <FieldLabel>
- <Radio />
- <FieldContent>
- <FieldTitle />
- <FieldDescription />
- <FieldLabel>
- <FieldItem>
- <RadioGroup>
Settings list
FieldLegend variant="section" titles the list. FieldGroup variant="card" pads every row and draws the dividers between rows, so rows need no classes. Field orientation="responsive" moves the control beside its text once the group is wide enough. Skins tune rows through the --cui-field-group-* knobs and label weight through --cui-field-label-font-weight.
- <FieldSet>
- <FieldLegend />
- <FieldGroup>
- <Field>
- <FieldContent>
- <FieldLabel />
- <FieldDescription />
- control
- <FieldContent>
- <Field>
Installation
The Control UI source installs this component from src/registry/sources/control-ui/ui/field.tsx.
npx shadcn@latest add https://control-ui.dev/r/field.jsonDependencies
Raw code
Primary installed source
"use client";
import { Field as FieldPrimitive } from "@base-ui/react/field";import { Fieldset as FieldsetPrimitive } from "@base-ui/react/fieldset";import { cva } from "class-variance-authority";import type { ComponentProps, CSSProperties, ReactNode } from "react";import type { FieldKnobStyle } from "@/components/control-ui/knob-contracts/field-knobs";import { cn } from "@/components/control-ui/lib/cn";import { Separator } from "@/components/control-ui/ui/separator";
export type FieldProps = ComponentProps<"div"> & { orientation?: "vertical" | "horizontal" | "responsive"; name?: string; disabled?: boolean; invalid?: boolean; validationMode?: "onSubmit" | "onBlur" | "onChange"; validate?: FieldPrimitive.Root.Props["validate"]; validationDebounceTime?: number;} & { style?: CSSProperties & FieldKnobStyle };
export type FieldLabelVariant = "default" | "card";
export type FieldLabelProps = Omit<ComponentProps<"label">, "style"> & { variant?: FieldLabelVariant; style?: CSSProperties & FieldKnobStyle;};
export type FieldContentProps = ComponentProps<"div"> & { style?: CSSProperties & FieldKnobStyle };
export type FieldTitleProps = Omit<ComponentProps<"div">, "style"> & { style?: CSSProperties & FieldKnobStyle };
export type FieldControlProps = Omit<ComponentProps<"input">, "style"> & Pick<ComponentProps<typeof FieldPrimitive.Control>, "render"> & { style?: CSSProperties & FieldKnobStyle };
export type FieldDescriptionProps = Omit<ComponentProps<"p">, "style"> & { style?: CSSProperties & FieldKnobStyle };
export type FieldErrorMatch = boolean | keyof ValidityState;
export type FieldErrorProps = Omit<ComponentProps<"div">, "style"> & { match?: FieldErrorMatch; style?: CSSProperties & FieldKnobStyle;};
export type FieldGroupVariant = "default" | "card";
export type FieldGroupProps = ComponentProps<"div"> & { variant?: FieldGroupVariant; style?: CSSProperties & FieldKnobStyle };
export type FieldSeparatorProps = Omit<ComponentProps<"div">, "style"> & { children?: ReactNode; style?: CSSProperties & FieldKnobStyle;};
export type FieldItemProps = ComponentProps<"div"> & { disabled?: boolean; style?: CSSProperties & FieldKnobStyle };
export type FieldSetProps = Omit<ComponentProps<"fieldset">, "style"> & { style?: CSSProperties & FieldKnobStyle };
export type FieldLegendVariant = "default" | "section";
export type FieldLegendProps = Omit<ComponentProps<"div">, "style"> & { variant?: FieldLegendVariant; style?: CSSProperties & FieldKnobStyle;};
const fieldVariants = cva("group/field flex w-full", { variants: { orientation: { vertical: "flex-col items-start [&>[data-control-ui=field][data-slot=content]]:w-full [&>[data-control-ui=field][data-slot=control]]:w-full", horizontal: "flex-row items-center [&>[data-control-ui=field][data-slot=label]]:flex-auto has-[>[data-control-ui=field][data-slot=content]]:items-start", responsive: "flex-col items-start [&>[data-control-ui=field][data-slot=content]]:w-full [&>[data-control-ui=field][data-slot=control]]:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>[data-control-ui=field][data-slot=content]]:w-auto @md/field-group:[&>[data-control-ui=field][data-slot=control]]:w-auto @md/field-group:[&>[data-control-ui=field][data-slot=label]]:flex-auto @md/field-group:has-[>[data-control-ui=field][data-slot=content]]:items-start", }, }, defaultVariants: { orientation: "vertical", },});
export function Field({ className, orientation = "vertical", ...props }: FieldProps) { return ( <FieldPrimitive.Root data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="root" data-orientation={orientation} className={cn(fieldVariants({ orientation }), className)} {...props} /> );}
export function FieldContent({ className, ...props }: FieldContentProps) { return ( <div data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="content" className={cn("flex min-w-0 flex-1 flex-col", className)} {...props} /> );}
export function FieldTitle({ className, ...props }: FieldTitleProps) { return ( <div data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="title" className={className} {...props} /> );}
export function FieldLabel({ className, variant = "default", ...props }: FieldLabelProps) { return ( <FieldPrimitive.Label data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="label" data-variant={variant} data-focus-ring={variant === "card" ? "within" : undefined} className={cn( variant === "card" && "flex w-full items-start gap-3 self-stretch [&>[data-control-family=choice]]:mt-[calc((1lh_-_var(--cui-choice-size))/2)]", className, )} {...props} /> );}
export function FieldControl({ className, render, ...props }: FieldControlProps) { const classes = cn("w-full", className);
if (render !== undefined) { return ( <FieldPrimitive.Control data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="control" className={classes} render={render} {...props} /> ); }
return ( <FieldPrimitive.Control data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="control" data-control="true" data-size="md" className={classes} {...props} /> );}
export function FieldDescription({ className, ...props }: FieldDescriptionProps) { return ( <FieldPrimitive.Description data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="description" className={className} {...props} /> );}
export function FieldError({ className, ...props }: FieldErrorProps) { return ( <div data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="error-reserve" className="min-h-[1lh]"> <FieldPrimitive.Error data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="error" className={className} {...props} /> </div> );}
export function FieldGroup({ className, variant = "default", ...props }: FieldGroupProps) { return ( <div data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="group" data-variant={variant} className={cn("group/field-group @container/field-group flex flex-col", className)} {...props} /> );}
export function FieldSeparator({ children, className, ...props }: FieldSeparatorProps) { return ( <div data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="separator" data-content={children ? "true" : undefined} className={cn("relative", className)} {...props} > <Separator className={children ? "absolute top-1/2" : undefined} /> {children ? ( <span data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="separator-content" className="relative block w-fit" > {children} </span> ) : null} </div> );}
export function FieldItem({ className, ...props }: FieldItemProps) { return ( <FieldPrimitive.Item data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="item" className={cn("flex items-center", className)} {...props} /> );}
export function FieldSet({ className, ...props }: FieldSetProps) { return ( <FieldsetPrimitive.Root data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="set" className={cn("flex flex-col", className)} {...props} /> );}
export function FieldLegend({ className, variant = "default", ...props }: FieldLegendProps) { return ( <FieldsetPrimitive.Legend data-control-ui="field" data-control-family="field" data-field-kind="field" data-slot="legend" data-variant={variant} className={className} {...props} /> );}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-field-label-radius | <length-percentage> | var(--radius-control) |
--cui-field-label-background | <color> | transparent |
--cui-field-label-hover-background | <color> | var(--hover-fill) |
--cui-field-label-checked-background | <color> | oklch(from var(--primary) l c h / 0.06) |
--cui-field-label-border-color | <color> | var(--border) |
--cui-field-label-checked-border-color | <color> | var(--primary) |
--cui-field-label-border-width | <length> | var(--control-rim-width) |
--cui-field-label-padding-block | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-label-padding-inline | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-legend-foreground | <color> | var(--foreground) |
--cui-field-legend-font-size | <length-percentage> | var(--text-label) |
--cui-field-legend-font-weight | <number> | var(--font-weight-semibold) |
--cui-field-radius | <length-percentage> | var(--nest-radius, var(--radius-control)) |
--cui-field-background | <color> | var(--control-fill) |
--cui-field-hover-background | <color> | var(--hover-fill) |
--cui-field-affordance-background | <color> | transparent |
--cui-field-affordance-shadow | * | 0 0 transparent |
--cui-field-affordance-foreground | <color> | var(--muted-foreground) |
--cui-field-affordance-hover-background | <color> | var(--hover-fill) |
--cui-field-foreground | <color> | var(--foreground) |
--cui-field-border-color | <color> | var(--control-rim) |
--cui-field-focus-border-color | <color> | var(--focus-rim) |
--cui-field-border-width | <length> | var(--control-rim-width) |
--cui-field-shadow | * | var(--shadow-inset) |
--cui-field-backdrop-filter | * | blur(0px) |
--cui-field-height | <length-percentage> | var(--control-h-md) |
--cui-field-padding-inline | <length-percentage> | var(--padding-x) |
--cui-field-font-size | <length-percentage> | var(--text-body) |
--cui-field-font-weight | <number> | var(--font-weight-normal) |
--cui-field-font-family | * | var(--font-body) |
--cui-field-group-radius | <length-percentage> | var(--radius-panel) |
--cui-field-group-background | <color> | var(--card) |
--cui-field-group-border-color | <color> | var(--border) |
--cui-field-group-border-width | <length> | 1px |
--cui-field-group-shadow | * | 0 0 transparent |
--cui-field-group-padding-block | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-group-padding-inline | <length-percentage> | calc(var(--spacing) * 4) |
--cui-field-group-separator-color | <color> | var(--border) |
--cui-field-group-separator-inset | <length-percentage> | 0px |
--cui-field-label-font-size | <length-percentage> | var(--text-label) |
--cui-field-label-font-weight | <number> | var(--font-weight-medium) |
--cui-field-description-font-size | <length-percentage> | var(--text-caption) |