Repository navigation
Set aria-posinset and aria-setsize on grid rows - #159
Open
stepan-kuntso wants to merge 1 commit into
Open
stepan-kuntso wants to merge 1 commit into
stepan-kuntso wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same area as #156 (ARIA attributes for screen readers).
What is broken
Grid rows are
role="row"in arole="treegrid"witharia-level, but have noaria-posinsetoraria-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: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
masterat 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:
taskRowAttris 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_navigationon, nothing else), each built from one commit. Both are 10.0.3 builds, the ones used in the NVDA session:master67d4425 (10.0.3): https://stepan-kuntso.github.io/gantt/before.htmlWith NVDA running, on each page:
Cause
src/core/ui/wai_aria.js,taskRowAttr, setsaria-level,aria-selectedandaria-expanded, but notaria-posinsetandaria-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 whengantt.getGlobalTaskIndex(id) > -1, which is the order the grid renders) and setaria-posinset(the task's position among them) andaria-setsize(their number). 18 lines in one function, existing public methods only. Like every_waiAriamethod, nothing is added whenwai_aria_attributesis 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"):
onBeforeTaskDisplayfilter: 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: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 ofgantt.render(), then the average of 20 calls timed withperformance.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
after.htmlhavearia-posinset/aria-setsize1/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. Onbefore.htmlthe rows have neither attribute.gantt.close/gantt.open; on 10.0.4 neither attribute.gantt.getChildren, no mismatch.onBeforeTaskDisplayhiding in turn Design and Release, Test, Project B, then nothing, repainted withgantt.render()organtt.refreshData(); and the 2,600-row chart with every third id hidden, at three scroll positions. No mismatch. Also aftergantt.addTask,gantt.deleteTask,gantt.moveTaskandgantt.sort: no mismatch.npm run build,npm run lintandnpm 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.