Field
Combine labels, controls, and help text to compose accessible form fields and grouped inputs.
Source code
Click to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.
Installation
npx ui-thing@latest add field
Usage
<template>
<UiFieldSet>
<UiFieldLegend>Profile</UiFieldLegend>
<UiFieldDescription>This appears on invoices and emails.</UiFieldDescription>
<UiFieldGroup>
<UiField>
<UiFieldLabel for="name">Full name</UiFieldLabel>
<UiInput id="name" autoComplete="off" placeholder="Tinker Bell" />
<UiFieldDescription>This appears on invoices and emails.</UiFieldDescription>
</UiField>
<UiField>
<UiFieldLabel for="username">Username</UiFieldLabel>
<UiInput id="username" autoComplete="off" aria-invalid />
<UiFieldError>Choose another username.</UiFieldError>
</UiField>
<UiField orientation="horizontal">
<UiSwitch id="newsletter" />
<UiFieldLabel for="newsletter">Subscribe to the newsletter</UiFieldLabel>
</UiField>
</UiFieldGroup>
</UiFieldSet>
</template>
Anatomy
The Field
family is designed for composing accessible forms. A typical field is structured as follows:
<template>
<UiField>
<UiFieldLabel for="input-id">Label</UiFieldLabel>
<!-- Input, Select, Switch, etc. -->
<UiFieldDescription>Optional helper text.</UiFieldDescription>
<UiFieldError>Validation message.</UiFieldError>
</UiField>
</template>
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 useFieldSet
withFieldLegend
for semantic grouping.
Examples
Basic
Input
Textarea
Select
Select your department or area of work.
Slider
Set your budget range ($ 200 - 800).
FieldSet
Checkbox
Your Desktop & Documents folders are being synced with iCloud Drive. You can access them from other devices.
Radio
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.
Choice Card
Wrap Field
components inside FieldLabel
to create selectable field groups. This works with RadioItem
, Checkbox
and Switch
components.
Field Group
Stack Field
components with FieldGroup
. Add FieldSeparator
to divide them.
Responsive Layout
- Vertical fields: Default orientation stacks label, control, and helper text—ideal for mobile-first layouts.
- Horizontal fields: Set
orientation="horizontal"
onField
to align the label and control side-by-side. Pair withFieldContent
to keep descriptions aligned. - Responsive fields: Set
orientation="responsive"
for automatic column layouts inside container-aware parents. Apply@container/field-group
classes onFieldGroup
to switch orientations at specific breakpoints.
Validation and Errors
- Add
data-invalid
toField
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 insideFieldContent
to keep error messages aligned with the field.
<template>
<UiField data-invalid>
<UiFieldLabel for="email">Email</UiFieldLabel>
<UiInput id="email" type="email" aria-invalid />
<UiFieldError>Enter a valid email address.</UiFieldError>
</UiField>
</template>
Accessibility
FieldSet
andFieldLegend
keep related controls grouped for keyboard and assistive tech users.Field
outputsrole="group"
so nested controls inherit labeling fromFieldLabel
andFieldLegend
when combined.- Apply
FieldSeparator
sparingly to ensure screen readers encounter clear section boundaries.