Field Label
catnip-field-label names the control whose id you pass in html-for, and a click on it reaches that control. Its required marker and disabled styling are visual only: you set the control's own required and disabled state.
Screen readers
- The label renders inside the element's shadow root, where a
forattribute can't reach your control. So the element finds the control with thehtml-foridin the same page (or the shadow root it sits in) and adds its ownidto the control'saria-labelledby. Without anid, it gets a generated one (catnip-field-label-1, …). IDs you already have inaria-labelledbystay; the element takes out only the one it added, whenhtml-forchanges or the label is removed. - A click on the label focuses the control, or toggles it for a checkbox or radio, like a native
<label>. - Catnip fields (
catnip-input,catnip-dropdown,catnip-checkbox, …) with thatidfind the label themselves and connect it to their inner control; nothing is written on their host. - Only the title, the optional hint and the required marker are inside the
<label>. The info button and theaction/suffixcontent sit beside it, so they aren't part of the control's name. inforenders a<button>named “More information about {title}” (locale keyfieldLabel.moreInfo) and described by the info text. The text shows as a tooltip on hover and focus, and Escape hides it. Clicking the button doesn't move focus to the control.- The
requiredmarker is visual only. - Optional
required-screen-reader-textadds a supplemental hidden phrase only when non-empty; it does not replacearia-requiredon the control.
What you own
- Association: Set
html-foron the label and a matchingidon the control, in the same document or shadow root. Expectaria-labelledbyon the control to include the label'sid. - Required: When
requiredis true, setrequiredand/oraria-required="true"on the control — the label marker is visual only. - Disabled: When
disabledis set on the label for visual coordination, also set nativedisabledon the control.
WCAG 2.2 AA
| Criterion | The component | You |
|---|---|---|
| 1.3.1 Info and relationships, 4.1.2 Name, role, value | Names the control through aria-labelledby and forwards clicks; the info icon is a named button | Set required / aria-required and disabled on the control |
| 2.5.3 Label in name | The name is the visible title; action and suffix content stay out of it | — |
| 3.3.2 Labels or instructions | Required and optional markers | Mark required or optional fields consistently |
This table says who handles what. It isn't a conformance claim: WCAG conformance is claimed for a page or a process.
Known issues
- The control has to be in the same document or shadow root as the label, since the label finds it by
id.