A11yTree - v0.7.1
    Preparing search index...

    A11yTree - v0.7.1

    A11yTree

    Accessibility for any React component.

    Build a parallel DOM accessibility tree for UIs that render outside the DOM: WebGL canvases, react-three-fiber scenes, Pixi stages, game UIs. Components declare accessible markup wherever they live in the scene graph; it tunnels into a screenreader-friendly DOM tree that mirrors the scene.

    Docs | Github | NPM

    npm i a11y-tree fiber-tunnel
    

    Requires React 19.2 or later.

    <A11yTreeProvider>
    <FiberAnchor>
    <Canvas fallback={<A11yTreeRenderer />}>
    <A11yTreeContainer
    render={(content) => (
    <div role="listbox" aria-label="Hand">
    {content}
    </div>
    )}
    >
    <Card3D>
    <A11yTreeElement>
    <div role="option">Ace of Spades</div>
    </A11yTreeElement>
    </Card3D>
    </A11yTreeContainer>
    </Canvas>
    </FiberAnchor>
    </A11yTreeProvider>

    The a11y tree mirrors the scene hierarchy:

    <div role="listbox" aria-label="Hand">
    <div role="option">Ace of Spades</div>
    </div>

    For lists whose items move: nodes keep their state, DOM node and focus across reorders and moves between lists.

    const renderHand = (List) => <List as="ul" aria-label="Hand" />;

    const hand = useA11yTreeOutlet();
    const nodes = cards.map((card) => ({ key: card.id, props: card }));

    <A11yTreeMirror
    lists={[{ id: "hand", outlet: hand, nodes, render: renderHand }]}
    nodeElement="li"
    >
    <A11yTreeOutlet outlet={hand} />
    {cards.map((card) => (
    <A11yTreeMirrorIn key={card.id} nodeKey={card.id}>
    <Card3D card={card} />
    </A11yTreeMirrorIn>
    ))}
    </A11yTreeMirror>;
    • Lists follow their outlet's visibility and tree order.
    • React events from a node bubble to the mirror, skipping its list: handle them in renderNode, or add native listeners to the list.
    • Keep render and renderNode stable to avoid re-renders.

    A11yTreeRenderer catches errors from tunneled content and shows a dismissible dialog; its fallback prop replaces the dialog.

    The tree is built on fiber-tunnel, which orders content by React tree position.

    See examples on the documentation website

    pnpm install
    pnpm dev

    This project uses React Compiler.