fix(electron): read progress values, empty-for labels, and text under aria-hidden or inert as web() does (ENG-892)
Merged
KD
20h ago+56+56+01234567890123456789-12-12-01234567890123456789
What
The Electron engine reads four things the way web() does:
- A
<progress>or<meter>value is clamped to its range (value="25" max="10"reads10). An indeterminate<progress>has no value, sotoHaveValue('')andnot.toHaveValue('')both fail on it. - A label with an empty
forlabels no control. A label with anyfordoes not label a control it wraps. So a zero-size checkbox beside or inside such a label is hidden, not drawn by the label. getByTextfinds text under aninertelement, as it already found text underaria-hidden.getByTextunderaria-hiddenorinertanswers with the element that holds the text (<span data-testid="north">North gate</span>), not only the element that hides it.
docs/electron.mdx also says that an element aria-owns names reads under its owner, so query results and first() order it there, not in document order. That order does not change.
Why
The second PR of the stack for the review of #2237 (ENG-892), which added @e2e-dev/electron. The review found these differences from the web engine in what the tree reads:
rangeValueOfread a native element'svalueattribute as written:25forvalue="25" max="10", and''for an indeterminate progress bar, which has no value on the web.drawnByLabeltook a label withfor=""as the label of an element with noid, and a wrapping label with aforas the label of the control it wraps. A hidden control next to such a label read as visible.placeAbsentplaced only the element that carriesaria-hidden="true". Text underinertwas not found, and text in a child of a hiding element was found only on the hiding element.
The aria-owns order is Chromium's tree order. We decided to document it and not change it.
How it works
rangeValueOf(packages/electron/src/fields.ts:208) readsaria-valuetext, thenaria-valuenow, as written. Without them, aPROGRESSorMETERelement with avalueattribute reads Chromium's value for it (node.value), which is clamped. Else a slider or spinbutton reads'', and any other range role, an indeterminate progress bar too, has no value.drawnByLabel(packages/electron/src/snapshot.ts:182) looks up labels byforonly for an element with a non-emptyid. A label around the element counts only when it has noforattribute (snapshot.ts:184), aslabel.controlreads it.placeAbsent(packages/electron/src/tree.ts:201) collects every element witharia-hidden="true"orinert, then places every element with bounds that is one of them or under one (tree.ts:212). A page with no such element is not walked. Text nodes are left out: their text folds into the element that holds them, so a text query answers with that element. These nodes have no role, so a role query still does not find them.docs/electron.mdx:268adds thearia-ownsrow to "What differs from the web".- The testbed's controls page gets the cases (
apps/electron-testbed/app/controls.html), with assertions inapps/electron-testbed/tests/controls.e2e.ts.
Issue
Part of ENG-892. Stack: #2419 ā this PR ā #2421 ā #2422 ā #2423.
Verified
Ran it locally: yes
pnpm --filter @e2e-dev/electron testandtest:integration, and the electron testbed, on this layer:
@e2e-dev/electron unit + integration: Tests 147 passed (147)
apps/electron-testbed: Tests 75 passed (75)
- The testbed tests of this PR on the code of the PR below it (the bug) and on this PR (the fix):
| Test | PR below | this PR |
|---|---|---|
testbed controls.e2e.ts: reads a heading tag's level over its aria-level, and a progress element's value | failed | passed |
testbed controls.e2e.ts: checks a checkbox its label draws, and finds text by text alone, as web() does | failed | passed |
testbed controls.e2e.ts: finds text that inline markup splits, and text under aria-hidden or inert, as web() does | failed | passed |
- Behavior and timing against
main: see thepnpm bench:abtable in #2423. - No changeset:
@e2e-dev/electronis not released yet (0.0.0, not on npm).
š¤ Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Progress indicators now clamp determinate values to their maximum; indeterminate indicators are no longer mistaken for empty or populated ones.
- Label-based control matching ignores labels that do not identify the control. Text queries handle inert content more accurately.
- Accessibility queries better reflect range values and account for elements hidden with
aria-hiddenorinert.
- Documentation
- Clarified how
aria-ownsaffects accessibility-tree reading order and query results.
- Clarified how