Screen Readers Implementation in Vanilla-Diagram

A drawing isn't read shape by shape: with culling (14-large-diagrams) most shapes aren't even in the DOM. So the shapes stay out of the accessibility tree, and two visually hidden parts, outside the SVG, are the accessible view: the announcer, which says what the keys and the changes did, and the outline, which lists the nodes and their connections for browse mode.

The canvas and the tree

Descriptions

The announcer

A <div class="vn-diagram-announcer" role="status"> in .vn-diagram-root, styled as the Gantt's announcer. Its text is set with textContent, never as HTML. Several messages in one frame: the last one wins. The same text twice in a row is said again: the region is emptied, then set in the next frame.

When Text
A keyboard selection of one node (the arrows, J, Escape back to the anchor) The node's description
N or P announceConnection: Connector {index} of {count}: {connector}
The keyboard brings focus to the canvas (:focus-visible) The focus node's description, else announceDiagram
A committed change, from any source (api too: the toolbar's Delete and Tidy up) An undo or redo: announceUndone / announceRedone with the command's label; a move of one node (a nudge burst too): announceMoved with its top-left, rounded; a connect: announceConnected; anything else: the command's label
vn-diagram-save-failed announceSaveFailed with the failed change's label
C; an arrow in connect mode announceConnectMode; announceTarget

A pointer selection says nothing, as in the Gantt. The message overlay (.vn-diagram-message: the busy overlay's label, loading, arranging or exporting, and the load error) keeps its own role="status", so the label is said when the overlay shows, as a job begins. The spinner is aria-hidden. No aria-busy is set on the canvas: the label says the job, and on a role="application" element aria-busy might make a reader stop reading its content.

Walking connections

With a focus node:

So a connector can be selected from the keyboard (WCAG 2.1.1). Read-only: walking and J work; Delete and Enter don't.

The outline

A visually hidden <div class="vn-diagram-outline"> after the SVG, holding a <ul> named outlineLabel:

It follows committed changes, never a preview: the nodes an effect touched and the nodes at the other end of their connectors are written again (a moved node's item goes to its new place by a binary search of its list), a removed one's item goes. A change touching more than a quarter of the nodes (a load, a layout) rebuilds it, 256 items a frame: each item costs the browser layout, about 20µs, so 10,000 at once would block for 200ms. Text goes in with textContent.

The cap: up to 10,000 nodes it lists every one; above, it is one item, outlineTooLarge, and the keys and the announcer are the way in (a 100,000-item list can't be read through in browse mode). A change that crosses the cap, either way, rebuilds it.

Messages

Every text above is a message key of the en bundle (other locales fall back to it), with {count} and no plural forms, as the command labels: nodeConnections, connectorDescription, connectorDescriptionLabelled, freeEnd, announceConnection, announceMoved, announceConnected, announceUndone, announceRedone, announceSaveFailed, announceConnectMode, announceTarget, announceDiagram, keyboardHint, outlineLabel, outlineTooLarge, outlineTo, outlineFrom.