Skip to content
Focsd homeFocsd homeFocsd
Forms

Field

A wrapper that gives any input, including native and third-party ones, a label, a hint and messages.

  • Tag: focsd-field
  • Pattern: Label, hint and messages for any control (light-DOM IDs)
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-field label="Email" hint="We reply within one working day">
<input type="email" name="email" value="[email protected]" />
</focsd-field>
<focsd-field label="Size" required>
<select name="size">
<option>Small</option>
<option>Medium</option>
</select>
</focsd-field>
<focsd-field
label="Coupon code"
error="This code expired on October 1. Try a current code.">
<input name="coupon" value="AUTUMN" />
</focsd-field>
<focsd-field label="Delivery notes" warning="Add a gate code if the building has one.">
<div slot="control" role="textbox" contenteditable="true" aria-multiline="true"></div>
</focsd-field>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-field.js';
</script>
<focsd-field label="Email" hint="We reply within one working day">…</focsd-field>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
hinthintstring—
errorerrorstring | undefined—
warningwarningstring | undefined—
successsuccessstring | undefined—
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
requiredrequiredbooleanfalse

Slots

SlotDescription
(default)The control (an input, select, textarea or a form-associated element).
controlA control that is not a native or form-associated element, such as a role="textbox" element.
labelThe generated label.
hintThe generated hint.
messageThe generated error, warning or success message.

CSS parts

Style the inside of the component with ::part(), for example focsd-field::part(layout).

PartDescription
layoutThe row or column holding the label and the body.
labelThe wrapper around the generated label and the required marker.
bodyThe wrapper around the control, the hint and the message.
markerThe required marker (hidden from assistive technology).
announcerThe visually hidden status region that announces a changed message.

Accessibility

  • The label is a real <label for> for labelable controls (native inputs and form-associated elements); for any other [slot="control"] element it sets aria-labelledby.
  • The hint and message are light-DOM siblings of the control, referenced by aria-describedby (shadow roots cannot share IDs). The field keeps any aria-describedby ids you set.
  • error uses setCustomValidity where the control has it, so it blocks submission, and sets aria-invalid; clearing it undoes both. warning and success never block.
  • A message that changes after the first render is announced politely; one present at first render is only described.
  • The required marker is hidden from assistive technology: set required on the control itself so the name and state are read.
  • One control per field: only the first is labeled and described, so use one field per control.
  • The field has no role of its own. Author content is never replaced; generated nodes carry data-focsd-field.