Field
The React Field component helps you build form fields with labels, inputs, helper text, and error messages. It keeps everything connected and structured in one place.
It makes forms easier to build and more accessible by linking labels, descriptions, and errors to the input. For example, a field can show a label, helper text, and an error message for an email input.
Built with React Aria and styled using Tailwind CSS. It supports accessibility, proper form structure, and flexible layouts using simple sub-components.
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli add fieldAnatomy
Import the sub-components you need and compose them together.
import {
FieldSet,
FieldLegend,
FieldGroup,
Field,
FieldContent,
FieldLabel,
FieldTitle,
FieldDescription,
FieldError,
FieldSeparator,
ComposedField
} from "@/registry/core/Field";
export const FieldAnatomy = () => (
<FieldSet>
<FieldLegend>Group Title</FieldLegend>
<FieldGroup>
<Field>
<FieldLabel htmlFor="input-id">Label</FieldLabel>
{/* Input, Select, Textarea, etc. */}
<FieldDescription>Optional helper text.</FieldDescription>
<FieldError>Validation message.</FieldError>
</Field>
<FieldSeparator />
<Field orientation="horizontal">
<FieldContent>
<FieldTitle>Title</FieldTitle>
<FieldDescription>Helper text.</FieldDescription>
</FieldContent>
{/* Input, Select, Textarea, etc. */}
</Field>
<ComposedField
label="Label"
description="Helper text"
errorMessage="Error message"
isInvalid
>
{/* Input, Select, Textarea, etc. */}
</ComposedField>
</FieldGroup>
</FieldSet>
);Fieldis the core wrapper for a single field. Supportsvertical,horizontal, andresponsiveorientations.FieldContentgroups a label and description side by side with the control — useful in horizontal layouts.FieldGroupstacks multipleFieldcomponents with consistent spacing.FieldSetwithFieldLegendprovides semantic<fieldset>grouping.ComposedFielduses React Aria'suseFieldhook to automatically wire up ARIA attributes.
Examples
Input
Compose a Field with an Input to create a labeled text field with optional description and error state.
Textarea
The same composition pattern works with any form control, including TextArea.
Horizontal
Use orientation="horizontal" to place the label and control side by side. Wrap the label and description in FieldContent for proper alignment.
Fieldset
Use FieldSet, FieldLegend, and FieldGroup to semantically group related fields. Add FieldSeparator to visually divide sections.
Composed Field
The ComposedField component uses React Aria's useField hook under the hood to automatically generate IDs, associate labels with inputs via aria-labelledby, and link descriptions and errors with aria-describedby.
API Reference
FieldSet
Container that renders a semantic <fieldset> with spacing presets.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the fieldset |
FieldLegend
Legend element for a FieldSet. Use the label variant to match label sizing in nested fieldsets.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'legend' | 'label' | 'legend' | Controls the text styling — legend is larger, label matches label size |
className | string | - | Additional CSS classes |
FieldGroup
Layout wrapper that stacks Field components with consistent spacing. Enables container queries for responsive orientations.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the container |
Field
The core wrapper for a single field. Controls layout orientation and invalid state.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'responsive' | 'vertical' | Flex direction of the field |
data-invalid | boolean | - | Marks the field as invalid for styling |
className | string | - | Additional CSS classes |
FieldContent
Flex column that groups elements like label and description. Useful when the label sits beside the control in horizontal layouts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
FieldLabel
Styled label element for form controls.
| Prop | Type | Default | Description |
|---|---|---|---|
htmlFor | string | - | The id of the form control this label is for |
asChild | boolean | false | When true, renders only children without a <label> wrapper |
className | string | - | Additional CSS classes |
FieldTitle
Renders a title with label styling inside FieldContent. Useful for non-interactive labels.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
FieldDescription
Helper text slot for providing context about a form field.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
FieldError
Validation message slot, styled with error color.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
FieldSeparator
Visual divider to separate sections inside a FieldGroup. Accepts optional inline content.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Optional text content shown centered within the line |
className | string | - | Additional CSS classes |
ComposedField
Fully composed field wrapper using React Aria's useField hook. Automatically handles aria-labelledby, aria-describedby, and ID generation.
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | - | Label text for the field |
description | ReactNode | - | Helper text displayed below the control |
errorMessage | ReactNode | - | Error message displayed when isInvalid is true |
isInvalid | boolean | - | Marks the field as invalid and shows the error message |
orientation | 'vertical' | 'horizontal' | 'responsive' | 'vertical' | Flex direction of the field |
children | ReactNode | Required | The form control element (Input, TextArea, Select, etc.) |
className | string | - | Additional CSS classes |
Accessibility
- Label association: FieldLabel connects to form controls using
htmlFor, so clicking the label focuses the input. - ARIA linking:
ComposedFieldautomatically links the label, description, and error message to the input usingARIAattributes. - Error messages:
FieldErrordisplays validation messages and connects them to the input so screen readers can announce them. - Descriptions:
FieldDescriptionprovides helper text that gives additional context to users. - Semantic grouping: Use
FieldSetandFieldLegendto group related fields using native<fieldset>and<legend>elements.
