Skip to content
Glint UI

Field

The composition that ties a label, a control, its description and its errors into one announced unit.

Usage

import { Field } from "@glint/components/field.slint";
import { Input } from "@glint/components/input.slint";
export component AppWindow inherits Window {
in-out property <string> username: "";
VerticalLayout {
alignment: center;
username-field := Field {
label: "Username";
required: true;
description: "Your unique public handle.";
errors: root.username == "" ? ["Username is required."] : [];
label-clicked => { username-input.focus(); }
username-input := Input {
text <=> root.username;
invalid: username-field.invalid;
}
}
}
}

Field acts as the single source of truth for form field composition. It pairs a label, helper description, and validation errors with an arbitrary slotted control. Bind your control’s invalid property to the surrounding Field.invalid output so that visual error borders and message text remain synchronized.

Examples

Orientations

The orientation property controls label placement relative to the control. FieldOrientation.vertical stacks the label above the control (standard for form columns). FieldOrientation.horizontal places the label beside the control (ideal for settings rows and switches). FieldOrientation.responsive places the label beside the control when container width exceeds responsive-breakpoint (default 448px), falling back to stacked on narrower widths.

Validation errors and live region

Pass an array of error messages to errors. When non-empty, Field.invalid becomes true and each message is rendered in destructive red text below the control. Each error is declared as an assertive live region so assistive technology immediately announces the failure upon validation.

Disabled field

Setting disabled: true on Field cascades disabled styling (dimmed opacity and silenced click interactions) to the label.

API Reference

Properties

PropertyTypeDefaultDescription
labelin stringno defaultLabel shown beside or above the control; empty hides the label row.
requiredin boolfalseAppends the destructive asterisk to the label.
descriptionin stringno defaultHelper text under the label; empty hides it.
errorsin [string]no defaultValidation messages under the control, one text node each; an empty list means "valid". A control failing two rules reports two messages rather than one string the consumer had to join.
orientationin FieldOrientationFieldOrientation.verticalWhere the label sits — see FieldOrientation.
responsive-breakpointin length448pxThe width a responsive field needs before it lays out as a row. shadcn's is the @md container query; a narrower form column can say so here.
disabledin boolfalseCarries the row's disabled state to the label this Field owns, so a disabled form row is said once here rather than on the label and the control both. The control in the slot still takes its own disabled — it is the thing that stops answering.
invalidout boolno defaultTrue while errors carries a message — bind the control's invalid to it.

Callbacks

CallbackDescription
label-clicked()Fired when the label is clicked; forward focus to your control.

Enums

EnumValues
FieldOrientationvertical, horizontal, responsive

Accessibility

  • Groupbox role. Field publishes an accessible groupbox node carrying accessible-label: root.label.
  • Descriptive context. The accessible description joins description and the first validation error message (ADR-0013).
  • Live region error announcements. Every error in errors is announced via accessible-live-region: AccessibleLiveness.assertive.
  • Label forwarding. Activating the label runs label-clicked(), allowing the parent container to forward keyboard focus to the slotted control.