Keyboard and accessibilityDiagram
The complete keyboard map, keyboard connect mode, what screen readers announce, the list view fallback and how to keep custom templates accessible.
A diagram is a visual medium, but everything in Birch UI Diagram can be done without a pointer, and screen-reader users can explore the whole structure through the list view.
Structure and focus#
- The root is a
role="application"region with the role description "diagram editor" and yourariaLabel(default "Diagram"). Give each diagram a specific name, such as "Purchase approval workflow". - Every visible node is a focusable
role="button". Its accessible name is built from its label, its type name, its connection count and, for groups, whether it is collapsed and how many children it has: "Manager approval, step, 3 connections". - Nodes share a short description of the keyboard commands, so screen readers can announce how to operate the diagram.
- Focus uses a roving
tabindex: the diagram is one tab stop, Tab and Shift+Tab move between nodes in model order, and Tab on the last node leaves the diagram. Moving focus to a node also selects it, and a node that is off screen is scrolled into view. - Moves, resizes, connections, deletions, layouts, undo and redo are announced in a polite live region, for example "Moved Pick items to 320, 160" or "Connected Payment to Pick items".
- Edges, the grid, the minimap and the selection overlay are hidden from assistive technology; connections are conveyed through each node's description and the list view.
Keyboard map#
| Keys | Action |
|---|---|
| Tab / Shift+Tab | Focus and select the next or previous node. |
| Arrow keys | Move the selected nodes by 1 unit. With nothing selected, pan the view. |
| Shift+arrows | Move by 10 units. |
| Alt+ArrowUp / ArrowDown | Collapse or expand the focused group. |
| Enter or F2 | Edit the label of the focused node, or of the selected edge. |
| C | Start a connection from the focused node. |
| Delete or Backspace | Delete the selection. |
| Escape | Cancel the current drag, or clear the selection. |
| Ctrl/Cmd+A | Select everything. |
| Ctrl/Cmd+C, X, V, D | Copy, cut, paste, duplicate. |
| Ctrl/Cmd+Z | Undo. |
| Ctrl/Cmd+Shift+Z or Ctrl+Y | Redo. |
| + / - | Zoom in or out. |
| Shift+1 / Shift+2 | Fit the whole diagram, or the selection. |
| Space (held) | Drag with the pointer to pan. |
Shortcuts are ignored while focus is in a text field, including the label editor and inputs inside HTML templates. In read-only mode, keys that would change the diagram do nothing, while navigation, selection, copy, zoom and the list view keep working.
Arrow-key moves of the same selection within a second merge into one undo step, so nudging a node into place and undoing it is a single Ctrl+Z.
Connect from the keyboard#
- Focus the source node and press C. The diagram announces "Connecting from Payment".
- Press an arrow key to jump to the nearest node in that direction. The target is outlined green when the connection is allowed and red when it is not, and the live region says "Target Pick items" or "Target Order received, connection not allowed".
- Press Enter to connect, or Escape to cancel.
Keyboard connections go through validateConnection like pointer connections, and emit connect and edgesChange. They connect node to node; to attach an edge to a specific port, edit it afterwards with updateEdge.
List view#
The list view presents the diagram as nested HTML lists instead of a canvas. It opens from the toolbar's list button or with listView: true, and replaces the canvas while it is shown.
- A summary at the top gives the node and connection counts.
- Every node is a button with its label, followed by its type and connection count.
- Under each node, its connections are listed as "to Pick items (approved)" or "from Payment", with edge labels in parentheses. Each connected node is a button too, so users can follow the flow.
- Groups and swimlanes contain their children as nested lists labelled "Inside Finance".
- Activating a node in the list selects it and centers it on the canvas.
const diagram = createDiagram(container, {
nodes,
edges,
ariaLabel: 'Order fulfilment process',
listView: prefersListView(),
});
showAsListButton.addEventListener('click', () => {
diagram.update({ listView: true });
});The list view is also a good default for very large diagrams on small screens, and for read-only reports where the structure matters more than the drawing.
Motion, contrast and themes#
layout({ animate: true })and other transitions are skipped when the user prefers reduced motion.theme: 'auto'followsprefers-color-scheme;'light'and'dark'force a theme. Withouttheme, the diagram inherits the page theme from an ancestor withlq-theme-dark, like the other Birch UI components.- Colors come from the shared
--lq-*tokens and diagram tokens such as--lq-diagram-accent,--lq-diagram-focus,--lq-diagram-selection,--lq-diagram-validand--lq-diagram-invalid. Keep focus and selection colors at a 3:1 contrast ratio against the background if you change them. - Valid and invalid connection targets differ in line style (solid or dashed) as well as color.
Checklist for your diagrams#
- Give every node a meaningful
label. It is the node's accessible name, also when a template draws something else. - Give node types a
labelsuch as'employee'or'server', so the type part of the name means something. - Label edges whose meaning is not obvious ("approved", "replication"). The list view reads them out.
- Do not rely on color alone in templates; add a word or an icon with a text alternative for status.
- Put links and buttons that open details outside templates where possible, and handle
nodeDoubleClickor the context menu instead.
Next steps#
- Interaction for pointer behaviour.
- API and events for
select,editLabelandcenterOn.