Field

Combine labels, controls, and help text to compose accessible form fields and grouped inputs.

Payment Method

All transactions are secure and encrypted

Enter your 16-digit card number

Billing Address

The billing address associated with your payment method

Installation

pnpm dlx cubix@latest add field --base radix

Usage

Import
import {
  Field,
  FieldContent,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSeparator,
  FieldSet,
  FieldTitle,
} from "@/components/cubix/field"
Example
<FieldSet>
  <FieldLegend>Profile</FieldLegend>
  <FieldDescription>This appears on invoices and emails.</FieldDescription>
  <FieldGroup>
    <Field>
      <FieldLabel htmlFor="name">Full name</FieldLabel>
      <Input id="name" autoComplete="off" placeholder="Evil Rabbit" />
      <FieldDescription>This appears on invoices and emails.</FieldDescription>
    </Field>
    <Field>
      <FieldLabel htmlFor="username">Username</FieldLabel>
      <Input id="username" autoComplete="off" aria-invalid />
      <FieldError>Choose another username.</FieldError>
    </Field>
    <Field orientation="horizontal">
      <Switch id="newsletter" />
      <FieldLabel htmlFor="newsletter">Subscribe to the newsletter</FieldLabel>
    </Field>
  </FieldGroup>
</FieldSet>

Composition

Field

A single control with label, helper text, and validation.

 
Field
├── FieldLabel
├── Input / Textarea / Switch / Select
├── FieldDescription
└── FieldError

FieldGroup

Related fields in one group. Use FieldSeparator between sections when needed.

 
FieldGroup
├── Field
   ├── FieldLabel
   ├── Input / Textarea / Switch / Select
   ├── FieldDescription
   └── FieldError
├── FieldSeparator
└── Field
    ├── FieldLabel
    └── Input / Textarea / Switch / Select

FieldSet

Semantic grouping with a legend and description, usually containing a FieldGroup.

 
FieldSet
├── FieldLegend
├── FieldDescription
└── FieldGroup
    ├── Field
       ├── FieldLabel
       ├── Input / Textarea / Switch / Select
       ├── FieldDescription
       └── FieldError
    └── Field
        ├── FieldLabel
        └── Input / Textarea / Switch / Select

Anatomy

The Field family is designed for composing accessible forms. A typical field is structured as follows:

 
<Field>
  <FieldLabel htmlFor="input-id">Label</FieldLabel>
  {/* Input, Select, Switch, etc. */}
  <FieldDescription>Optional helper text.</FieldDescription>
  <FieldError>Validation message.</FieldError>
</Field>
  • Field is the core wrapper for a single field.
  • FieldContent is a flex column that groups label and description. Not required if you have no description.
  • Wrap related fields with FieldGroup, and use FieldSet with FieldLegend for semantic grouping.

Input

Choose a unique username for your account.

Must be at least 8 characters long.

Textarea

Share your thoughts about our service.

Select

Select your department or area of work.

Fieldset

Address Information

We need your address to deliver your order.

Checkbox

Show these items on the desktop

Select the items you want to show on the desktop.

Your Desktop & Documents folders are being synced with iCloud Drive. You can access them from other devices.

Radio

Subscription Plan

Yearly and lifetime plans offer significant savings.

Switch

Choice Card

Wrap Field components inside FieldLabel to create selectable field groups. This works with radio, checkbox, and switch controls.

Compute Environment

Select the compute environment for your cluster.

Field Group

Stack Field components with FieldGroup. Add FieldSeparator to divide them.

Get notified when an assistant responds to requests that take time, like research or image generation.

Get notified when tasks you've created have updates. Manage tasks

Responsive Layout

  • Vertical fields: Default orientation stacks label, control, and helper text - ideal for mobile-first layouts.
  • Horizontal fields: Set orientation="horizontal" on Field to align the label and control side-by-side. Pair with FieldContent to keep descriptions aligned.
  • Responsive fields: Set orientation="responsive" for automatic column layouts inside container-aware parents. Apply @container/field-group classes on FieldGroup to switch orientations at specific breakpoints.
Profile

Fill in your profile information.

Provide your full name for identification

Validation and Errors

  • Add data-invalid to Field to switch the entire block into an error state.
  • Add aria-invalid on the input itself for assistive technologies.
  • Render FieldError immediately after the control or inside FieldContent to keep error messages aligned with the field.
 
<Field data-invalid>
  <FieldLabel htmlFor="email">Email</FieldLabel>
  <Input id="email" type="email" aria-invalid />
  <FieldError>Enter a valid email address.</FieldError>
</Field>

Accessibility

  • FieldSet and FieldLegend keep related controls grouped for keyboard and assistive tech users.
  • Field outputs role="group" so nested controls inherit labeling from FieldLabel and FieldLegend when combined.
  • Apply FieldSeparator sparingly to ensure screen readers encounter clear section boundaries.

API Reference

FieldSet

Container that renders a semantic fieldset with spacing presets.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldLegend

Legend element for a FieldSet. Switch to the label variant to align with label sizing.

PropTypeDefaultDescription
variant"legend" | "label""legend"Visual size of the legend. Use label for nested fieldsets that should match FieldLabel.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldGroup

Layout wrapper that stacks Field components and enables container queries for responsive orientations.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

Field

The core wrapper for a single field. Provides orientation control, invalid state styling, and spacing.

PropTypeDefaultDescription
orientation"vertical" | "horizontal" | "responsive""vertical"Layout of the label and control. responsive switches at the FieldGroup container breakpoint.
data-invalidboolean-Marks the field as invalid and applies destructive text color.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldContent

Flex column that groups control and descriptions when the label sits beside the control. Not required if you have no description.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldLabel

Label styled for both direct inputs and nested Field children.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldTitle

Renders a title with label styling inside FieldContent.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldDescription

Helper text slot that automatically balances long lines in horizontal layouts.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

FieldSeparator

Visual divider to separate sections inside a FieldGroup. Accepts optional inline content.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Optional label rendered over the separator line.

FieldError

Accessible error container that accepts children or an errors array.

PropTypeDefaultDescription
errorsArray<{ message?: string } | undefined>-Validation messages to render. Multiple unique messages become a list.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Custom error content. When set, errors is ignored.