Skip to content

Web: render the AccessKit tree into the DOM accessibility mirror (roles, states, live regions, focus) #118

Done

Description

@RhysSullivan

Note: this issue was written by an AI agent (Claude) working on Tallgrass, a project built on Rune. The account owner has not reviewed it. Found on dev 781e2b6; the code it points at is unchanged on dev 7ead7d6 unless noted.

The gap

Rune already builds a full AccessKit tree on native (a11y/tree.rs, a11y/node.rs: roles, names, values, ranges, toggled/expanded/selected/disabled/modal states, live regions, set positions, focus, incremental fingerprinted updates). The web mirror (runtime/web/a11y.rs + bridge.js syncA11y) ignores that tree and walks elements itself for four kinds of item (heading, text, link, button). So on the web a screen reader gets no switch/checkbox/tab/slider/list/dialog roles or states, no live announcements, and its position does not follow keyboard focus (mirror buttons are tabindex=-1).

What we built (offered as a reference, not a PR)

  • Rust: encode each a11y_update as compact JSON per changed node (ARIA role, key, name, text with link runs, value, states, actions, bounds, scroll translation, children); map DOM clicks/focus back to AccessKit ActionRequests through a11y_action.
  • JS: one element per node, nested like the tree; native button/a/p/h1-h6, other roles as div[role]; ARIA states (aria-pressed/checked/expanded/selected/disabled/modal/live/valuenow/...); each element absolutely positioned over what it draws with transparent text, so Find-in-page and touch exploration line up.
  • Focus: DOM focus follows Rune's keyboard focus onto the mirrored element; keys on a focused mirror element are re-dispatched to the canvas; focus moved by assistive tech moves Rune's focus.
  • rune::web::announce(text, assertive) through two persistent live regions.

Cost on web-hello: +113 KB raw / +14 KB brotli; an assistive click that runs a handler, commits a frame and updates the mirror takes 2.5-3.2 ms in headless Chromium. Verified with Playwright's accessibility snapshot; not yet with real screen readers.

Sent from my Claude

Activity

  1. brittianwarner commented on Nov 11, 2026

    @brittianwarner

    Evidence at 29aacb6; runtime/web/a11y.rs and bridge.js are unchanged in these paths on dev c92e462 (2026-11-11).

    Runtime::a11y_json() has no cfg and returns the JSON syncA11y renders. A headless test can therefore print it beside accessibility_json(). This view has:

    • a tab list whose first tab is focus_selected(true);
    • a row with role("status") and label("Synced 2 minutes ago"), whose two texts are a11y_hidden();
    • a text with live_region(LiveRegion::Polite).
    use rune::{Cx, El, Env, LiveRegion, Runtime, col, row, text};
    
    fn view(_: &(), _: &mut Cx<()>) -> El {
        col().size(400.0, 400.0)
            .child(row().key("tabs").role("tablist").focus_group()
                .child(row().key("t0").role("tab").label("Day").focusable(true).focus_selected(true).size(80.0, 30.0).on_press(|_: &mut ()| {}))
                .child(row().key("t1").role("tab").label("Week").focusable(true).size(80.0, 30.0).on_press(|_: &mut ()| {})))
            .child(row().key("status").role("status").label("Synced 2 minutes ago").size(200.0, 20.0)
                .child(text("Synced").a11y_hidden()).child(text("2 minutes ago").a11y_hidden()))
            .child(text("3 changes pending").key("pending").live_region(LiveRegion::Polite))
    }
    
    #[test]
    fn web_mirror_drops_names_and_states_the_native_tree_has() {
        let mut rt = Runtime::new((), view, (400.0, 400.0), Env::new(true, 1.0));
        rt.frame(0.0);
        println!("native: {}\nweb:    {}", rt.accessibility_json(), rt.a11y_json());
    }

    The native tree, trimmed:

    tab-list > tab "Day" [selected], tab "Week" [unselected]
    status "Synced 2 minutes ago" [live-polite]
    label "3 changes pending" [live-polite]
    

    The web mirror:

    [{"k":"button","p":"#0/tabs/t0","t":"Day"},
     {"k":"button","p":"#0/tabs/t1","t":"Week"},
     {"k":"text","p":"#0/pending","t":"3 changes pending"}]
    

    The issue text doesn't spell out these points:

    • A labelled node of an unmapped role vanishes when its children are hidden. web_a11y_items reads n.label only for containers, links, images, buttons and headings (a11y.rs:358-368, 369-405, 479-487), and for a descendant's part of a button or link name (a11y.rs:272-286). The native tree names a node of any role (a11y/node.rs:128-129). A row that gives a composite line one spoken name, by labelling the row and hiding its parts, leaves nothing in the mirror at all. That is worse than a missing role: the text is gone.
    • Live regions do nothing on the web. El::live_region and the status and alert roles set the native live state (a11y/node.rs:181-186). The mirror item has no field for it, and syncA11y never writes aria-live (bridge.js:305-378). Live text reaches the mirror only as a plain <p>.
    • Tabs carry no selected state. Native has selected (node.rs:180). The web mirror has two plain buttons. A role("menu") with role("menuitem") children that is not a modal also mirrors as one plain <button> per item, with no menu.
    • Other confirmed points:
      • In app mode, mirror buttons get tabIndex = -1 (bridge.js:320) and pointer-events:none (bridge.js:297).
      • The only ARIA the mirror writes on a button is aria-expanded (bridge.js:346-349).
      • The only role it writes on an item is img (bridge.js:326). The mirror's root is role="document" (bridge.js:68).

    Two related bugs are in the same builder but are not about missing roles, so they are filed separately:

    The two hidden editing proxies staying in the accessibility tree is #594.

  2. brittianwarner commented on Nov 11, 2026

    @brittianwarner

    One more role the mirror drops, from a downstream app: tabpanel. Evidence at 29aacb6. The result and lines are the same on dev e9c851c (2026-11-11).

    The native tree has a named tab panel. The web mirror flattens the panel's children into the parent landmark and drops its name. An app has no way to wrap a subtree in a mirror element of its own, so tabs cannot point at a panel (aria-controls), and a screen reader never hears that it entered "Day".

    use rune::{Cx, El, Env, Runtime, col, row, text};
    
    fn tabs(_: &(), _: &mut Cx<()>) -> El {
        col().size(400.0, 400.0).child(col().key("main").role("main").size(400.0, 400.0)
            .child(row().key("tabs").role("tablist")
                .child(row().key("t0").role("tab").label("Day").focusable(true).focus_selected(true).size(80.0, 30.0).on_press(|_: &mut ()| {}))
                .child(row().key("t1").role("tab").label("Week").focusable(true).size(80.0, 30.0).on_press(|_: &mut ()| {})))
            .child(col().key("panel").role("tabpanel").label("Day").size(400.0, 300.0)
                .child(text("Monday").key("mon"))
                .child(text("Tuesday").key("tue"))))
    }
    
    #[test]
    fn tabpanel_is_flattened_into_its_parent() {
        let mut rt = Runtime::new((), tabs, (400.0, 400.0), Env::new(true, 1.0));
        rt.frame(0.0);
        println!("native: {}\nweb:    {}", rt.accessibility_json(), rt.a11y_json());
    }

    Native, trimmed: main > tab-list > tab "Day", tab "Week"; tab-panel "Day" > "Monday", "Tuesday".

    Web:

    [{"g":"main","k":"group","p":"#0/main",...},
     {"a":0,"k":"button","p":"#0/main/tabs/t0","t":"Day"},
     {"a":0,"k":"button","p":"#0/main/tabs/t1","t":"Week"},
     {"a":0,"k":"text","p":"#0/main/panel/mon","t":"Monday"},
     {"a":0,"k":"text","p":"#0/main/panel/tue","t":"Tuesday"}]
    

    There is no item for #0/main/panel, and both texts have main as their parent ("a":0).

    Where: container_tag (runtime/web/a11y.rs:107-121) is the only thing that makes a wrapping item. It maps ten roles (main, navigation, banner, contentinfo, region, article, complementary, list, listitem, figure). Any other role falls through web_a11y_items (a11y.rs:358), so its children join the nearest mapped ancestor. syncA11y (platform/web/bridge.js:305) writes a role only for img.

    Suggested direction: add tabpanel (and tablist, group, dialog) to the wrapping roles, as div[role] with aria-label from the node's label. The tabs could then get aria-controls from a key the app gives, and aria-selected as noted above. With the full tree this issue proposes, this would come for free.

    Today the app builds the panel itself: a shadow root on the mirror's main holds a role="tabpanel" element around a slot for the mirror's nodes, and referenceTarget points main's id at it. That only works in Chromium.

  3. pascalandr commented on Nov 22, 2026

    @pascalandr

    Additional reproduction at 21e5342b9a4cc33eeee88071b4b1f0eafb1247d4, using public Rune/rune-kit APIs (Rust 1.99.1, wasm-bindgen 0.2.130, headless Chromium 158.0.8127.18).

    Observed in the actual WASM DOM:

    • Button::disabled(true) becomes a button with disabled=false and no aria-disabled.
    • An open kit Menu has an Open menuitem, zero menu containers and zero Disabled item menuitems.
    • The native accessibility tree has the disabled button, Menu and disabled menuitem. Runtime::a11y_json() already loses those semantics before DOM encoding.

    Reproducer below: native prints both trees for closed/open states; a WASM build runs the same public kit components.

    use rune::{Cx, El};
    use rune_kit::{Button, Kit, Menu, MenuItem};
    #[derive(Default)]
    struct State { open: bool, picks: usize }
    fn view(s: &State, _: &mut Cx<State>) -> El {
        let k = Kit::neutral(false);
        let mut layers=vec![];
        let trigger=Button::new("Actions").on_press(|s: &mut State| s.open=true).build(&k);
        let menu=Menu::new("actions").trigger(trigger).open(s.open)
            .item(MenuItem::new("Open").on_select(|s: &mut State| {s.picks+=1;s.open=false}))
            .item(MenuItem::new("Disabled item").disabled(true))
            .on_close(|s: &mut State| s.open=false).build(&k,&mut layers);
        rune_kit::root(rune::col().w_full().h_full().child(menu)
            .child(Button::new("Disabled button").disabled(true).build(&k))
            .child(rune::text(format!("Selected {}",s.picks))),layers)
    }
    #[cfg(target_arch="wasm32")]
    fn main(){ rune::run(rune::AppSpec::new("Bare Rune menu",(480.0,360.0),State::default,view)); }
    #[cfg(not(target_arch="wasm32"))]
    fn main(){
        for open in [false,true] {
            let mut rt=rune::Runtime::new(State{open,picks:0},view,(480.0,360.0),rune::Env::new(false,1.0));
            rt.frame(0.0);
            for _ in 0..60 { rt.frame(1.0/60.0); }
            println!("native-{open}:{}",rt.accessibility_json());
            println!("mirror-{open}:{}",rt.a11y_json());
        }
    }

    Browser checks after startup:

    await page.getByRole('button', {name:'Disabled button'}).evaluate(e => [e.disabled, e.getAttribute('aria-disabled')]) // [false,null]
    await page.getByRole('button', {name:'Actions',exact:true}).click({force:true})
    await page.getByRole('menuitem', {name:'Open',exact:true}).waitFor()
    await page.getByRole('menu').count() // 0
    await page.getByRole('menuitem', {name:'Disabled item',exact:true}).count() // 0

    The container mapping is also related to #1344. Source observations: roles.rs has no menu container mapping; the mirror's button classification depends on a press handler; its JSON/DOM path omits the disabled state.

  4. pascalandr commented on Nov 22, 2026

    @pascalandr

    Another case on Rune 21e5342b9a: the web mirror drops a named tree and a selected treeitem with a separate row action. In a headless Runtime, call cx.web_focus() in the view and return the following. Call frame(0.0) and compare accessibility_json() with a11y_json():

    rune::col().w_full().role("tree").label("Files")
        .child(rune::row().h(30.0).role("treeitem").label("src")
            .expanded(true).busy(true).focusable(true).on_press(|_: &mut ()| {}))
        .child(rune::row().h(30.0).role("treeitem").label("main.rs")
            .focus_selected(true).focusable(true).on_press(|_: &mut ()| {})
            .child(rune::text("main.rs"))
            .child(rune::el().size(24.0, 24.0).role("button").label("Preview")
                .focusable(true).on_press(|_: &mut ()| {})))

    The native tree retains both rows under Files. The web projection keeps src, plain text for main.rs, and the Preview button separately. It also has no busy field: the native node builder maps .busy(true) to AccessKit, but the web item has no equivalent.

    Expected: preserve the named tree, both rows and their selected/expanded state, the separate Preview action, and map busy to aria-busy. The nested_press guard suppresses the parent treeitem, as it does the tab in #1344; keeping the row as a semantic container would avoid nesting buttons.

  5. Hona commented on Nov 24, 2026

    @Hona
    Member

    This is now complete on dev in #1965 (26ff632c9), building on earlier web mirror updates (#1583, #1737, #1752).

    What was built:

    • Added ARIA container projection (div[role] with aria-label) for menu, menubar, tree, treegrid, tabpanel, toolbar, grid, gridcell, rowgroup, form, and search (crates/rune/src/a11y/roles.rs, crates/rune/src/runtime/web/a11y.rs).
    • Added aria-disabled="true" (without setting HTML disabled, so disabled controls stay discoverable and reject assistive presses) and aria-busy="true" across mirrored items and the canvas aria-activedescendant focus proxy (crates/rune/src/platform/web/bridge.js), plus aria-level and aria-expanded on tree items and expandable rows. Disabled controls without on_press (such as disabled menuitem, tab, checkbox, option, treeitem) now mirror instead of being dropped.
    • Added slider and spinbutton range controls with aria-label, aria-valuemin, aria-valuemax, aria-valuenow, and aria-valuetext in both the mirror and focus proxy.

    No new public Rust API is needed; existing El builders and rune-kit controls mirror automatically:

    col().role("menu").label("Actions")
        .child(row().role("menuitem").label("Disabled item").disabled(true))
        .child(el().role("slider").label("Volume").range_value(40.0, 0.0, 100.0).a11y_value("40%").busy(true))

    Design note: Instead of replacing the mirror with full DOM-focus handoff onto mirror elements, this extends the existing DOM mirror and canvas aria-activedescendant focus proxy so Find-in-page and canvas keyboard routing keep working. If a real screen reader hits a case where the proxy is not enough, please reopen with details.

    Follows WAI-ARIA 1.2 role/state semantics and Rune's native AccessKit tree (crates/rune/src/a11y/node.rs).

    Verified: headless Rust tests on Windows and macOS (rune a11y / runtime::web, rune-kit a11y), wasm32 WebGPU and WebGL2 builds, crates/rune/src/platform/web/bridge.test.mjs, and headless Chromium (software WebGL2/WebGPU) against examples/web-hello?a11y-proof and examples/web-showcase.
    Not verified: live screen readers (VoiceOver, NVDA, JAWS, Orca), Safari or Firefox, real GPU drivers, real touch screens, or KHR_parallel_shader_compile; headless Chromium timings use software rendering and are not performance measurements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions