Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Field for Astro

Astro field layouts that connect labels, controls, descriptions, and errors.

Profile

Enter your profile information below.

This appears on invoices and emails.

Installation

bunx --bun shadcn@latest add @gnostic/field

Usage

import {
    Field,
    FieldContent,
    FieldDescription,
    FieldGroup,
    FieldLabel,
    FieldLegend,
    FieldSeparator,
    FieldSet,
    FieldTitle,
} from "@/components/ui/field"
<FieldSet>
  <FieldLegend>Profile</FieldLegend>
  <FieldGroup>
    <Field>
      <FieldLabel for="name">Full name</FieldLabel>
      <Input id="name" placeholder="Morgan Reed" />
      <FieldDescription>Optional helper text.</FieldDescription>
    </Field>
  </FieldGroup>
</FieldSet>

Composition

Use the following composition for a single field with a label, control, helper text, and validation:

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

Use FieldGroup to group related fields. Add FieldSeparator between sections when needed.

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

Use FieldSet and FieldLegend for semantic grouping:

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 for="input-id">Label</FieldLabel>
  <!-- Input, Select, Checkbox, etc. -->
  <FieldDescription>Optional helper text.</FieldDescription>
</Field>
  • Put one control and its label in a Field.
  • Add FieldContent when the label needs a supporting description.
  • Use FieldGroup to arrange several fields. Use FieldSet and FieldLegend when those fields form a named group.

Examples

Use the address where you want to receive project updates.

Write a short bio about yourself.

Select your country of residence.

Personal Information

Enter your personal details below.

Include the current review notes with your project summary.

Notifications

Choose how you want to be notified.

Field Group

Place each field inside FieldGroup. A FieldSeparator can mark a change between sets of related inputs.

Your primary email address.

Or

Your phone number for SMS updates.

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.

Help improve the app by sharing anonymous usage data.

Receive emails about new products and features.

Validation

Add data-invalid="true" to Field to switch the entire block into an error state, and add aria-invalid="true" on the input itself for assistive technologies.

Enter a valid email address.

This email will be used for account notifications.

API Reference

Field

The root component for the Field family.

FieldProps

PropType
orientation?"vertical" | "horizontal" | "responsive" | null | undefined
Type"vertical" | "horizontal" | "responsive" | null | undefined

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.

When to use Field

Use Field to keep a label, control, help text, and error together. Match label for to the control ID and connect description and error IDs with aria-describedby. FieldSet and FieldLegend group related controls using native fieldset markup.

Keyboard and behavior

These parts arrange form content; they do not run Base UI validation. Native constraints and your server or client validation determine the error. Set aria-invalid on the control and show an error that tells the user how to correct the value.

Theme and layout

Use the existing orientation variants to place labels beside or above controls. Check long help text in narrow columns. Shared error and muted-text tokens keep the state consistent with Input and Textarea.