Skip to content

Set aria-posinset and aria-setsize on grid rows - #159

Open
stepan-kuntso wants to merge 1 commit into
DHTMLX:masterfrom
stepan-kuntso:fix/grid-row-aria-posinset-setsize
Open

stepan-kuntso wants to merge 1 commit into
DHTMLX:masterfrom
stepan-kuntso:fix/grid-row-aria-posinset-setsize

Conversation

@stepan-kuntso

Copy link
Copy Markdown

Same area as #156 (ARIA attributes for screen readers).

What is broken

Grid rows are role="row" in a role="treegrid" with aria-level, but have no aria-posinset or aria-setsize. NVDA reports a position for each row ("2 of 4"), and without the fix that position is wrong and changes for the same row as the user moves around:

Step Row 10.0.3, 67d4425 (NVDA says) With the fix, 90cc9ce (NVDA says)
Tab into the grid Project A 1 of 1 1 of 2
Down Design 1 of 1 1 of 4
Down Build 2 of 2 2 of 4
Down Frontend 1 of 1 1 of 2
Down Backend (not recorded) 2 of 2
Shift+Up on Build (collapse) Build 1 of 1 2 of 4
Down Test 2 of 2 3 of 4
Up Build 1 of 2 2 of 4
Shift+Down on Build (expand) Build 1 of 1 2 of 4
Enter, then Save in the lightbox Build 1 of 1 2 of 4

The data has two top-level projects; "Project A" has four subtasks (Design, Build, Test, Release), and "Build" has two (Frontend, Backend). The correct positions are the ones in the right column.

Versions. The NVDA session was done on 10.0.3: the "before" build is master at 67d4425, the "after" build is the same commit plus this change (90cc9ce). Screen reader: NVDA 2026.3.1. Browser/OS: Google Chrome 157.0.8103.79, Windows (via AssistivLabs).

The branch is now rebased on 10.0.4 (498e217) with no conflicts and no change to the patch. 10.0.4 has the same defect in the markup: taskRowAttr is unchanged since 10.0.3, and on a 10.0.4 build the grid rows have neither attribute (checked in the DOM). I have not repeated the NVDA session on 10.0.4.

How to reproduce

Two pages with the same chart (12 tasks, two levels of subtasks, links, keyboard_navigation on, nothing else), each built from one commit. Both are 10.0.3 builds, the ones used in the NVDA session:

With NVDA running, on each page:

  1. Press Tab once: focus lands on "Project A".
  2. Press Down four times (Design, Build, Frontend, Backend), then Up twice (back to Build).
  3. Press Shift+Up to collapse "Build", Down to "Test", Up back to "Build".
  4. Press Shift+Down to expand "Build".
  5. Press Enter, Tab to Save, press Space; focus returns to "Build".
  6. Listen to the position NVDA gives after each step.

Cause

src/core/ui/wai_aria.js, taskRowAttr, sets aria-level, aria-selected and aria-expanded, but not aria-posinset and aria-setsize. Without them the browser works out the position and the size of the level itself. Why the numbers without the fix take the values in the table, and why they change after collapsing, expanding or closing the lightbox, I have not investigated.

Fix

In taskRowAttr, count the displayed siblings of the task (gantt.getSiblings; a sibling counts when gantt.getGlobalTaskIndex(id) > -1, which is the order the grid renders) and set aria-posinset (the task's position among them) and aria-setsize (their number). 18 lines in one function, existing public methods only. Like every _waiAria method, nothing is added when wai_aria_attributes is disabled.

The position is counted from the data, not from the DOM, so it does not depend on which rows are rendered. This part was checked in the DOM only, not with a screen reader (see "How to verify"):

  • Smart rendering: with 2,600 rows, of which 13–15 are in the DOM, every rendered row has the position and size expected from the data at five scroll positions.
  • onBeforeTaskDisplay filter: hidden siblings are not counted, and the values are updated when the filter changes and the chart is repainted.

Cost: each rendered row copies and walks the list of its siblings once, so the cost grows with (rows in the DOM) x (number of siblings). gantt.render() on a flat list, 14 rows in the DOM, 10.0.4 against this branch:

Siblings 10.0.4 (498e217) This branch (09c624a)
100 1.5 ms 1.5 ms
1,000 1.9 ms 2.1–2.2 ms
10,000 6.6–7.0 ms 8.9–9.5 ms

The added loop alone takes about 0.002 ms per row with 100 siblings, 0.02 ms with 1,000 and 0.18 ms with 10,000. How it was measured: headless Chrome 148 on an Apple M5, 1280x900 viewport, chart 480 px high, tasks added with gantt.parse; 5 warm-up calls of gantt.render(), then the average of 20 calls timed with performance.now(); three page loads per build at each size, and eight more per build at 10,000, alternating builds.

If this cost matters for very large flat lists, the sibling count can be cached per parent for one render pass; I kept the patch minimal and did not add a cache. Happy to change it if you prefer.

How to verify

  • NVDA 2026.3.1 with Google Chrome 157.0.8103.79 on Windows, the two pages above (10.0.3 builds), the steps above: the positions in the table. Not repeated on the rebased commit.
  • In the DOM (Chromium and WebKit), the rows on after.html have aria-posinset / aria-setsize 1/2, 1/4, 2/4, 1/2, 2/2, 3/4 for the rows above, and keep them after collapsing, expanding and saving the lightbox. On before.html the rows have neither attribute.
  • The rebased commit 09c624a and 10.0.4 (498e217), same data, script in headless Chrome 148, attributes read from the DOM: on 09c624a the same values, kept after gantt.close / gantt.open; on 10.0.4 neither attribute.
  • Smart rendering, same script: 2,000 top-level tasks, every tenth with 3 subtasks (2,600 rows); scrolled to 0, 13, 50, 77 and 100 %; 72 rendered rows compared with the position and size computed from gantt.getChildren, no mismatch.
  • Filter, same script: the 12-task chart with onBeforeTaskDisplay hiding in turn Design and Release, Test, Project B, then nothing, repainted with gantt.render() or gantt.refreshData(); and the 2,600-row chart with every third id hidden, at three scroll positions. No mismatch. Also after gantt.addTask, gantt.deleteTask, gantt.moveTask and gantt.sort: no mismatch.
  • npm run build, npm run lint and npm run test (128 samples) pass on 09c624a.

The checking script is not part of the branch (the repository's test suite is the sample smoke test); I can share it.

Not checked with other screen readers or browsers. Smart rendering and the filter were not checked with a screen reader.

With smart rendering only the rows in view are in the DOM, and
onBeforeTaskDisplay can hide some of them, so a screen reader that
counts the rows in the DOM reports a wrong position and size. Each row
now states its position among the displayed siblings.
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