Skip to content
All components
Forms

Field

Lay out one form control with its label and either a hint or an error, and group related fields, with every association wired explicitly.

The label, control, hint and error wrapper every control shares.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add field

Then import it from @/components/ui/field. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Billing details

Group fields in a fieldset with a legend, one hint and one associated error. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import {
  Field,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSet,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"

export function FieldBillingDetails() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <FieldSet className="w-full max-w-md">
        <FieldLegend>Billing details</FieldLegend>
        <FieldGroup>
          <Field>
            <FieldLabel htmlFor="field-demo-company">Company</FieldLabel>
            <Input id="field-demo-company" placeholder="Acme Inc." aria-describedby="field-demo-company-hint" />
            <FieldDescription id="field-demo-company-hint">
              Appears on every invoice we send.
            </FieldDescription>
          </Field>
          <Field>
            <FieldLabel htmlFor="field-demo-vat">VAT number</FieldLabel>
            <Input id="field-demo-vat" defaultValue="12" aria-invalid aria-describedby="field-demo-vat-error" />
            <FieldError id="field-demo-vat-error">A VAT number has at least 8 characters.</FieldError>
          </Field>
        </FieldGroup>
      </FieldSet>
    </div>
  )
}

Validate on blur

Validate when focus leaves the field and swap the hint for an error until it is fixed. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"

const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

export function FieldValidateOnBlur() {
  const id = React.useId()
  const [email, setEmail] = React.useState("")
  const [emailError, setEmailError] = React.useState<string | null>(null)

  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Field>
        <FieldLabel htmlFor={`${id}-invite`}>Work email</FieldLabel>
        <Input
          id={`${id}-invite`}
          type="email"
          autoComplete="email"
          value={email}
          aria-invalid={emailError ? true : undefined}
          aria-describedby={`${id}-invite-message`}
          onChange={(event) => {
            setEmail(event.target.value)
            // Once an error is shown, clear it as soon as the value is fixed.
            if (emailError && EMAIL_PATTERN.test(event.target.value)) setEmailError(null)
          }}
          onBlur={() => {
            // Validate when the person leaves the field, never on the first keystroke.
            if (email && !EMAIL_PATTERN.test(email)) {
              setEmailError("Enter an email address in the format name@company.com.")
            }
          }}
        />
        {emailError ? (
          <FieldError id={`${id}-invite-message`}>{emailError}</FieldError>
        ) : (
          <FieldDescription id={`${id}-invite-message`}>
            We send the invitation to this address.
          </FieldDescription>
        )}
      </Field>
    </div>
  )
}

Checkbox group

Describe a group of checkboxes with a legend and a hint linked to the fieldset. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Checkbox } from "@/components/ui/checkbox"
import { FieldDescription, FieldLegend, FieldSet } from "@/components/ui/field"

import { Label } from "@/components/ui/label"

export function FieldCheckboxGroup() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <FieldSet aria-describedby={`${id}-topics-hint`}>
        <FieldLegend>Email me about</FieldLegend>
        <FieldDescription id={`${id}-topics-hint`} className="-mt-3">
          Choose any. You can change this later in settings.
        </FieldDescription>
        <div className="flex flex-col gap-3">
          <div className="flex items-center gap-2">
            <Checkbox id={`${id}-topic-product`} defaultChecked />
            <Label htmlFor={`${id}-topic-product`}>Product updates</Label>
          </div>
          <div className="flex items-center gap-2">
            <Checkbox id={`${id}-topic-billing`} defaultChecked />
            <Label htmlFor={`${id}-topic-billing`}>Billing and invoices</Label>
          </div>
          <div className="flex items-center gap-2">
            <Checkbox id={`${id}-topic-events`} />
            <Label htmlFor={`${id}-topic-events`}>Events and webinars</Label>
          </div>
        </div>
      </FieldSet>
    </div>
  )
}

Setting row

Place a label and description beside a switch in one setting row. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

import { Switch } from "@/components/ui/switch"

export function FieldSettingRow() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <Field className="flex-row items-start justify-between gap-4">
        <div className="flex flex-col gap-1">
          <FieldLabel htmlFor={`${id}-public`}>Public profile</FieldLabel>
          <FieldDescription id={`${id}-public-hint`}>
            Anyone with the link can see your name and role.
          </FieldDescription>
        </div>
        <Switch id={`${id}-public`} aria-describedby={`${id}-public-hint`} />
      </Field>
    </div>
  )
}

Responsive columns

Stack fields on narrow screens and place them side by side from the small breakpoint. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import {
  Field,
  FieldDescription,
  FieldGroup,
  FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"

export function FieldResponsiveColumns() {
  const id = React.useId()
  
  

  return (
    <div className="flex w-full max-w-md flex-col gap-10">
      <FieldGroup className="sm:grid sm:grid-cols-2">
        <Field>
          <FieldLabel htmlFor={`${id}-city`}>City</FieldLabel>
          <Input id={`${id}-city`} autoComplete="address-level2" aria-describedby={`${id}-city-hint`} />
          <FieldDescription id={`${id}-city-hint`}>Used for local tax rates.</FieldDescription>
        </Field>
        <Field>
          <FieldLabel htmlFor={`${id}-postal`}>Postal code</FieldLabel>
          <Input id={`${id}-postal`} autoComplete="postal-code" aria-describedby={`${id}-postal-hint`} />
          <FieldDescription id={`${id}-postal-hint`}>Used to calculate shipping.</FieldDescription>
        </Field>
      </FieldGroup>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Field

The wrapper every form control shares: label, control, hint, error. Consumers choose whether to render a hint or an error and wire the control IDs explicitly. The wrapper provides layout, not automatic validation.

Field props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
Field inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FieldDescription

Hint text. Give it an id and reference it through the control aria-describedby.

FieldDescription props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
FieldDescription inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLParagraphElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLParagraphElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLParagraphElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLParagraphElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLParagraphElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FieldError

Error text. Render instead of a hint and connect its id to an aria-invalid control.

FieldError props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
FieldError inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLParagraphElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLParagraphElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLParagraphElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLParagraphElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLParagraphElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLParagraphElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FieldGroup

Group related parts while preserving the parent component's required composition.

FieldGroup props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
FieldGroup inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FieldLabel

Associate htmlFor with the control id; Field does not generate that association.

FieldLabel props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (15)
FieldLabel inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLLabelElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
htmlForstring | undefined—ID of the actual form control named by this label.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLLabelElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLLabelElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLLabelElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLLabelElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLLabelElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLLabelElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FieldLegend

The FieldLegend part of field. Use it with the complete source composition and preserve its required parent context.

FieldLegend props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
FieldLegend inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLLegendElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLLegendElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLLegendElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLLegendElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLLegendElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLLegendElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLLegendElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

FieldSet

The FieldSet part of field. Use it with the complete source composition and preserve its required parent context.

FieldSet props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (16)
FieldSet inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLFieldSetElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
namestring | undefined—Name used by the control's form submission or primitive form integration.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLFieldSetElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLFieldSetElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLFieldSetElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLFieldSetElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLFieldSetElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLFieldSetElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/field.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Any form control that needs a visible label plus a hint or an error: Input, Textarea, Select, NativeSelect, Combobox, DatePicker, Slider, InputOTP.
  • Grouping related controls under a fieldset and legend, such as an address, a set of checkboxes or a setting group.
  • Forms that do not use React Hook Form, or that validate with their own state.

When not to use

  • React Hook Form forms where FormItem, FormLabel and FormMessage can wire ids automatically.
  • Layout around controls that are not form input, such as buttons or links.

Anatomy

Field
A vertical stack for one control: label, control, then hint or error. Layout only; it creates no ids or validation.
FieldLabel
A native label; set htmlFor to the control id.
FieldDescription
Hint text; give it an id and reference it from the control's aria-describedby.
FieldError
Error text with role="alert". Renders nothing without children, so it can stay mounted while the field is valid.
FieldGroup
A vertical stack of fields with consistent spacing.
FieldSet and FieldLegend
A native fieldset and legend that name a group of related controls.

Keyboard & interaction

  • FieldLabel activates its control on click, like any native label.
  • FieldError has role="alert": rendering it announces the message once. Render it when an error is detected (on blur or submit), not on every keystroke.
  • When an error appears, keep focus where it is on blur; on submit move focus to the first invalid control.
  • A fieldset legend is announced when focus enters the group; keep it short.
  • Clear the error as soon as the value becomes valid, and show the hint again.

Responsive behavior

  • Single column by default. Put related short fields side by side only from a breakpoint where each keeps its expected width (for example sm:grid-cols-2 on a FieldGroup).
  • Keep the label above the control; side-by-side label and control only for switch setting rows, where the control sits at the end of the row.
  • Hints and errors wrap under the control and never truncate.
  • On phones, keep the error directly under its control so it stays visible near the on-screen keyboard.

Content guidelines

  • Label: a short noun phrase; hint: the format or constraint stated before input; error: what went wrong and how to fix it (WCAG 3.3.1, 3.3.2, 3.3.3).
  • Use the same words in hint and error so the fix is obvious ('3 to 20 characters' and 'Use 3 to 20 characters').
  • Write errors in plain language without blame or codes; avoid 'Invalid input' and 'Error 422'.
  • Legend: name the group ('Billing details', 'Email me about'), not the action.

Alternatives

  • Form — React Hook Form bindings that generate ids and aria-describedby for you.
  • Label — Only a visible name, without hint or error layout.

Resources