Repository navigation
fix(web): check an sr-only checkbox or radio through its own label - #1748
abhinavapasok wants to merge 3 commits into
Conversation
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
There was a problem hiding this comment.
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
| 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; |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
[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:
packages/web/src/actions.ts:142-box.width <= 1 && box.height <= 1is a size heuristic, and it still fails a clipped 2x2 control,zoom: 2andtransform: scale(2). The real condition is "the control can't be hit at its own centre". Suggested shape: computehits = 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), returnlabelAtCentre(true); else throw unrendered when nothing was hit, otherwise null. Locally this kept all 101check-actionstests green (including "covered from outside the label box" and the dialog case), fixed zoom/scale/2x2, and removed thepixelflag plus both branches reading it.packages/web/tests/integration/check-actions.test.ts- nothing covers thecontrolPointclamp (actions.ts:166) or the missed-hit branch: reverting either leaves the suite green. Add an RTL (dir="rtl") case or a siblingfor=label set apart from the input, plus zoom/scale once (1) lands.actions.ts:131-136- removingunreachedbreaks no test. Cover it or drop it.
Nits:
pickStandInJSDoc (~:101) is a run-on now. If (1) lands, say "clipped" instead of "shrunk to a pixel" there, in the changeset and indocs/reference/screen.mdx:794.- cubic's
INTERACTIVEARIA-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.
|
Thanks for the detailed pass. Addressed in 31f03bc:
Nits: JSDoc rewritten, and "clipped" in the changeset and |
There was a problem hiding this comment.
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
okwasniewski
left a comment
There was a problem hiding this comment.
[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.tsfails 16 tests. - Removing the miss branch fails 20, removing the clamp fails 6, and removing the
unreachedthrow 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:
- 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 atcontrolPoint, which is the link. checkfollows the link and fails with "state did not change".tapreturns ok and leaves the box unchecked. Main refuses with<a> intercepts pointer events.
- Setup: a clipped input absolutely positioned inside its label, over an
- 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".
- The boxless path accepts the label, while the missed-hit path throws
Both have one root cause: pickStandIn hit-tests a different point from the one Playwright clicks.
Fix:
- Have
pickStandIncompute 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,requireHitandunreachedthen go away.- Add tests for the link case and for a wrapped label with an sr-only input.
Nits:
actions.ts:145copies the predicate insidetopmost(:123). Pull it into one helper.- One changeset line: a full-size checkbox with
pointer-events: noneand a separate label is now checked through the label (main failed it).
What and why
sr-only(and Bootstrap'svisually-hidden) shrinks a checkbox to one clipped pixel withmargin: -1px. In a label with no left padding, the usual toggle switch, that pixel's centre sits half a pixel outside the label, sopickStandIn(packages/web/src/actions.ts) rejected the label stand-in and Playwright clicked the hidden input:<div class="track"></div> intercepts pointer events.controlPointclicks the label's centre for a control centred outside it, so the point read and the point clicked are the same.pointer-events: nonewhile 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.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 boxdepends on it.Not covered, and failing on main too: an
sr-onlycontrol underzoomortransform: 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 newsr-only/visually-hiddencases (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.e2eand@e2e-dev/webpacked from main and from this branch, installed into thesr-only-togglerepro,npx e2e run:3 failed:ACTION_FAILED: check did not become actionable in time ... <div class="track"></div> intercepts pointer events3 passed(check972ms,tap142ms, text-only label 141ms)This branch running
check()on the toggle: