Repository navigation
Added accessible names and descriptions to the graph SVG and hid its decorative parts from screen readers - #1850
Open
danielrafailov wants to merge 4 commits into
Open
danielrafailov wants to merge 4 commits into
danielrafailov wants to merge 4 commits into
Conversation
…decorative parts from screen readers
Coverage Report for CI Build 46960897288Coverage increased (+0.2%) to 63.296%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
8 tasks done
david-yz-liu
reviewed
Dec 2, 2026
| onTouchStart={onTouchStart} | ||
| > | ||
| <defs> | ||
| {/* A <desc> is automatically the description of its parent <svg>. Don't also |
Contributor
There was a problem hiding this comment.
I don't think this comment is very helpful, please remove it and just keep the code change
| transform={props.transform} | ||
| > | ||
| {ellipse} | ||
| {/* The box is decorative (the text is read instead). Without aria-hidden, |
Contributor
There was a problem hiding this comment.
Hm I don't think this is the best approach for nodes. Rather, I'd prefer adding an aria-label to the containing <g> that contains the text of the node and prevent navigation into the <g> contents entirely. I think we did this with the MemoryViz svgs, if I remember correctly.
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.
Proposed Changes
The second of the graph accessibility PRs, following the graph controls in #1849. This one covers the graph SVG itself. Before this change, VoiceOver never announced the graph as a graph, since the root
<svg>had no name, description or role. Instead it read the area labels, every "and"/"or", the hybrid nodes and the course codes as one flat list, with nothing to separate them.Changes:
a11y.tsmodule, following the feedback on the memory-viz accessibility PRs to keep the strings in a constant map with a separate helper module:GRAPH_A11Y_TEXTholds all the text read out for the graph.getGraphA11yNamenames the graph after the displayed graph (e.g. "Computer Science prerequisite graph"), falling back to "Prerequisite graph" when there's no name (e.g. on the Generate page).getGraphA11yDescriptionbuilds the description, giving the first two of the graph's own area labels as examples: "Courses are shown as boxes, grouped into labelled areas, such as Mathematics and Statistics, and Introductory Courses. Arrows point from each course to the courses that require it as a prerequisite." It skips continuation lines like "and Computer Graphics", and leaves the examples out for graphs with no area labels, such as Statistics.getNodeA11yLabelbuilds each node's name from its text, joining text split over several lines (e.g. "MAT224H1/" and "MAT247H1" become "MAT224H1/MAT247H1").GraphCanvas.tsx: the root<svg>now hasrole="graphics-document", anaria-labeland a<desc>. The<defs>(filters and arrowhead marker) isaria-hidden.Graph.js:role="group"), so VoiceOver announces e.g. "Course areas, group" … "end of, Course areas, group".aria-hidden. An "and" or "or" read on its own, away from the courses it connects, is meaningless.aria-hidden; the area labels stay readable.Node.tsx: each course and hybrid node's<g>hasrole="img"and anaria-labelwith the node's text, so screen readers read it as one item and don't navigate into its box, text or spotlight.a11y.test.js: the name, description and node label helpers, including the real Computer Science labels, no labels (Statistics), a label split over two lines, labels starting with a number, and node text split over several lines.GraphCanvas.test.js: the role, name and<desc>, noaria-describedby(see below), and hidden<defs>.Graph.test.js: the graph's name and description (including a graph with area labels), the two group labels, the hidden and/or and arrow groups, hidden region shapes with readable labels, course and hybrid nodes labelled with their text as a single image, and the spotlight kept inside the labelled node.Notes on the implementation:
aria-labelrather than SVG<title>elements, because browsers show a<title>as a hover tooltip over everything inside it, so "Computer Science prerequisite graph" would pop up whenever the mouse rests on the graph.<desc>alone, without also linking it witharia-describedby. With both, Safari exposed the description twice and VoiceOver read it twice. I confirmed in Safari that removingaria-describedbyfixes this.role="graphics-document", Safari started exposing unnamed SVG shapes that it ignored before: each node's box was announced as "image", and each highlighted node's spotlight as "clickable, image", before the node's text. Each node is now a singlerole="img"labelled with its text, so screen readers don't see its box or spotlight at all.role="img"is used because a labelled<g>would otherwise be a group that VoiceOver can still navigate into. When nodes become keyboard accessible, course nodes can switch torole="button", which also hides its contents. Hybrid nodes aren't clickable, so they stayimg.I tested with VoiceOver in Safari and with Chrome's Accessibility pane. Nothing changes visually.
Screenshots of your changes (if applicable)
Chrome Accessibility pane for the graph




<svg>, before the change (no name or description):Chrome Accessibility pane for the graph
<svg>, after the change (name and description):VoiceOver reading the graph's description, after the change:
Chrome accessibility tree, before the change:
Chrome accessibility tree, after the change:
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments