Form field

stable 1.4 kB
<hk-form-field>

The wiring layer: it generates ids, links label, hint and error with aria-describedby, and flips to the error skin — for any control you put inside it.

#label#validation

Live demo

Running in this page — interact with it.

Inputs

NameTypeDefaultDescription
labelstring''Field label. Linked to the projected control by generated id.
hintstring''Helper line, replaced by error when that is set.
errorstring''Error message. Sets aria-invalid on the control.
requiredbooleanfalseMarks the label and sets the required attribute.
labelHiddenbooleanfalseKeeps the label for assistive tech but hides it visually.

Theming

Component tokens, each falling back to a global one:

PropertyDefaultControls
--hk-field-gap0.375remSpace between label, control and message.
--hk-field-error#b91c1cError text colour.

Accessibility

  • Ids are generated and wired automatically, so the label always points at the real control.
  • Hint and error are joined into one aria-describedby, so both are announced in order.
  • Required is conveyed through the attribute, not just the asterisk.

More in Forms