Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

Field

Fields wrap a single form control with label, description, and error messaging in a consistent layout.

Try it

We will never share your email.

Usage

The name and the disabled state live on the control: write name (and disabled) on the control, inside a field or outside one. The field only reads the control's name and registers it with RuiForm under it, and it uses the name as the key for errors and rules. Place a Radiant control (RuiInput, RuiSelect, RuiSwitch, …) as the child; Field discovers controls via data-rui-control and known host tags, not bare <input> elements. Use RuiFieldDescription and RuiFieldError for helper and error text.

import { RuiField, RuiFieldDescription, RuiFieldError } from '@ecopages/radiant-ui/field';
import { RuiLabel } from '@ecopages/radiant-ui/label';
import { RuiInput } from '@ecopages/radiant-ui/input';

<RuiField invalid={!!errors.email} error={errors.email?.message}>
  <RuiLabel>Email</RuiLabel>
  <RuiInput name="email" type="email" placeholder="you@example.com" />
  <RuiFieldDescription>We will never share your email.</RuiFieldDescription>
  <RuiFieldError />
</RuiField>

Custom markup

<rui-field> coordinates any light-DOM tree that matches its query contract. The RuiField helper stamps [data-ref="field"]; it is not required.

import '@ecopages/radiant-ui/field';
import '@ecopages/radiant-ui/input';

<rui-field>
  <div class="rui-field" data-ref="field">
    <label class="rui-label" data-rui-field-label>Email</label>
    <input name="email" type="email" data-rui-control class="rui-input" />
    <p data-rui-field-description class="rui-field__description">We will never share your email.</p>
    <p data-rui-field-error class="rui-field__error" role="alert" hidden></p>
  </div>
</rui-field>

The field wires aria-describedby, aria-invalid, and error text on the control. Use a library control host or [data-rui-control] — bare native inputs without the marker are ignored.

Set name on the control so it can submit natively and the field can register it. Checkbox and radio groups supply their name to their members. Number Field submits through its native number input. Date Field copies name to its nested Date Input. Date Range Picker uses start-name and end-name on its two nested Date Inputs and registers under its own name. Select, Combobox, standalone Listbox and standalone Tag Group submit one entry per selected value.

A control with no name is not registered, so it is never validated or written to the form. Inside a rui-form the field warns about it once, in development.

A control that is renamed after the field connected moves to its new name at once: the field watches the control's name attribute, and nothing else, and the form moves the registration with its value, validity and rules to the new path before anything else reads it. A host whose name is a property must reflect it to the attribute; every Radiant control host does. A control that lost its name is released, and registered again when it gets one. For a control host that changes its name without touching the attribute, the form still resolves the name at submission, in focusField, and on the next event from the control or focus leaving it. A field reports one focus to its store when focus comes into its control from outside it, and one blur when focus leaves it: moving between the parts of the same control, or into the portaled popup of a rui-select, rui-combobox or rui-date-range-picker it owns and back, keeps the same visit. The blur of the field focus left is reported before the focus of the next, and a blur is reported only while the store's getFocusedPath() still names the field, so a visit a reset or a row removal ended gets none. A field removed from the document mid-visit tells the form it was left, and a window or tab losing focus is not a leave. Focus the form moves itself (focusField) is reported with the source program, and a field that already holds focus when it registers opens its visit then.

Text a visitor typed into server-rendered markup before the scripts loaded wins over the store. When the field registers its control, it compares the control's native state with what its markup declared: value with defaultValue for a text input or textarea, checked with defaultChecked for a checkbox or radio, and the options' selected with defaultSelected for a select. A control that differs was edited, so the form publishes its value to the store as a user change (the field turns dirty and validates as mode says) instead of writing the store's value into it. A control the visitor did not edit is seeded from the store as before, and so is one that appears after hydration with its server default. The rule is the same for the form's own store and an injected one. A host that is not form-associated is read through the native inputs, selects and textareas it owns (those inside it that no host between them keeps for itself) and marks with data-rui-control, whatever events it reports its value with, plus every native input of a host whose adapter declares events: 'members' (Checkbox, Switch, Radio Group, Checkbox Group, Number Field). A custom host registered with registerFieldControl that wraps a native input marks that input (a RuiInput already does), and text typed into it before the host upgraded wins over the store the same way. A form-associated host (FormAssociatedElement: Select, Combobox, Listbox, Tag Group, Slider, Knob, Date Input) holds its value in the element, so its inner inputs, such as the search input of a Select or the query input of a Combobox, are parts of its interface and are never read, even when marked: what a visitor types there is not a value. A custom host that has not been defined yet, because its script has not loaded, is not read either: the form seeds it, and reads it when it upgrades and announces itself. A form-associated host with no native input to read (Select, Combobox, Listbox, Tag Group, Slider, Date Input and Knob) follows the same rule through the browser: a value the browser restored or autofilled into it (the host matches :state(restored) until its form resets) wins over the store, and a host the browser did not restore is seeded. In a browser without :state(), such a host is always seeded. A control the form has already written, by seeding it, resetting it or connecting another store, is never read as edited, wherever it moves afterwards, and a browser that restores a native control's value on back navigation leaves it differing from its markup, so the restored value is the one published. Radio Group and Checkbox Group take a choice the visitor made before they upgraded into their own value first, and so does a Checkbox that joins a group later, so the form publishes that value.

Script cannot tell a typed value from one it assigned, so a value set as a property that changes the native state the field compares counts as an edit, on a native input, textarea, checkbox, radio or select and on a host that owns native inputs (Checkbox, Switch, Radio Group, Checkbox Group, Number Field, a custom host that wraps a marked input): a script that restores a draft, or a framework that writes value as a property. Set initial values through markup attributes or the store instead. A host that owns no native input to read (Date Input, Slider, Knob, Select, Combobox, Listbox, Tag Group) is seeded unless the browser restored it, whatever a script assigned to its properties.

Disable a control with its disabled prop. Use a native <fieldset disabled> around a group of controls. Native inputs follow the fieldset before JavaScript loads, and form-associated hosts follow it once they upgrade. The built-in form store skips disabled controls during validation and omits their values on submit. Style a disabled field with rui-field:has(:disabled). This selector also matches a read-only Number Field with disabled stepper buttons.

Use Radiant controls

RuiField only wires library controls: presentational ones marked with data-rui-control (RuiInput, RuiTextarea, select triggers) and host elements such as rui-select, rui-switch, and rui-date-input. The listbox inside a select or combobox popup is plain markup, not a separate field control. Bare <input> / <textarea> without the marker are ignored.

Surface errors inline

Set invalid and pass the error message so RuiFieldError renders below the control with aria-live semantics.

Errors that belong to a group

Pass error to RuiFieldError for a message that is not about one control, such as a group or a repeating array. The region is controlled: it renders error (with children as the fallback), is visible while it has content, works outside a RuiField and on the server, and carries data-rui-field-error-controlled so an enclosing field never overwrites or hides it. For example, a list with a minimum length:

import { RuiFieldError } from '@ecopages/radiant-ui/field';

<ul aria-describedby="items-error">{items}</ul>
<RuiFieldError id="items-error" error={items.length === 0 ? 'Add at least one item' : ''} />

An empty error keeps the region controlled and hidden; omit error to leave the region to the enclosing field. Give the region an id and point the group's aria-describedby or aria-errormessage at it. Inside a field, a controlled region without an id gets one and is added to the control's aria-describedby and stays listed while hidden, since an empty region adds nothing to the description.

Warnings

A form store you inject can report warnings beside its errors. A warning is advice: RuiFieldWarning shows it under the control, and it never marks the control invalid, never reaches aria-invalid or aria-describedby, and never blocks submit. The field fills the region and hides it when there is no warning, the way it does RuiFieldError. The region renders role="status", a polite live region, so a warning that appears is announced without interrupting.

import { RuiField, RuiFieldError, RuiFieldWarning } from '@ecopages/radiant-ui/field';

<RuiField>
	<RuiInput name="password" type="password" />
	<RuiFieldError />
	<RuiFieldWarning />
</RuiField>;

A field writes a native control (<input>, <textarea>, <select>) to its form on the native input and change events, and any other control, such as a checkbox group or a multi-select, on the same two events, but only when the event target is the control host or a member native input of a wrapper or group. See Form for how to inject a store that reports warnings.

Required fields

required marks a field for aria-required and for a required marker (it is reflected as an attribute, so CSS can target rui-field[required], and fieldContext.required carries it to a control). It validates nothing, so it is the way to mark a field required when a form store you inject owns validation and the form ignores rules. With the built-in store a required rule still validates as before and also implies the flag.

<RuiField required>
	<RuiLabel>Email</RuiLabel>
	<RuiInput name="email" type="email" />
</RuiField>

Controls that arrive late

The field discovers its contained control during server rendering to wire label and description IDs. In the browser, the field also finds its control when it connects. A Radiant control host, or a custom host that calls announceControlConnect, can appear later: it announces itself with a bubbling rui-control-connect event and the field seeds it from the form and reads its validity. A native <input>, <select> or <textarea> marked data-rui-control announces nothing, so it must already be inside its rui-field when the field connects. One inserted later is picked up on the field's next sync, that is, on the next store notification or re-render.

Disabled fields

The field has no disabled prop: the control carries it, or a native <fieldset disabled> around the field does, as described above.

Theming

Field surfaces map to semantic surface roles, never Tailwind palette steps:

PartCSS roles
Root (.rui-field)space-inline gap
Description (.rui-field__description)on-surface, text-body-sm
Error (.rui-field__error)error, text-body-sm
Warning (.rui-field__warning)warning, text-body-sm

The nested control keeps its own control tokens (--size-control-*, --radius-control) so fields stack consistently. Override at the theme layer, not in component CSS.

API

RuiField is a custom element (<rui-field>) connecting a composed control to an ancestor <rui-form>. It is not listed in native FormData; the child control is.

Attributes

AttributeTypeDefaultDescription
errorstring''Standalone error message when not using a form provider.
invalidbooleanfalseStandalone invalid flag when not using a form provider.
requiredbooleanfalsePresentation only: sets aria-required on the control and fieldContext.required for a required marker, in every mode. It validates nothing. A required rule still validates with the built-in store and also implies it.
data-default-valuestringJSON-serialized default value for SSR hydration.

Props

PropTypeDescription
rulesFieldRulesValidation rules (required, min/max, pattern, validate…).
defaultValueunknownDefault value when uncontrolled.
defaultValueDatastringJSON default value; falls back to data-default-value.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-rui-control] or control host tagyesid, data-rui-field-managed, aria-invalid, aria-required, aria-describedby on ARIA targetscontrol element; see each host's inner contract
[data-rui-field-label]nohtmlFor; id when the control is a registered custom hostlabel text
[data-rui-field-description]noiddescription content
[data-rui-field-error]noid, textContent, hidden (skipped when data-rui-field-error-controlled; only a missing id is written)error region presence
[data-rui-field-warning]notextContent, hiddenwarning region presence
[data-ref="field"]no—presentation column

Nested hosts: registered control hosts inside the field (rui-switch, rui-slider, …).

Custom control hosts

A host registered with registerFieldControl carries its own name, which the field reads and registers it under. Give it a name attribute or property; the field reads it again the next time it syncs. Code outside the field reads that name the same way with readControlName(control) from @ecopages/radiant-ui/form: the control's name property, then its name attribute, trimmed, or '' when there is none.

A host registered with registerFieldControl that declares data-rui-aria-target or data-rui-aria-targets renders its target on its own schedule, often after the field connected. The field therefore writes no id, data-rui-field-managed or aria-* for it. It publishes the state on fieldContext (controlId, labelId, describedBy, invalid, required) and the host binds it onto its target declaratively. Read the context into a @state field with @contextSelector, then:

A host that owns a render() tree spreads fieldAria(field) on the target, so the attributes are repainted whenever the target renders or the field changes:

import { RadiantElement, customElement, state } from '@ecopages/radiant';
import { contextSelector } from '@ecopages/radiant/context';
import { fieldAria, fieldContext, type FieldContextValue } from '@ecopages/radiant-ui/field';

@customElement('x-code')
class XCode extends RadiantElement {
  @contextSelector({ context: fieldContext })
  @state
  field?: FieldContextValue = undefined;

  override render() {
    return <input {...fieldAria(this.field)} />;
  }
}

Register the tag before the field connects and declare the target on the host element in the field's markup:

import { registerFieldControl } from '@ecopages/radiant-ui/form';

registerFieldControl('x-code', {
  read: (host) => host.querySelector('input')?.value ?? '',
  write: (host, value) => {
    const input = host.querySelector('input');
    if (input) input.value = String(value ?? '');
  },
});

// <RuiField>
//   <RuiLabel>Code</RuiLabel>
//   <x-code name="code" data-rui-aria-target="input" />
//   <RuiFieldError />
// </RuiField>

A host that keeps authored DOM (no render()) decorates the same field with @bindTo(fieldAriaBindings(selector)):

@contextSelector({ context: fieldContext })
@bindTo(fieldAriaBindings('input'))
@state
field?: FieldContextValue = undefined;

@bindTo copies on connect and when the field changes; it does not repaint a target inserted afterwards. A target the host creates after connecting must come from render(). Both forms bind id (the controlId the label's htmlFor points at, so clicking the label focuses the target) along with aria-labelledby, aria-describedby, aria-invalid and aria-required, and set data-rui-field-managed on the target.

data-rui-field-managed marks a target whose ARIA comes from the field. The control supplies its label as an accessible-name fallback when the field has no visible label. The field and both helpers set it; never set it yourself. It is what lets a host wrap a Radiant UI control (a rui-select, rui-combobox, rui-number-field, rui-date-field or rui-listbox inside your host) and keep the painted aria-labelledby: left unmarked, the control looks for a label beside itself, finds none, and strips it. A control whose target no field or field host paints keeps labelling itself.

Native disabled stays with the author. Painted hosts support a single ARIA target, since both helpers yield one id; a host with several targets (data-rui-aria-targets) must assign its own ids. A host that declares its target only when it connects is switched over on the field's next sync, which removes what the field wrote on the host before (an authored id stays); the view needs no declaration helper. Catalog hosts and native inputs keep the field's direct writes.

A form-associated host that reports invalid through setValidity also makes its field invalid; see the custom form-associated hosts section of Form.

View helpers

ComponentTarget stampedNotes
RuiField[data-ref="field"]Passes rules / defaultValue via prop: bindings.
RuiFieldDescription[data-rui-field-description]Wired into aria-describedby.
RuiFieldError[data-rui-field-error]Text populated by the field; role="alert". error makes it controlled (data-rui-field-error-controlled).
RuiFieldWarning[data-rui-field-warning]Text populated by the field from a warning an injected form store reports; role="status", hidden until set. A warning never marks the control invalid or blocks submit.

CSS classes

Public BEM classes (documented via @cssclass):

ClassDescription
.rui-fieldRoot column (authored by the element).
.rui-field__descriptionHelper text below the control.
.rui-field__errorError text; hidden until a message is set.
.rui-field__warningWarning text; hidden until a warning is set.

Theme roles

PartCSS variables consumed
Root--space-inline
Description--on-surface, --text-body-sm
Error--error, --text-body-sm
Warning--warning, --text-body-sm

Accessibility

  • Associate labels with controls using RuiLabel; do not rely on placeholder text alone.
  • Error messages are linked to the input via aria-describedby.
  • Descriptions provide supplementary context without replacing the label.