Components / Field
Field
Compose controls with visible labels, connected help and errors, and named groups. Square, monospaced parts keep native semantics and adapt to the space available.
Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.
Usage playground
Edit a composed email field, change its layout, or show an explicit error. Responsive layout follows the containing FieldGroup, not the viewport. Error preview does not validate the value.
We send only account updates.
'use client';
import { useId, useState } from 'react';
import { Field, FieldGroup, FieldContent, FieldLabel, FieldDescription, FieldError } from '@/components/ui/yads-field';
import { Input } from '@/components/ui/yads-input';
Installation
pnpm dlx [email protected] add biehlio/yet-another-design-system/field#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40In a shadcn-configured project this installs yads-field, its scoped CSS and JetBrains Mono automatically. No Tailwind, reset, global stylesheet, provider or form library is needed. Light is the default; a containing .dark class selects dark colors.
Field has no control dependencies and does not wrap or modify Input. Install the separate controls used by each copied example: input for email and customization; also textarea, checkbox and button for the form. Use the same command, replacing field before the revision hash with the companion name. Copy sample always includes a complete module and any recipe CSS, even when collapsed; interactive modules include a client boundary. Example layouts also work without Tailwind.
Helper text and errors
FieldError presents your message; it does not validate or connect itself. This controlled example starts invalid and uses native email validity while typing. Keep help attached when the error clears.
We only use this to reply to your message.
Enter a valid email address.
'use client';
import { useId, useState } from 'react';
import { Field, FieldLabel, FieldDescription, FieldError } from '@/components/ui/yads-field';
import { Input } from '@/components/ui/yads-input';
Fieldsets and native forms
A native fieldset and legend name each related group. Responsive fields stack below 32rem of group width; a horizontal checkbox keeps its label beside it. Submit uses FormData and native required validation, and reset restores uncontrolled defaults. Nothing is sent to a server.
'use client';
import { useId, useState } from 'react';
import { Field, FieldGroup, FieldContent, FieldSet, FieldLegend, FieldLabel, FieldDescription, FieldSeparator } from '@/components/ui/yads-field';
import { Input } from '@/components/ui/yads-input';
import { Textarea } from '@/components/ui/yads-textarea';
className customization
Use ordinary scoped recipe CSS or inline styles on any part. This complete recipe changes spacing and label decoration, without replacing control focus rings or error colors.
Use a name your team recognizes.
'use client';
import { useId } from 'react';
import { Field, FieldGroup, FieldLabel, FieldDescription } from '@/components/ui/yads-field';
import { Input } from '@/components/ui/yads-input';
Accessibility
- Associate the actual control. Use unique IDs (React useId for repeated instances), FieldLabel htmlFor, and control aria-describedby referencing existing help and error IDs. These wrappers never clone children or inject ARIA. A placeholder is not a label.
- Name related groups. FieldSet with its first child FieldLegend supplies native fieldset semantics. FieldGroup and Field are layout divs, not automatic groups. Each control still needs a label. Connect group-level help with aria-describedby on FieldSet.
- Explain errors in text. Your application decides validation and announcement timing. Set aria-invalid on the control, conditionally render FieldError, and include its ID in aria-describedby while present. Optional data-invalid on Field is visual only. Neither property blocks submission; native required/type constraints do.
- Preserve native interactions. Tab order follows DOM order, never visual reordering. Labels activate controls; Space toggles a checkbox; Enter submits a valid form. Disabled fieldsets disable descendants and omit their values. Read-only input remains focusable and submitted. Field adds no keyboard handlers or focus ring; controls keep their own.
- Keep layouts readable. Vertical is the default. Horizontal stays a row, suitable for checkbox and label. Responsive stacks until the nearest FieldGroup is at least 32rem wide; pair a direct FieldLabel with FieldContent. Without container-query support it remains vertical.
API reference
Import parts and their named prop types from @/components/ui/yads-field. All parts forward their ref to the native element below; native attributes, ARIA, data attributes and events pass through. className is appended to scoped styles; style passes through unchanged. No IDs, values, labels or validation state are managed. No asChild or form-framework API is provided.
On narrow screens, focus the table and scroll horizontally to read all columns.
| Part | Element / ref | Props | Behavior |
|---|---|---|---|
Field | div / HTMLDivElement | FieldProps: HTMLAttributes<HTMLDivElement> + orientation | orientation: vertical (default), horizontal, responsive. Layout only; no implicit role or associations. data-invalid="true" colors its direct label, not the control. |
FieldGroup | div / HTMLDivElement | FieldGroupProps: HTMLAttributes<HTMLDivElement> | Vertical spacing and named inline-size container. Put responsive Fields inside a FieldGroup. Not a semantic group. |
FieldContent | div / HTMLDivElement | FieldContentProps: HTMLAttributes<HTMLDivElement> | Flexible column for a control, description and error. Use with responsive rows. |
FieldSet | fieldset / HTMLFieldSetElement | FieldSetProps: FieldsetHTMLAttributes<HTMLFieldSetElement> | Native grouping; disabled, name and form pass through. Put FieldLegend first. disabled excludes descendant controls from submission (except the native first-legend exception). |
FieldLegend | legend / HTMLLegendElement | FieldLegendProps: HTMLAttributes<HTMLLegendElement> | Native accessible name for the containing fieldset. Not a replacement for individual labels. |
FieldLabel | label / HTMLLabelElement | FieldLabelProps: LabelHTMLAttributes<HTMLLabelElement> | Explicit htmlFor must match the actual control id. No IDs or required markers are generated. |
FieldDescription | p / HTMLParagraphElement | FieldDescriptionProps: HTMLAttributes<HTMLParagraphElement> | Supporting text. Give it an id and reference it from the control or fieldset aria-describedby. |
FieldError | p / HTMLParagraphElement | FieldErrorProps: HTMLAttributes<HTMLParagraphElement> | Error text, hidden when empty. No validation, automatic announcement, error array parsing or focus movement. Supply children, id and optional aria-live. |
FieldSeparator | hr / HTMLHRElement | FieldSeparatorProps: HTMLAttributes<HTMLHRElement> | Native horizontal separator between groups. No children; use aria-hidden if purely decorative. |
Composition and defaults
Field renders a vertical div by default. Other parts add no attribute defaults; native defaults apply. Use FieldContent for help/error placement beside a label in horizontal or responsive layouts. FieldDescription and FieldError render paragraphs, so use phrasing content rather than nested paragraphs. FieldLegend belongs directly inside FieldSet. FieldSeparator is a void element.
Reset playground restores vertical layout, “[email protected]” and no error. The error toggle is a documentation control, not a Field prop. Input remains separately installable and independently usable. Field does not style arbitrary descendant controls or require a theme provider.