Getting started
Accessible names
The primitives set no role, no name and no text, so you name the flow, its nodes, edges, handles and buttons, and write the announcements in your own words.
The package ships no text, in any language, so it cannot name anything. No primitive sets an
aria-label, and nodes and edges get no role: aria-roledescription would be text too. What the
package does give is focus (with keyboard(), nodes and edges take tabindex="0", and so do
handles with connection() and resize handles with resize()), the state as attributes, and
events for everything a screen reader user should hear about. The words are yours.
Name the flow and its parts
Every primitive passes its props through to its element, so ARIA goes where you would put it on any element:
<Flow.Root<Types, typeof features>
features={features}
defaultNodes={nodes}
role="group"
aria-label="Delivery workflow"
className="h-96"
>
<Flow.Viewport>
<Flow.Edges<Types>>
{(edge) => (
<Flow.Edge<Types>
edge={edge}
role="group"
aria-roledescription="edge"
aria-label={`${edge.source} to ${edge.target}`}
>
<Flow.EdgePath />
</Flow.Edge>
)}
</Flow.Edges>
<Flow.Nodes<Types>>
{(node) => (
<Flow.Node<Types> node={node} role="group" aria-roledescription="node" aria-label={node.data.label}>
{node.data.label}
<Flow.Handle type="target" side="top" title="Input" />
<Flow.Handle type="source" side="bottom" title="Output" />
</Flow.Node>
)}
</Flow.Nodes>
</Flow.Viewport>
</Flow.Root>Write the roles and names your app's language and your users need: the nodes' and edges' roles
are the announcements example's choice, the root's name is this page's suggestion, and neither
is a rule.
Name the buttons
Flow.ZoomIn, Flow.ZoomOut, Flow.FitView and Flow.ToggleInteractive render only their
children, often an icon: give each one an aria-label, and the group a name.
<Flow.Controls role="group" aria-label="Zoom and lock" className="absolute bottom-3 left-3 flex flex-col">
<Flow.ZoomIn aria-label="Zoom in">
<PlusIcon />
</Flow.ZoomIn>
<Flow.ZoomOut aria-label="Zoom out">
<MinusIcon />
</Flow.ZoomOut>
<Flow.FitView aria-label="Fit view">
<MaximizeIcon />
</Flow.FitView>
<Flow.ToggleInteractive aria-label="Lock the flow">
<LockIcon />
</Flow.ToggleInteractive>
</Flow.Controls>Flow.ToggleInteractive sets aria-pressed while the flow is locked; the buttons set disabled
while their action is refused (a zoom at its limit). The minimap is an SVG: give MiniMap a
role="img" and an aria-label when it should be announced.
Announce what happens
The engine tells what happened on screen through engine.subscribe, as events with ids and no
text: nodes-move (with source: "pointer" or "keyboard"), drag-cancel, connect,
connect-cancel (with refused), connect-target (each target of a keyboard connection, its
index of count), reconnect, resize, box-select, remove, and more
(Engine). Turn the ones your users need into words, and write them into a live
region of your own:
import { type FlowEngineEvent, type FlowModel, useFlow } from "@fragiola/flow-react";
import { useEffect, useState } from "react";
type Model = FlowModel<Types, typeof features>;
/** The app's words for an engine event, or nothing for one it keeps quiet about. */
function describe(event: FlowEngineEvent, model: Model): string | undefined {
const name = (id: string) => model.get("node-by", { id })?.data.label ?? id;
switch (event.type) {
case "nodes-move":
return `Moved ${event.nodeIds.map(name).join(", ")}.`;
case "connect":
return `Connected ${name(event.source)} to ${name(event.target)}.`;
case "connect-cancel":
return event.refused ? "That connection is not allowed." : undefined;
case "remove":
return `Removed ${event.nodeIds.length} node(s) and ${event.edgeIds.length} edge(s).`;
default:
return undefined;
}
}
export function LiveRegion() {
const { model, engine } = useFlow<Types, typeof features>();
const [message, setMessage] = useState("");
useEffect(
() =>
engine.subscribe((event) => {
const text = describe(event, model);
if (text) setMessage(text);
}),
[model, engine],
);
return (
<p role="status" className="sr-only">
{message}
</p>
);
}Render LiveRegion (live-region.vue, live-region.svelte, live-region.ts) inside Flow.Root: it reads the root's engine with
useFlow. The events
carry ids, so the words can name the nodes the way your app names them, in its language.
Keyboard users
With keyboard(), Tab reaches every node and edge, the arrows move the selection (or the focused
node), Shift with an arrow moves it further, Enter or Space selects, Delete and Backspace remove,
Escape cancels a gesture and clears the selection. With connection() too, Tab reaches the
handles and Enter on one draws an edge; with resize(), the arrows on a focused resize handle
resize its node. See Keyboard and accessibility. Give focused nodes,
edges and handles a visible focus style: focus-visible: is enough, the element is the one that
takes focus. A focusable handle is read by its name: give it one (the title above, or an
aria-label), and never aria-hidden.