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
- The canvas is
<svg tabindex="0" role="application">, labelled bydiagramLabelandaria-describedbya visually hiddenkeyboardHint. As an application, NVDA and JAWS pass the arrow and letter keys to it without a switch to focus mode; reading happens in the outline, after it, soapplication's usual cost (no reading commands inside it) takes nothing away. That NVDA, JAWS and VoiceOver do so is a check by hand. - Every node and connector group is
aria-hiddenand has noroleoraria-label, and so are the adorners and the preview layer: culling then never changes the tree, and browse mode doesn't read the shapes before the outline repeats them. The item under the text editor is the exception: its group dropsaria-hiddenwhile the editor is open, since the focused<textarea>(labelledtextEditorLabel) lives in its<foreignObject>. That is why the groups carry it, not the world layer.
Descriptions
- A node:
{nodeLabel}, {nodeConnections}, asDiamond: In stock?, 2 connections. - A connector:
connectorDescription({type} from {from} to {to}) or, with a label,connectorDescriptionLabelled;{type}isconnectorType.<kind>, and a free end readsfreeEnd.
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:
Nselects its next connector,Pits previous one, clockwise by the direction from its centre to the connector's other end, from 12 o'clock (ties by id), wrapping; the node becomes the anchor. They are matched bykey, any case, with no Ctrl, Cmd or Alt: a letter is one key on every Latin layout, where]is the+key (zoom in) on Italian and German layouts.- With a walked connector selected,
NandPgo on through the anchor's connectors;Jselects its other end (a free end: nothing), which becomes the focus node, revealed and announced; the arrows act from the anchor; Escape selects the anchor again, and a second Escape clears the selection. - A walked connector takes the existing keys: Delete removes it (after
vn-diagram-removing), Enter or F2 edits its label. A node without connectors:NandPsaynodeConnectionswith 0 and select nothing. - Any other selection change (a pointer, the API) drops the anchor.
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:
- one
<li>per top-level node in reading order (the top of its box, then its start in the page's direction), its text the node's description and its connections, clockwise asNwalks them:Rectangle: Check stock, 2 connections: to Pack order (Yes); from Start(outlineTo,outlineFrom; a connector's label in parentheses); - a container's
<li>holds a nested<ul>of its children, in the same order; - every node, drawn or not: it reads the model.
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.