Skip to content

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
Courseography:masterfrom
danielrafailov:graph-svg-titles
Open

danielrafailov wants to merge 4 commits into
Courseography:masterfrom
danielrafailov:graph-svg-titles

Conversation

@danielrafailov

@danielrafailov danielrafailov commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • New a11y.ts module, following the feedback on the memory-viz accessibility PRs to keep the strings in a constant map with a separate helper module:
    • GRAPH_A11Y_TEXT holds all the text read out for the graph.
    • getGraphA11yName names 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).
    • getGraphA11yDescription builds 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.
    • getNodeA11yLabel builds 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 has role="graphics-document", an aria-label and a <desc>. The <defs> (filters and arrowhead marker) is aria-hidden.
  • Graph.js:
    • The regions group is labelled "Course areas" and the nodes group "Courses" (role="group"), so VoiceOver announces e.g. "Course areas, group" … "end of, Course areas, group".
    • The and/or group and the arrows group are aria-hidden. An "and" or "or" read on its own, away from the courses it connects, is meaningless.
    • The region shapes are aria-hidden; the area labels stay readable.
  • Node.tsx: each course and hybrid node's <g> has role="img" and an aria-label with the node's text, so screen readers read it as one item and don't navigate into its box, text or spotlight.
  • Tests:
    • 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>, no aria-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.
    • Updated the Graph and Node snapshots, which only change by the new attributes.

Notes on the implementation:

  • The names use aria-label rather 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.
  • The description relies on the <desc> alone, without also linking it with aria-describedby. With both, Safari exposed the description twice and VoiceOver read it twice. I confirmed in Safari that removing aria-describedby fixes this.
  • With 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 single role="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 to role="button", which also hides its contents. Hybrid nodes aren't clickable, so they stay img.

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):
Screenshot 2026-11-30 at 10 03 20 PM
Chrome Accessibility pane for the graph <svg>, after the change (name and description):
Screenshot 2026-11-30 at 10 03 57 PM
VoiceOver reading the graph's description, after the change:
Screenshot 2026-11-30 at 10 29 31 PM
Chrome accessibility tree, before the change:
Screenshot 2026-11-30 at 10 21 09 PM
Chrome accessibility tree, after the change:

Screenshot 2026-11-30 at 10 11 19 PM

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
✨ New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

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:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CI checks have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

  • Until the per-node descriptions (the next PR) are in, the prerequisite logic isn't available to screen readers at all, since the and/or nodes are now hidden. Before, it was read out, but as isolated "and"/"or" fragments that didn't make sense. The plan is to describe each course's prerequisites in its own description.
  • The area labels and the courses are separate groups in the SVG, linked only by their position on screen, so a screen reader user can't tell which courses are in which area. I'd like to include each course's area in its description in the next PR (e.g. "CSC373H1, Theory of Computing, …").
  • "Human-Computer Interaction and Computer Graphics" is stored as two separate labels, so VoiceOver reads it as two items. I left this alone since it would need a change to how the labels are rendered, but I can look into it if you'd like.

@coveralls

coveralls commented Dec 1, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 46960897288

Coverage increased (+0.2%) to 63.296%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 14 of 14 lines across 3 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4347
Covered Lines: 2796
Line Coverage: 64.32%
Relevant Branches: 1023
Covered Branches: 603
Branch Coverage: 58.94%
Branches in Coverage %: Yes
Coverage Strength: 155.59 hits per line

💛 - Coveralls

Comment thread js/components/graph/GraphCanvas.tsx Outdated
onTouchStart={onTouchStart}
>
<defs>
{/* A <desc> is automatically the description of its parent <svg>. Don't also

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is very helpful, please remove it and just keep the code change

Comment thread js/components/graph/Node.tsx Outdated
transform={props.transform}
>
{ellipse}
{/* The box is decorative (the text is read instead). Without aria-hidden,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

3 participants