fix(web): check an sr-only checkbox or radio through its own label

AB
2d ago
+165-30

What and why

  • Tailwind's sr-only (and Bootstrap's visually-hidden) shrinks a checkbox to one clipped pixel with margin: -1px. In a label with no left padding, the usual toggle switch, that pixel's centre sits half a pixel outside the label, so pickStandIn (packages/web/src/actions.ts) rejected the label stand-in and Playwright clicked the hidden input: <div class="track"></div> intercepts pointer events.
  • A pixel-sized control whose centre lands outside its label, or hits nothing, now takes a label the way a boxless control does: the first visible label whose centre is not a link or another control. controlPoint clicks the label's centre for a control centred outside it, so the point read and the point clicked are the same.
  • On that path a label whose centre nothing hits yet (a dialog with pointer-events: none while it opens) is read again rather than taken, so a click never lands on a link there that was not checked. The boxless path keeps its current behaviour, so a wrapping or very tall label still works there.
  • Everything else reads as before: a pixel inside a padded label is still clicked at its own point, a visible pixel-sized input with no visible label is still clicked as itself, and a full-size radio covered from outside its label box is still refused.

I kept the label-box check instead of widening it by a pixel, since still refuses a radio whose label covers it from outside the label box depends on it.

Not covered, and failing on main too: an sr-only control under zoom or transform: scale() (it measures more than a pixel), and one whose label starts with a button, which the half-pixel point hits first.

Issue

Fixes #1744

Verified

Ran it locally: yes

  • check-actions.test.ts: the 8 new sr-only/visually-hidden cases (check, tap, uncheck, both target kinds) fail on main and pass here. The padded-label-with-a-link, visible one-pixel, link-behind-an-opening-dialog, and wrapping-label cases pass on both, as guards.
  • Built CLI: e2e and @e2e-dev/web packed from main and from this branch, installed into the sr-only-toggle repro, npx e2e run:
mainthis branch
3 failed: ACTION_FAILED: check did not become actionable in time ... <div class="track"></div> intercepts pointer events3 passed (check 972ms, tap 142ms, text-only label 141ms)
mainafter

This branch running check() on the toggle:

check on this branch