Repository navigation
Added accessible names and descriptions to the graph SVG and hid its decorative parts from screen readers - #1850
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 |
| onTouchStart={onTouchStart} | ||
| > | ||
| <defs> | ||
| {/* A <desc> is automatically the description of its parent <svg>. Don't also |
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, |
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.
There was a problem hiding this comment.
Each node's <g> now has role="img" with an aria-label of the node's text (e.g. "MAT224H1/MAT247H1"), so screen readers read it as one item and don't navigate into its box, text or spotlight (see the last screenshot in the description). That made the aria-hidden on the box and spotlight unnecessary, so I removed those. When nodes become keyboard accessible, the role can change to button, which also keeps its contents hidden.
david-yz-liu
left a comment
There was a problem hiding this comment.
Great, thanks @danielrafailov!
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 Chrome, 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 (each course and hybrid node is a single image, named after its text):
VoiceOver in Chrome after trying to move inside a course (VO-Shift-Down), 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