Skip to content

Toggle Group ​

catnip-toggle-group is a role="radiogroup" of role="radio" segments with arrow-key navigation built in. You provide the group label and a text label for every option.

Keyboard ​

KeyBehaviour
Arrow keysMove the selection.
Home / EndJump to the first / last enabled segment.
Space / EnterSelect the focused segment.

Screen readers ​

PartSemantics
Grouprole="radiogroup" with aria-labelledby pointing at the field label when visible.
SegmentA role="radio" button with aria-checked.

info renders a button after the label, named “More information about {label}” and described by the info text, which shows as a tooltip on hover and focus; Escape hides it. Content in label.action and label.suffix sits beside the <label>, not inside it, so it isn't part of the field's name.

Visual ​

  • In Windows contrast themes, the focused option shows a system-colour outline.
  • The selected segment's label is semibold and the others are regular, so the selection isn't shown by colour alone. In Windows contrast themes it's filled with the system selection colours, since every segment gets the same border there.
  • Segment labels wrap, breaking long words if they must, so nothing is cut off in a narrow group or with larger text spacing.

What you own ​

  • Label: Set label (or the label slot). With hide-label, set toggle-group-aria-label to name the group.
  • Icon options: Keep a text label for every icon-bearing option; the icon is decorative and does not replace the accessible option name.
  • Errors on submit: Supporting text isn't a live region, so a message that appears later isn't announced by itself. On submit, move focus to the first invalid field or to an error summary.
  • Outside label or description: A <label for> or catnip-field-label html-for that points at the catnip-toggle-group element's id names the inner control when the field has no label of its own, and clicking it focuses the selected option, or the first one. IDs in aria-describedby (ariaDescribedby) are looked up in the page, or in the shadow root the element sits in, and read before the supporting text. Both are connected through element reflection; axe-core 4.11 doesn't read reflection yet and still reports label for an outside label.

WCAG 2.2 AA ​

CriterionThe componentYou
1.3.1 Info and relationships, 4.1.2 Name, role, valueA named radiogroup of radio segmentsShort labels; a label for icon-only options
1.4.1 Use of color, 1.4.11 Non-text contrastThe selected segment's label is semibold, so the selection isn't shown by fill alone; system selection colours in Windows contrast themesDon't override component colours
1.4.10 Reflow, 1.4.12 Text spacingLabels wrap at 320 px and with larger text spacingKeep labels short and check them at 320 px
2.1.1 KeyboardOne Tab stop; arrow keys, Home and End—
2.4.7 Focus visibleA focus ring in every state, read-only and Windows contrast themes includedDon't override focus styles

This table says who handles what. It isn't a conformance claim: WCAG conformance is claimed for a page or a process.

Known issues ​

None known.

Catnip Design System by Signicat