Skip to content
Alpha

Hololink UI is under active development. Components, APIs and these docs may change without notice.

Holo Form Field

The <holo-form-field> component wraps a <label>, a slotted control, an optional hint, and an error message region. It automatically generates and forwards id/aria-describedby/aria-invalid/aria-required attributes onto the first slotted element, so native controls and form-associated custom elements are labelled and described without manual wiring.

Use it for:

  • Giving any single control a visible label, optional hint and error message with consistent layout.
  • Wrapping native controls (<input>, <select>) or custom ones that do not have their own label.

Don’t use it for:

  • Wrapping Text Field, Textarea, Select or Checkbox when you already set their own label. They render their own label and error.
  • Grouping several related controls. Use a <fieldset> with a <legend>.
  • Page-level error summaries. Use Alert.
<holo-form-field label="Email address" hint="We'll never share your email.">
<input type="text" placeholder="you@example.com" />
</holo-form-field>
<holo-form-field label="Full name" required>
<input type="text" />
</holo-form-field>
<holo-form-field label="Email address" invalid error-message="Please enter a valid email address.">
<input type="text" value="not-an-email" />
</holo-form-field>

The component creates a native <label>, the hint and the error message as light-DOM children of <holo-form-field> (marked data-holo-form-field) and projects them into named slots. They sit in the same tree as your control, so the label’s for and the control’s aria-describedby resolve: the control’s accessible name is the label, and its description is the hint followed by the error. The error has role="alert" and is only present when invalid is set and errorMessage is provided.

On the first slotted element the component sets a generated id (if it has none), aria-describedby (hint, and error when shown), aria-invalid="true" when invalid, and aria-required="true" when required. The required marker is aria-hidden, so it is not part of the name.

The component is not interactive and has no keyboard behaviour. Keyboard use is that of the slotted control.

  • The created elements are ordinary light-DOM elements, so page-wide styles for label can reach them. Do not remove or reorder them from your framework code.
  • The for association works for labelable elements: native <input>, <select>, <textarea>, and form-associated custom elements. A custom element that renders its own input in a shadow root (such as Text Field) is not named by this label; use that component’s own label instead.

You provide:

  • A label. It is required.
  • The control itself. Set required and invalid on the wrapper; the wrapper copies the ARIA state onto the control, but a native required attribute (and validation) is still yours to set.
  • Error text that says what is wrong and how to fix it, not colour alone.

Importing

import '@philbob-sideprojects/hololink-ui/holo-form-field';

Properties

PropertyAttributeTypeDefaultDescription
errorMessageerror-messagestring—Error message rendered (and announced) when invalid is true.
hinthintstring—Optional hint/help text rendered below the control.
invalidinvalidbooleanfalseMarks the field as invalid — shows the error message and sets aria-invalid/aria-describedby on the slotted control.
label (required)labelstring—The visible label text describing the wrapped control.
requiredrequiredbooleanfalseMarks the field as required, appending a visual indicator to the label and setting aria-required on the slotted control.

Slots

SlotDescription
(default)The form control (input, textarea, or custom element) to label and describe.
error
hint
label

CSS custom properties

PropertyDescription
--holo-form-field-error-colorText color of the error message.
--holo-form-field-error-gapSpace above the error message.
--holo-form-field-hint-colorText color of the hint.
--holo-form-field-hint-gapSpace between the control and the hint.
--holo-form-field-label-colorText color of the label.
--holo-form-field-label-gapSpace between the label and the control.
--holo-form-field-required-colorColor of the required indicator.