Field
Combine labels, controls, and help text to compose accessible form fields and grouped inputs.
import { on } from '@ember/modifier';
import { tracked } from '@glimmer/tracking';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSeparator,
FieldSet,
} from '@/components/ui/field';
import { Input } from '@/components/ui/input';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { Textarea } from '@/components/ui/textarea';
class FieldDemoState {
@tracked cardName = '';
@tracked cardNumber = '';
@tracked cvv = '';
@tracked expMonth = '';
@tracked expYear = '';
@tracked sameAsShipping = true;
@tracked comments = '';
updateCardName = (event: Event) => {
this.cardName = (event.target as HTMLInputElement).value;
};
updateCardNumber = (event: Event) => {
this.cardNumber = (event.target as HTMLInputElement).value;
};
updateCvv = (event: Event) => {
this.cvv = (event.target as HTMLInputElement).value;
};
updateComments = (event: Event) => {
this.comments = (event.target as HTMLTextAreaElement).value;
};
selectMonth = (value: string) => {
this.expMonth = value;
};
selectYear = (value: string) => {
this.expYear = value;
};
toggleSameAsShipping = (checked: boolean) => {
this.sameAsShipping = checked;
};
handleSubmit = (event: Event) => {
event.preventDefault();
console.log('Form submitted');
};
}
const state = new FieldDemoState();
<template>
<div class="w-full rounded-lg border p-6">
<form {{on "submit" state.handleSubmit}}>
<FieldGroup>
<FieldSet>
<FieldLegend>Payment Method</FieldLegend>
<FieldDescription>
All transactions are secure and encrypted
</FieldDescription>
<FieldGroup>
<Field>
<FieldLabel @for="checkout-card-name">
Name on Card
</FieldLabel>
<Input
id="checkout-card-name"
placeholder="John Doe"
required
value={{state.cardName}}
{{on "input" state.updateCardName}}
/>
</Field>
<div class="grid grid-cols-3 gap-4">
<Field @class="col-span-2">
<FieldLabel @for="checkout-card-number">
Card Number
</FieldLabel>
<Input
id="checkout-card-number"
placeholder="1234 5678 9012 3456"
required
value={{state.cardNumber}}
{{on "input" state.updateCardNumber}}
/>
<FieldDescription>
Enter your 16-digit number.
</FieldDescription>
</Field>
<Field @class="col-span-1">
<FieldLabel @for="checkout-cvv">CVV</FieldLabel>
<Input
id="checkout-cvv"
placeholder="123"
required
value={{state.cvv}}
{{on "input" state.updateCvv}}
/>
</Field>
</div>
<div class="grid grid-cols-2 gap-4">
<Field>
<FieldLabel @for="checkout-exp-month">
Month
</FieldLabel>
<Select @onValueChange={{state.selectMonth}}>
<SelectTrigger id="checkout-exp-month">
<SelectValue @placeholder="MM" />
</SelectTrigger>
<SelectContent>
<SelectItem @value="01">01</SelectItem>
<SelectItem @value="02">02</SelectItem>
<SelectItem @value="03">03</SelectItem>
<SelectItem @value="04">04</SelectItem>
<SelectItem @value="05">05</SelectItem>
<SelectItem @value="06">06</SelectItem>
<SelectItem @value="07">07</SelectItem>
<SelectItem @value="08">08</SelectItem>
<SelectItem @value="09">09</SelectItem>
<SelectItem @value="10">10</SelectItem>
<SelectItem @value="11">11</SelectItem>
<SelectItem @value="12">12</SelectItem>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel @for="checkout-exp-year">
Year
</FieldLabel>
<Select @onValueChange={{state.selectYear}}>
<SelectTrigger id="checkout-exp-year">
<SelectValue @placeholder="YYYY" />
</SelectTrigger>
<SelectContent>
<SelectItem @value="2024">2024</SelectItem>
<SelectItem @value="2025">2025</SelectItem>
<SelectItem @value="2026">2026</SelectItem>
<SelectItem @value="2027">2027</SelectItem>
<SelectItem @value="2028">2028</SelectItem>
<SelectItem @value="2029">2029</SelectItem>
</SelectContent>
</Select>
</Field>
</div>
</FieldGroup>
</FieldSet>
<FieldSeparator />
<FieldSet>
<FieldLegend>Billing Address</FieldLegend>
<FieldDescription>
The billing address associated with your payment method
</FieldDescription>
<FieldGroup>
<Field @orientation="horizontal">
<Checkbox
@checked={{state.sameAsShipping}}
@onCheckedChange={{state.toggleSameAsShipping}}
id="checkout-same-as-shipping"
/>
<FieldLabel @class="font-normal" @for="checkout-same-as-shipping">
Same as shipping address
</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>
<FieldSeparator />
<FieldSet>
<FieldGroup>
<Field>
<FieldLabel @for="checkout-optional-comments">
Comments
</FieldLabel>
<Textarea
id="checkout-optional-comments"
placeholder="Add any additional comments"
value={{state.comments}}
{{on "input" state.updateComments}}
/>
</Field>
</FieldGroup>
</FieldSet>
<Field @orientation="horizontal">
<Button type="submit">Submit</Button>
<Button @variant="outline" type="button">
Cancel
</Button>
</Field>
</FieldGroup>
</form>
</div>
</template>Installation
Usage
import {
Field,
FieldContent,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSeparator,
FieldSet,
FieldTitle,
} from '@/components/ui/field';<FieldSet>
<FieldLegend>Profile</FieldLegend>
<FieldDescription>This appears on invoices and emails.</FieldDescription>
<FieldGroup>
<Field>
<FieldLabel @for="name">Full name</FieldLabel>
<Input id="name" autocomplete="off" placeholder="Evil Rabbit" />
<FieldDescription>This appears on invoices and emails.</FieldDescription>
</Field>
<Field>
<FieldLabel @for="username">Username</FieldLabel>
<Input id="username" autocomplete="off" aria-invalid />
<FieldError>Choose another username.</FieldError>
</Field>
<Field @orientation="horizontal">
<Switch id="newsletter" />
<FieldLabel @for="newsletter">Subscribe to the newsletter</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>Anatomy
The
Field
family is designed for composing accessible forms. A typical field is structured as follows:
<Field>
<FieldLabel @for="input-id">Label</FieldLabel>
{{! Input, Select, Switch, etc. }}
<FieldDescription>Optional helper text.</FieldDescription>
<FieldError>Validation message.</FieldError>
</Field>-
Fieldis the core wrapper for a single field. -
FieldContentis a flex column that groups label and description. Not required if you have no description. -
Wrap related fields with
FieldGroup, and useFieldSetwithFieldLegendfor semantic grouping.
Form
See the
Form
documentation for building forms with the
Field
component and React Hook Form or Tanstack Form.
Examples
Input
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
FieldSet,
} from '@/components/ui/field';
import { Input } from '@/components/ui/input';
<template>
<div class="w-full max-w-md">
<FieldSet>
<FieldGroup>
<Field>
<FieldLabel @for="username">Username</FieldLabel>
<Input id="username" placeholder="Max Leiter" type="text" />
<FieldDescription>
Choose a unique username for your account.
</FieldDescription>
</Field>
<Field>
<FieldLabel @for="password">Password</FieldLabel>
<FieldDescription>
Must be at least 8 characters long.
</FieldDescription>
<Input id="password" placeholder="••••••••" type="password" />
</Field>
</FieldGroup>
</FieldSet>
</div>
</template>Textarea
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
FieldSet,
} from '@/components/ui/field';
import { Textarea } from '@/components/ui/textarea';
<template>
<div class="w-full max-w-md">
<FieldSet>
<FieldGroup>
<Field>
<FieldLabel @for="feedback">Feedback</FieldLabel>
<Textarea
id="feedback"
placeholder="Your feedback helps us improve..."
rows="4"
/>
<FieldDescription>
Share your thoughts about our service.
</FieldDescription>
</Field>
</FieldGroup>
</FieldSet>
</div>
</template>Select
Select your department or area of work.
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
<template>
<div class="w-full max-w-md">
<Field>
<FieldLabel>Department</FieldLabel>
<Select>
<SelectTrigger>
<SelectValue @placeholder="Choose department" />
</SelectTrigger>
<SelectContent>
<SelectItem @value="engineering">Engineering</SelectItem>
<SelectItem @value="design">Design</SelectItem>
<SelectItem @value="marketing">Marketing</SelectItem>
<SelectItem @value="sales">Sales</SelectItem>
<SelectItem @value="support">Customer Support</SelectItem>
<SelectItem @value="hr">Human Resources</SelectItem>
<SelectItem @value="finance">Finance</SelectItem>
<SelectItem @value="operations">Operations</SelectItem>
</SelectContent>
</Select>
<FieldDescription>
Select your department or area of work.
</FieldDescription>
</Field>
</div>
</template>Slider
Set your budget range ($200 - 800).
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { Field, FieldDescription, FieldTitle } from '@/components/ui/field';
import { Slider } from '@/components/ui/slider';
class FieldSlider extends Component {
@tracked value = [200, 800];
handleValueChange = (newValue: number[]) => {
this.value = newValue;
};
get minValue() {
return this.value[0];
}
get maxValue() {
return this.value[1] ?? this.value[0];
}
<template>
<div class="w-full max-w-md">
<Field>
<FieldTitle>Price Range</FieldTitle>
<FieldDescription>
Set your budget range ($<span
class="font-medium tabular-nums"
>{{this.minValue}}</span>
-
<span class="font-medium tabular-nums">{{this.maxValue}}</span>).
</FieldDescription>
<Slider
@class="mt-2 w-full"
@max={{1000}}
@min={{0}}
@onValueChange={{this.handleValueChange}}
@step={{10}}
@value={{this.value}}
aria-label="Price Range"
/>
</Field>
</div>
</template>
}
export default FieldSlider;Fieldset
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSet,
} from '@/components/ui/field';
import { Input } from '@/components/ui/input';
<template>
<div class="w-full max-w-md space-y-6">
<FieldSet>
<FieldLegend>Address Information</FieldLegend>
<FieldDescription>
We need your address to deliver your order.
</FieldDescription>
<FieldGroup>
<Field>
<FieldLabel @for="street">Street Address</FieldLabel>
<Input id="street" placeholder="123 Main St" type="text" />
</Field>
<div class="grid grid-cols-2 gap-4">
<Field>
<FieldLabel @for="city">City</FieldLabel>
<Input id="city" placeholder="New York" type="text" />
</Field>
<Field>
<FieldLabel @for="zip">Postal Code</FieldLabel>
<Input id="zip" placeholder="90502" type="text" />
</Field>
</div>
</FieldGroup>
</FieldSet>
</div>
</template>Checkbox
Your Desktop & Documents folders are being synced with iCloud Drive. You can access them from other devices.
import { Checkbox } from '@/components/ui/checkbox';
import {
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSeparator,
FieldSet,
} from '@/components/ui/field';
<template>
<div class="w-full max-w-md">
<FieldGroup>
<FieldSet>
<FieldLegend @variant="label">
Show these items on the desktop
</FieldLegend>
<FieldDescription>
Select the items you want to show on the desktop.
</FieldDescription>
<FieldGroup @class="gap-3">
<Field @orientation="horizontal">
<Checkbox @checked={{true}} id="finder-pref-hard-disks" />
<FieldLabel @class="font-normal" @for="finder-pref-hard-disks">
Hard disks
</FieldLabel>
</Field>
<Field @orientation="horizontal">
<Checkbox id="finder-pref-external-disks" />
<FieldLabel @class="font-normal" @for="finder-pref-external-disks">
External disks
</FieldLabel>
</Field>
<Field @orientation="horizontal">
<Checkbox id="finder-pref-cds-dvds" />
<FieldLabel @class="font-normal" @for="finder-pref-cds-dvds">
CDs, DVDs, and iPods
</FieldLabel>
</Field>
<Field @orientation="horizontal">
<Checkbox id="finder-pref-connected-servers" />
<FieldLabel
@class="font-normal"
@for="finder-pref-connected-servers"
>
Connected servers
</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>
<FieldSeparator />
<Field @orientation="horizontal">
<Checkbox @checked={{true}} id="finder-pref-sync-folders" />
<FieldContent>
<FieldLabel @for="finder-pref-sync-folders">
Sync Desktop & Documents folders
</FieldLabel>
<FieldDescription>
Your Desktop & Documents folders are being synced with iCloud Drive.
You can access them from other devices.
</FieldDescription>
</FieldContent>
</Field>
</FieldGroup>
</div>
</template>Radio
import {
Field,
FieldDescription,
FieldLabel,
FieldSet,
} from '@/components/ui/field';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
<template>
<div class="w-full max-w-md">
<FieldSet>
<FieldLabel>Subscription Plan</FieldLabel>
<FieldDescription>
Yearly and lifetime plans offer significant savings.
</FieldDescription>
<RadioGroup @defaultValue="monthly">
<Field @orientation="horizontal">
<RadioGroupItem @value="monthly" id="plan-monthly" />
<FieldLabel @class="font-normal" @for="plan-monthly">
Monthly ($9.99/month)
</FieldLabel>
</Field>
<Field @orientation="horizontal">
<RadioGroupItem @value="yearly" id="plan-yearly" />
<FieldLabel @class="font-normal" @for="plan-yearly">
Yearly ($99.99/year)
</FieldLabel>
</Field>
<Field @orientation="horizontal">
<RadioGroupItem @value="lifetime" id="plan-lifetime" />
<FieldLabel @class="font-normal" @for="plan-lifetime">
Lifetime ($299.99)
</FieldLabel>
</Field>
</RadioGroup>
</FieldSet>
</div>
</template>Switch
Enable multi-factor authentication. If you do not have a two-factor device, you can use a one-time code sent to your email.
import {
Field,
FieldContent,
FieldDescription,
FieldLabel,
} from '@/components/ui/field';
import { Switch } from '@/components/ui/switch';
<template>
<div class="w-full max-w-md">
<Field @orientation="horizontal">
<FieldContent>
<FieldLabel @for="2fa">Multi-factor authentication</FieldLabel>
<FieldDescription>
Enable multi-factor authentication. If you do not have a two-factor
device, you can use a one-time code sent to your email.
</FieldDescription>
</FieldContent>
<Switch id="2fa" />
</Field>
</div>
</template>Choice Card
Wrap
Field
components inside
FieldLabel
to create selectable field groups. This works with
RadioItem
,
Checkbox
and
Switch
components.
import {
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
FieldSet,
FieldTitle,
} from '@/components/ui/field';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
<template>
<div class="w-full max-w-md">
<FieldGroup>
<FieldSet>
<FieldLabel @for="compute-environment">
Compute Environment
</FieldLabel>
<FieldDescription>
Select the compute environment for your cluster.
</FieldDescription>
<RadioGroup @defaultValue="kubernetes">
<FieldLabel @for="kubernetes-radio">
<Field @orientation="horizontal">
<FieldContent>
<FieldTitle>Kubernetes</FieldTitle>
<FieldDescription>
Run GPU workloads on a K8s configured cluster.
</FieldDescription>
</FieldContent>
<RadioGroupItem @value="kubernetes" id="kubernetes-radio" />
</Field>
</FieldLabel>
<FieldLabel @for="vm-radio">
<Field @orientation="horizontal">
<FieldContent>
<FieldTitle>Virtual Machine</FieldTitle>
<FieldDescription>
Access a VM configured cluster to run GPU workloads.
</FieldDescription>
</FieldContent>
<RadioGroupItem @value="vm" id="vm-radio" />
</Field>
</FieldLabel>
</RadioGroup>
</FieldSet>
</FieldGroup>
</div>
</template>Field Group
Stack
Field
components with
FieldGroup
. Add
FieldSeparator
to divide them.
import { Checkbox } from '@/components/ui/checkbox';
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
FieldSeparator,
FieldSet,
} from '@/components/ui/field';
<template>
<div class="w-full max-w-md">
<FieldGroup>
<FieldSet>
<FieldLabel>Responses</FieldLabel>
<FieldDescription>
Get notified when ChatGPT responds to requests that take time, like
research or image generation.
</FieldDescription>
<FieldGroup data-slot="checkbox-group">
<Field @orientation="horizontal">
<Checkbox @checked={{true}} @disabled={{true}} id="push" />
<FieldLabel @class="font-normal" @for="push">
Push notifications
</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>
<FieldSeparator />
<FieldSet>
<FieldLabel>Tasks</FieldLabel>
<FieldDescription>
Get notified when tasks you've created have updates.
<a href="#">Manage tasks</a>
</FieldDescription>
<FieldGroup data-slot="checkbox-group">
<Field @orientation="horizontal">
<Checkbox id="push-tasks" />
<FieldLabel @class="font-normal" @for="push-tasks">
Push notifications
</FieldLabel>
</Field>
<Field @orientation="horizontal">
<Checkbox id="email-tasks" />
<FieldLabel @class="font-normal" @for="email-tasks">
Email notifications
</FieldLabel>
</Field>
</FieldGroup>
</FieldSet>
</FieldGroup>
</div>
</template>Responsive Layout
- Vertical fields: Default orientation stacks label, control, and helper text—ideal for mobile-first layouts.
-
Horizontal fields:
Set
@orientation="horizontal"onFieldto align the label and control side-by-side. Pair withFieldContentto keep descriptions aligned. -
Responsive fields:
Set
@orientation="responsive"for automatic column layouts inside container-aware parents. Apply@container/field-groupclasses onFieldGroupto switch orientations at specific breakpoints.
import { on } from '@ember/modifier';
import { Button } from '@/components/ui/button';
import {
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSeparator,
FieldSet,
} from '@/components/ui/field';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
const handleSubmit = (event: Event) => {
event.preventDefault();
};
<template>
<div class="w-full max-w-4xl">
<form {{on "submit" handleSubmit}}>
<FieldSet>
<FieldLegend>Profile</FieldLegend>
<FieldDescription>Fill in your profile information.</FieldDescription>
<FieldSeparator />
<FieldGroup>
<Field @orientation="responsive">
<FieldContent>
<FieldLabel @for="name">Name</FieldLabel>
<FieldDescription>
Provide your full name for identification
</FieldDescription>
</FieldContent>
<Input id="name" placeholder="Evil Rabbit" required />
</Field>
<FieldSeparator />
<Field @orientation="responsive">
<FieldContent>
<FieldLabel @for="lastName">Message</FieldLabel>
<FieldDescription>
You can write your message here. Keep it short, preferably under
100 characters.
</FieldDescription>
</FieldContent>
<Textarea
@class="min-h-[100px] resize-none sm:min-w-[300px]"
id="message"
placeholder="Hello, world!"
required
/>
</Field>
<FieldSeparator />
<Field @orientation="responsive">
<Button type="submit">Submit</Button>
<Button @variant="outline" type="button">
Cancel
</Button>
</Field>
</FieldGroup>
</FieldSet>
</form>
</div>
</template>Validation and Errors
-
Add
data-invalidtoFieldto switch the entire block into an error state. -
Add
aria-invalidon the input itself for assistive technologies. -
Render
FieldErrorimmediately after the control or insideFieldContentto keep error messages aligned with the field.
<Field data-invalid>
<FieldLabel @for="email">Email</FieldLabel>
<Input id="email" type="email" aria-invalid />
<FieldError>Enter a valid email address.</FieldError>
</Field>Accessibility
-
FieldSetandFieldLegendkeep related controls grouped for keyboard and assistive tech users. -
Fieldoutputsrole="group"so nested controls inherit labeling fromFieldLabelandFieldLegendwhen combined. -
Apply
FieldSeparatorsparingly to ensure screen readers encounter clear section boundaries.
API Reference
FieldSet
Container that renders a semantic
fieldset
with spacing presets.
<FieldSet>
<FieldLegend>Delivery</FieldLegend>
<FieldGroup>{{! Fields }}</FieldGroup>
</FieldSet>FieldLegend
Legend element for a
FieldSet
. Switch to the
label
variant to align with label sizing.
<FieldLegend @variant="label">Notification Preferences</FieldLegend>
The
FieldLegend
has two variants:
legend
and
label
. The
label
variant applies label sizing and alignment. Handy if you have nested
FieldSet
.
FieldGroup
Layout wrapper that stacks
Field
components and enables container queries for responsive orientations.
<FieldGroup @class="@container/field-group flex flex-col gap-6">
<Field>{{! ... }}</Field>
<Field>{{! ... }}</Field>
</FieldGroup>Field
The core wrapper for a single field. Provides orientation control, invalid state styling, and spacing.
<Field @orientation="horizontal">
<FieldLabel @for="remember">Remember me</FieldLabel>
<Switch id="remember" />
</Field>FieldContent
Flex column that groups control and descriptions when the label sits beside the control. Not required if you have no description.
<Field>
<Checkbox id="notifications" />
<FieldContent>
<FieldLabel @for="notifications">Notifications</FieldLabel>
<FieldDescription>Email, SMS, and push options.</FieldDescription>
</FieldContent>
</Field>FieldLabel
Label styled for both direct inputs and nested
Field
children.
<FieldLabel @for="email">Email</FieldLabel>FieldTitle
Renders a title with label styling inside
FieldContent
.
<FieldContent>
<FieldTitle>Enable Touch ID</FieldTitle>
<FieldDescription>Unlock your device faster.</FieldDescription>
</FieldContent>FieldDescription
Helper text slot that automatically balances long lines in horizontal layouts.
<FieldDescription>We never share your email with anyone.</FieldDescription>FieldSeparator
Visual divider to separate sections inside a
FieldGroup
. Accepts optional inline content.
<FieldSeparator>Or continue with</FieldSeparator>FieldError
Accessible error container that accepts children or an
@errors
array (e.g., from form validation).
<FieldError @errors={{@errors.username}} />
When the
@errors
array contains multiple messages, the component renders a list automatically.
FieldError
also accepts issues produced by any validator that implements
Standard Schema
, including Zod, Valibot, and ArkType. Pass the
issues
array from the schema result directly to render a unified error list across libraries.