Field New Alpha Light DOM & Tailwind

Open in Storybook

A composable wrapper for laying out a form control with a label, helper text, and error message.

OverviewUsageCompositionExamplesAccessibilityAPI referencePartsDesign guidelines
This component is considered alpha. We're still finalising the API, so it may include a breaking change at any time — use it at your own risk.
Loading...

Usage

Field is a composable wrapper for a single form control. Combine it with its parts to lay out a control with a label, helper text and an error message, and group related fields together under a legend.

Import the parts you need — each import registers its custom element:

Copy code
import "@nordhealth/components/lib/Field"
import "@nordhealth/components/lib/FieldContent"
import "@nordhealth/components/lib/FieldDescription"
import "@nordhealth/components/lib/FieldError"
import "@nordhealth/components/lib/FieldGroup"
import "@nordhealth/components/lib/FieldLabel"
import "@nordhealth/components/lib/FieldLegend"
import "@nordhealth/components/lib/FieldSeparator"
import "@nordhealth/components/lib/FieldSet"
import "@nordhealth/components/lib/FieldTitle"

Then compose them around your controls:

Composition

The Field family is designed for composing accessible forms. A typical field pairs a Field Label with a control, and optionally a description and an error.

Copy code
Field
├── FieldLabel
├── Control (Input / Select / Toggle / …)
├── FieldDescription   (optional)
└── FieldError         (optional)
Copy code
<nord-field>
  <nord-field-label for="input-id">Label</nord-field-label>
  <!-- input, select, toggle, etc. -->
  <nord-field-description>Optional helper text.</nord-field-description>
  <nord-field-error>Validation message.</nord-field-error>
</nord-field>

Field

Field is the core wrapper for a single control. Its orientation attribute controls the layout:

  • vertical (default) stacks the label, control and helper text.
  • horizontal places the label and control side by side, vertically centered.
  • responsive is vertical on narrow containers and horizontal once the surrounding Field Group is wide enough.

Use Field Content to keep a label and description aligned in horizontal and choice-card layouts, and Field Title for an emphasized inline title.

Field Group

Field Group stacks several fields with consistent spacing. Add a Field Separator between sections where a visual divider helps.

Copy code
FieldGroup
├── Field
├── FieldSeparator   (optional)
└── Field

Field Set

Wrap a Field Group in a Field Set with a Field Legend to group related fields under a labelled, accessible section. Field Set exposes role="group" named by its legend, and an optional Field Description gives the group a hint.

Field Set is the composable successor to the deprecated Fieldset; reach for it in new code, and migrate existing nord-fieldset usage when convenient.

Copy code
FieldSet                  (role="group", labelled by the legend)
├── FieldLegend
├── FieldDescription      (optional)
└── FieldGroup
    ├── Field
    │   ├── FieldLabel
    │   ├── Control
    │   ├── FieldDescription
    │   └── FieldError
    └── Field
        ├── FieldLabel
        └── Control

Forms

Nord form controls participate in forms natively, so a control inside a Field submits its value like any other form control — Field only handles layout and labelling, it doesn't change form behaviour.

Validation

Field is validation-presentational: you decide when a field is invalid (Field does not run constraint validation itself) and reflect it by setting invalid on the nord-field and rendering a Field Error. From there Field wires up the accessibility for you:

  • invalid propagates to the control. Setting invalid on the nord-field marks the wrapped control invalid too — driving the control's own invalid state (and its inner aria-invalid) for Nord controls, or setting aria-invalid directly on a native/third-party control. You don't need to set invalid in two places; setting it back to false clears it on the control again. (A control you mark invalid on its own is left untouched.)
  • The error and description are announced. Field points the control's aria-describedby at any Field Description and Field Error, so assistive technology reads them out when the control is focused. Field Error is a polite live region, so a newly added message is announced.
Copy code
<nord-field invalid>
  <nord-field-label for="email">Email</nord-field-label>
  <nord-input id="email" type="email" value="not-an-email"></nord-input>
  <nord-field-error>Enter a valid email address.</nord-field-error>
</nord-field>

API reference

Field

Field is the wrapper for a single form control. It lays out a Field Label, a control (such as an Input), an optional Field Description and a Field Error with consistent spacing. Combine several together in a Field Group and group related groups with a Field Set. The Field shares its state with the control through context: a Nord control placed inside a Field suppresses its own built-in label/hint/error and takes its accessible name, description and invalid/disabled state from the Field.

<nord-field></nord-field>

Props

PropertyAttribute Description TypeDefault
orientationorientationThe layout of the field. - vertical (default) stacks the label, control and helper text. - horizontal places the label and control side by side, vertically centered. - responsive lays out horizontally in a wide enough container, otherwise vertical.'vertical' | 'horizontal' | 'responsive''vertical'
invalidinvalidMarks the field as invalid, enabling error styling hooks. Also reflected as data-invalid and propagated to the control via context.booleanfalse
disableddisabledDisables the field and, via context, its control. Reflected as data-disabled.booleanfalse

Slots

Slot name Description
Default slotDefault slot for the field parts (label, control, content, description, error).

CSS Properties

CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.

PropertyDescriptionDefault
--n-field-gapControls the spacing between the field parts, using our spacing tokens.var(--n-space-s)

State attributes

These data-* attributes are set by the component to reflect its current state. Use them as styling hooks — they are read-only and should not be set manually.

AttributeDescription
data-invalidPresent while the field is invalid (mirrors the invalid property). Style hook for the whole field.
data-disabledPresent while the field is disabled (mirrors the disabled property).
data-focusedPresent while the field's control has focus. Style hook for focus-within treatments across the field.
Light DOM & Tailwind. This component renders in the light DOM, so you can style it directly with your own CSS or Tailwind utility classes — there is no shadow boundary, and its default styles are low specificity, so your utilities win.

Parts

This component is made up of the following parts.

Field Content

Field Content wraps a Field Label and Field Description so they stay aligned as a single text block, which is especially useful in horizontal Field layouts.

<nord-field-content></nord-field-content>

Slots

Slot name Description
Default slotDefault slot for the label and description.

Field Description

Field Description is the helper or hint text for a Field. It is styled to match the hint text used by Nord form controls such as Input.

<nord-field-description></nord-field-description>

Slots

Slot name Description
Default slotDefault slot for the description text.

Field Error

Field Error displays validation error text for a Field. It is styled to match the error text used by Nord form controls such as Input. Exposes itself as a live region (role="alert", aria-live="polite") so the message is announced when it appears. The message is supplied as the element's children.

<nord-field-error></nord-field-error>

Slots

Slot name Description
Default slotDefault slot for the error message(s).

Field Group

Field Group stacks a set of Field controls vertically with consistent spacing. Separate sections with a Field Separator when needed.

<nord-field-group></nord-field-group>

Slots

Slot name Description
Default slotDefault slot for Field and Field Separator elements.

CSS Properties

CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.

PropertyDescriptionDefault
--n-field-group-gapControls the spacing between fields, using our spacing tokens.var(--n-space-l)

Field Label

Field Label is the label for a control inside a Field. It is styled to match the labels used by Nord form controls such as Input. The enclosing Field shares this label's id and text with the control through context, so the control names itself (aria-labelledby for light-DOM controls, aria-label for shadow-DOM ones) — no wiring needed. Set the for attribute to a control's id to additionally get native-style click-to-focus. The required indicator is driven by the control: mark the control required and the Field toggles this label's required attribute automatically.

<nord-field-label></nord-field-label>

Props

PropertyAttribute Description TypeDefault
forforThe id of the control this label describes. Enables native-style click-to-focus, mirroring the native <label for> attribute.string | undefined

Slots

Slot name Description
Default slotDefault slot for the label text.

Field Legend

Field Legend labels a Field Set, naming the group of fields for assistive technology. Place it as the first child of a Field Set.

<nord-field-legend></nord-field-legend>

Slots

Slot name Description
Default slotDefault slot for the legend text.

Field Separator

Field Separator draws a thin divider between sections inside a Field Group.

<nord-field-separator></nord-field-separator>

Field Set

Field Set groups related fields under a Field Legend for semantic, accessible grouping. It exposes role="group" named by its legend; wrap a Field Group inside.

<nord-field-set></nord-field-set>

Props

PropertyAttribute Description TypeDefault
disableddisabledDisables every field in the set. Each enclosed Field reads this and cascades it to its control.booleanfalse

Slots

Slot name Description
Default slotDefault slot for a Field Legend and a Field Group.

Field Title

Field Title is an emphasized inline title used inside choice-card style Field layouts, where a Field Label wraps a whole selectable field.

<nord-field-title></nord-field-title>

Slots

Slot name Description
Default slotDefault slot for the title text.
Design guidelinesFor designers

Usage

This section includes guidelines for designers and developers about the usage of this component in different contexts.

Do

  • Connect each Field Label to its control with the for attribute so clicking the label focuses the control and the control gets an accessible name.
  • Wrap related fields in a Field Set with a Field Legend to group them under a legend.
  • Mark a Field as invalid when showing a Field Error so the error styling and announcement stay in sync.

Don’t

  • Don’t omit the for attribute on a Field Label, as the control would then lack an accessible name.
  • Don’t put more than one control in a single Field; use a Field Group for multiple fields.
  • Don’t reach for a Field around a Nord control that already has its own label, hint and error unless you need the extra composition.

Was this page helpful?

Yes No

We use this feedback to improve our documentation.