Skip to content

fix(a11y): compliance toggle knob position - #11

Merged
build-with-dhiraj merged 1 commit into
mainfrom
fix/compliance-knob-position
Jun 23, 2026
Merged

build-with-dhiraj merged 1 commit into
mainfrom
fix/compliance-knob-position

Conversation

@build-with-dhiraj

Copy link
Copy Markdown
Owner

What

Fixes the Compliance toggle knob geometry in the LabOS top nav. Follow-up to the focus-ring fix merged in #10; that PR cleaned the keyboard focus ring, this one corrects where the knob sits inside the track.

Root cause

In src/components/shell/ComplianceToggle.tsx, the switch knob span had a vertical anchor (top-0.5) but no horizontal anchor. With position: absolute and no left/right, left resolves to auto, placing the knob's base at the static-flow position (~14px, mid-track) instead of 0. The translate-x-* offsets were then applied on top of that wrong base.

Measured live before the fix:

  • OFF (aria-checked=false): computed left: 14px + translate(2px) so knob.left - track.left = 16px. The knob sat on the right, so OFF read like ON.
  • ON (aria-checked=true): computed left: 14px + translate(14px) so knob.left - track.left = 28px. Knob right edge at 770.66 vs track right 758.66, overflowing the 28px track by 12px (knob off the right edge, looks broken).

Fix (one line, ComplianceToggle.tsx only)

Add left-0 to the knob span so its base position is 0. Everything else is unchanged: track, colors, sizes, the translate-x-0.5 / translate-x-3.5 values, and the focus treatment from #10.

-          className={`absolute top-0.5 h-3 w-3 rounded-full bg-white ...
+          className={`absolute left-0 top-0.5 h-3 w-3 rounded-full bg-white ...

Verification (in-browser, Chromium via Playwright, against next dev)

After the fix:

  • OFF (aria-checked=false): knob.left - track.left = 2px (knob at the LEFT), right-overflow 0. Computed left: 0px, transform: translate(2px).
  • ON (aria-checked=true): knob.left - track.left = 14px (knob at the RIGHT, knob right edge 756.66 inside track right 758.66), right-overflow 0. Computed left: 0px, transform: translate(14px).
  • Toggle flips correctly both ways; aria-checked and the persisted localStorage value track state (false/0 to true/1 to false/0).
  • No console errors or warnings; no layout shift.

The pre-fix 16px / 28px-overflow numbers above were reproduced live in the same browser by removing the left-0 anchor, confirming the diagnosis.

CI parity

  • npx tsc --noEmit: pass
  • npm run build (Next build): pass, all 9 static pages generated, lint and type step clean
  • Lint: this project has no separate eslint config or lint script; Next's build-time check passed.

No change to globals.css and no change to mcclean.ts.

🤖 Generated with Claude Code

The switch knob span had a vertical anchor (top-0.5) but no horizontal
anchor, so left:auto resolved its base position to mid-track (~14px)
instead of 0. Measured live: OFF rendered the knob 16px from the track
left (reading like ON), and ON pushed the knob to 28px, overflowing the
28px track by 12px (knob off the right edge, looks broken).

Add left-0 to the knob so its base is 0. OFF now translates 2px (knob at
the left), ON translates 14px (knob right, right edge at 26px, fully
inside the 28px track, no overflow). Verified in a headless browser:
OFF knob.left - track.left = 2px, ON = 14px, right-overflow 0 in both,
aria-checked flips correctly, no console errors.

Follow-up to the focus-ring fix shipped in #10. Track, colors, sizes,
the translate values, and the focus treatment are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@build-with-dhiraj
build-with-dhiraj merged commit b25a3a5 into main Jun 23, 2026
1 check passed
@build-with-dhiraj
build-with-dhiraj deleted the fix/compliance-knob-position branch June 23, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant