Skip to content

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

Open
abhinavapasok wants to merge 3 commits into
e2e-inc:mainfrom
abhinavapasok:fix/web-sr-only-label-stand-in
Open

abhinavapasok wants to merge 3 commits into
e2e-inc:mainfrom
abhinavapasok:fix/web-sr-only-label-stand-in

Conversation

@abhinavapasok

@abhinavapasok abhinavapasok commented Nov 13, 2026 •

Copy link
Copy Markdown

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:
main this branch
3 failed: ACTION_FAILED: check did not become actionable in time ... <div class="track"></div> intercepts pointer events 3 passed (check 972ms, tap 142ms, text-only label 141ms)
main after

This branch running check() on the toggle:

check on this branch

View guided diff

Tailwind's sr-only shrinks the input to a clipped pixel with margin:-1px,
so in a label with no left padding its centre sits half a pixel outside
the label and pickStandIn refused the stand-in; Playwright then clicked
the hidden input and failed with "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, and
controlPoint clicks the label's centre for a control centred outside it.
On that path a label whose centre nothing hits yet is read again rather
than taken. The boxless path is unchanged.

Fixes e2e-inc#1744
@github-actions github-actions Bot added the size:M Up to 99 changed lines, not counting tests, fixtures, or the lockfile label Nov 13, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/web/src/actions.ts">

<violation number="1" location="packages/web/src/actions.ts:134">
P2: The pixel fallback accepts a label whose center lands on an ARIA checkbox, radio, or switch because `INTERACTIVE` omits those roles. Extend the interactive-control check so this path refuses those targets rather than clicking them.</violation>
</file>

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread .changeset/check-sr-only-label.md Resolved
label.scrollIntoView({ block: 'nearest', inline: 'nearest' });
const hit = topmost(...centre(label.getBoundingClientRect()));
if (hit === undefined && requireHit) unreached = true;
else if (!pressesInteractive(label, hit)) return label;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The pixel fallback accepts a label whose center lands on an ARIA checkbox, radio, or switch because INTERACTIVE omits those roles. Extend the interactive-control check so this path refuses those targets rather than clicking them.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/web/src/actions.ts, line 134:

<comment>The pixel fallback accepts a label whose center lands on an ARIA checkbox, radio, or switch because `INTERACTIVE` omits those roles. Extend the interactive-control check so this path refuses those targets rather than clicking them.</comment>

<file context>
@@ -122,37 +123,48 @@ function pickStandIn(node: Element, unrendered: string): HTMLLabelElement | null
+      label.scrollIntoView({ block: 'nearest', inline: 'nearest' });
+      const hit = topmost(...centre(label.getBoundingClientRect()));
+      if (hit === undefined && requireHit) unreached = true;
+      else if (!pressesInteractive(label, hit)) return label;
+    }
+    if (unreached) throw new Error(unrendered);
</file context>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INTERACTIVE is the selector every label stand-in path on main already uses (the boxless control and the hit at the control point), not something this PR adds. Adding the ARIA checkbox, radio, and switch roles would change those paths for Element Plus and boxless controls too, so I have left it out of this fix. Happy to send it as a follow-up if you want it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Thanks! Root cause of #1744 confirmed on main: the 1x1 sr-only input centre is x=7.5, the label starts at x=8, so pickStandIn refuses the label and Playwright clicks the clipped input. Your 8 new tests fail on main and pass here.

Must fix:

  1. packages/web/src/actions.ts:142 - box.width <= 1 && box.height <= 1 is a size heuristic, and it still fails a clipped 2x2 control, zoom: 2 and transform: scale(2). The real condition is "the control can't be hit at its own centre". Suggested shape: compute hits = root.elementsFromPoint(x, y) once; if the hit is in a label with nothing interactive under it and the centre is inside the label box, return the label (as now); else if !hits.includes(node), return labelAtCentre(true); else throw unrendered when nothing was hit, otherwise null. Locally this kept all 101 check-actions tests green (including "covered from outside the label box" and the dialog case), fixed zoom/scale/2x2, and removed the pixel flag plus both branches reading it.
  2. packages/web/tests/integration/check-actions.test.ts - nothing covers the controlPoint clamp (actions.ts:166) or the missed-hit branch: reverting either leaves the suite green. Add an RTL (dir="rtl") case or a sibling for= label set apart from the input, plus zoom/scale once (1) lands.
  3. actions.ts:131-136 - removing unreached breaks no test. Cover it or drop it.

Nits:

  • pickStandIn JSDoc (~:101) is a run-on now. If (1) lands, say "clipped" instead of "shrunk to a pixel" there, in the changeset and in docs/reference/screen.mdx:794.
  • cubic's INTERACTIVE ARIA-roles note predates this PR (#1595); fine as a follow-up.

Changeset package/bump and the docs edit look right.

Replace the one-pixel size check with the real condition: a control
that elementsFromPoint does not hit at its own centre is clicked through
its label. A clipped control under zoom or a CSS scale now works, and
the pixel flag and the branches reading it are gone.

Cover the controlPoint clamp with a for= label set apart from its input,
and the unreached throw with a label in a dialog that takes pointer
events only after a delay.
@abhinavapasok

Copy link
Copy Markdown
Author

Thanks for the detailed pass. Addressed in 31f03bc:

  1. Replaced the size check with "is the control hit at its own centre", as suggested; the pixel flag and both branches reading it are gone.
  2. Added zoom: 2 and transform: scale(2) cases (both fail on the previous commit) and a for= label set apart from its input, which fails with the controlPoint clamp removed. An RTL label didn't exercise the clamp in my attempts, so I left it out.
  3. Kept unreached and covered it: an sr-only checkbox whose label sits in a dialog that takes pointer events after 300ms. Without the throw the click goes to the clipped input and fails; with it the read retries and checks through the label.

Nits: JSDoc rewritten, and "clipped" in the changeset and screen.mdx. Leaving the INTERACTIVE ARIA roles for a follow-up as you suggested.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.

View guided diff | Re-trigger cubic

Comment thread packages/web/src/actions.ts Resolved

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[claude-opus-5-5] automated review on behalf of @okwasniewski

Re-reviewed at 31f03bc58. All three earlier asks are done and the tests catch a revert:

  • Swapping in main's actions.ts fails 16 tests.
  • Removing the miss branch fails 20, removing the clamp fails 6, and removing the unreached throw fails 2.

Regressions I checked are all fine: a visible checkbox under an overlay, a label-less sr-only control, and a display:none label all behave as on main. cubic's covered-from-outside case still refuses.

The new fall-through has one problem that needs fixing:

  1. It can click a link inside the label (packages/web/src/actions.ts:151).
    • Setup: a clipped input absolutely positioned inside its label, over an <a> in that label, with plain text at the label's centre.
    • The control-centre hit is the link, so labelAtCentre(true) checks the label's centre (text) and accepts the label. The click then lands at controlPoint, which is the link.
    • check follows the link and fails with "state did not change". tap returns ok and leaves the box unchecked. Main refuses with <a> intercepts pointer events.
  2. The two "nothing hit at label centre" policies disagree (actions.ts:127-142).
    • The boxless path accepts the label, while the missed-hit path throws UNRENDERED.
    • An sr-only checkbox whose inline label wraps, so the box centre falls between lines, now times out with "the control and its labels are not visible". On main it said "label intercepts pointer events".

Both have one root cause: pickStandIn hit-tests a different point from the one Playwright clicks.

Fix:

  • Have pickStandIn compute the actual click point: the control centre if it's inside the label, otherwise the centre of the label's first client rect.
  • Hit-test only that point and return { label, position }.
  • controlPoint, its clamp, requireHit and unreached then go away.
  • Add tests for the link case and for a wrapped label with an sr-only input.

Nits:

  • actions.ts:145 copies the predicate inside topmost (:123). Pull it into one helper.
  • One changeset line: a full-size checkbox with pointer-events: none and a separate label is now checked through the label (main failed it).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M Up to 99 changed lines, not counting tests, fixtures, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web: check() and tap() fail on a Tailwind sr-only checkbox inside its own label

2 participants