Repository navigation
Description
Context
Part of #2576.
(Toggle, packages/ui-kit/src/primitives/Toggle.tsx:64-120) draws an operable switch as <span role="switch" aria-checked tabIndex> with a hand-written Space handler (onKeyDown, Toggle.tsx:98-102). Disabled is aria-disabled plus pointerEvents: none plus tabIndex -1 (:84, :112-113). The knob moves by animating left (:89) through inline transition declarations on the track (:83) and knob (:94). Its 44px reach is .bk-switch::before (D34, documented at Toggle.tsx:13-22). It has 9 operable call sites in ui-react, plus a decorative use in (ListRow, packages/ui-kit/src/rows/ListRow.tsx:196).
A native <input type="checkbox" role="switch"> provides focus, Space, disabled, form participation and the checked state natively. The HTML switch attribute is Safari-only and its polyfill is not allowed, so role="switch" with appearance: none is the cross-engine form. Guide forms/switch: "Use the HTML switch attribute on <input type="checkbox" switch> … to build a binary on/off toggle that preserves native form submission, keyboard navigation, and screen reader semantics". Its fallback section names role="switch" and appearance: none as what the polyfill applies.
Reduced-motion defect (absorbed from #2166, closed as a duplicate of this issue)
Those inline transitions override the reduced-motion rule: tokens.css declares .bk-switch, .bk-switch * { transition: none; } inside @media (prefers-reduced-motion: reduce) (packages/ui-kit/src/tokens.css:1436, rule at :1463-1466), but a normal stylesheet declaration does not beat an inline one. Observed failure (recorded on #2166, found while verifying #2059): pinned offline Chromium with reducedMotion: "reduce" returned matchMedia("(prefers-reduced-motion: reduce)").matches === true and a computed track transition duration of 0.18s; the assertion expected 0s and failed on that value, not during module loading. Fixing it is owned scope of this issue, not a side effect.
Scope
- When
onClickis passed, render a native<input type="checkbox" role="switch">withappearance: none, painted as today's 38×22 track. Usechecked={on},onChangecallingonClick,disabled, andaria-label/aria-labelledbyas today. - Draw the knob without children (an input has none): either a sibling element that
:checked +positions, or a background layer. Move it withtranslatein the stylesheet. Put the track and knob transitions intokens.css, not inline, so the existing reduced-motion block removes them. Audit the touched primitive for any other inline transition that would override that block. - An
<input>does not reliably render::beforeacross engines (Firefox ignores it), so move the 44px reach (.bk-switch::before) onto a wrapping element. Keep D34's geometry: reach of 11px vertically and 3px horizontally. - When no
onClickis passed, render the decorative switch as today (non-interactivespan, no role).
Out of scope
- The
switchattribute and its polyfill. - New visuals or motion timings (keep
.18s ease). TogglePropschanges.- ThemeToggle (ui-react: the theme radiogroup is three tab stops with no arrow keys #2580).
Acceptance criteria
- An operable
Toggleis a native checkbox input withrole="switch". It has notabIndexand no key handler of its own. Space toggles it once and Enter does nothing (the design's key table). Disabled is nativedisabled. - The
Toggle.stories.tsxelementFromPointedge assertions for adjacent switches pass, and track and knob pixels match the current baselines in both themes and in both states. - Under
prefers-reduced-motion: reduce, toggling runs no transition on track or knob: their computed transition duration is0s. Under no preference both keep0.18s ease. Asserted with real computed styles and state changes in the pinned offline Chromium harness, in both motion modes. - Reduced-motion mutation: reintroduce an inline
transitionon the track (or knob) and watch the reduced-motion assertion fail on its0sexpectation (not on module load), then restore. Record both runs in the PR. - Keyboard operation, accessible name, checked state and the 44px hit area remain intact in both motion modes.
- A real-browser test toggles each operable call site in
packages/ui-reactby keyboard and pointer. The native-element assertion fails on the current tree. Record that run in the PR. - Changeset for
@schlessera/brain-ui-kit(patch).
Verification
node scripts/visual.mjs --project=storybook --project=storybook-light --filter=Toggle.stories
node scripts/visual.mjs --project=visual --project=module-settings
bun run test packages/ui-kit packages/ui-react
bun run typecheck
bun run lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. - This changes a published package's behaviour, so it needs a changeset.
ToggleProps is unchanged. Only the rendered element changes.
2026-10-24: merged #2166 into this issue: its reduced-motion criteria, Chromium failure evidence and guard-removal mutation are now owned scope here, and #2166 is closed as a duplicate. Refreshed the Toggle and tokens.css citations.
Activity
schlessera commentedon Oct 23, 2026
2026-10-24 restructuring: raised to p2 because this issue now also owns #2166's p2 reduced-motion fix, which is being merged into it.