Field
nswds-ui/fieldFreeComponent
Form field layout primitives — set, group, label, description, error, and separator slots.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/digitalnsw/nswds-ui/main/apps/registry/public/r/field.jsonSource
1'use client'23import { Field as FieldPrimitive } from '@base-ui/react/field'4import { cva, type VariantProps } from 'class-variance-authority'5import * as React from 'react'67import { Label } from '@/components/label'8import { Separator } from '@/components/separator'9import { cn } from '@/lib/utils'1011// ─────────────────────────────────────────────────────────────────────────────12// Base UI Field13// ─────────────────────────────────────────────────────────────────────────────14//15// `Field`, `FieldLabel`, `FieldDescription`, and `FieldError` wrap Base UI's16// Field primitive (@base-ui/react/field). Base UI owns the accessible wiring:17// the label is associated with the control, and any description/error ids are18// added to the control's `aria-describedby` automatically — no manual19// `htmlFor` / `aria-describedby` / `aria-invalid` plumbing required. Set20// `invalid` on `Field` (e.g. from react-hook-form) and the control receives21// `aria-invalid` and the wrapper gets `data-invalid` for free.22//23// Base UI's Field parts must live inside a `Field.Root`. To keep the previous24// behaviour where a label/description/error could also be used standalone25// (e.g. a group-level FieldDescription directly inside a FieldSet), FieldLabel/26// FieldDescription/FieldError opt into the Base UI part only when they detect a27// surrounding `Field` (via `InsideFieldContext`) and otherwise render the plain28// element they did before. Inside a Field they gain the automatic association;29// outside one they are unchanged.30//31// `FieldSet` / `FieldLegend` stay native `<fieldset>` / `<legend>` (already32// accessible for grouping); `FieldGroup` / `FieldContent` / `FieldSeparator` /33// `FieldTitle` remain layout-only primitives.34//35// ─────────────────────────────────────────────────────────────────────────────36// Typography hierarchy (deliberate, do not collapse to a single size)37// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from @nswds/ui
All 46 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aspect Ratioaspect-ratio | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Badgebadge | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Buttonbutton | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Cardcard | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Collapsiblecollapsible | @nswds/ui | Components | Free | 1 dep | |
| Drawerdrawer | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Expandable Searchexpandable-search | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Footerfooter | @nswds/ui | Components | Free | 3 deps · 2 files |
