- Docs
- enzUI framework
- Developers
Accessibility and keyboard
The AT-SPI bridge, keyboard traversal and focus, live regions, desktop accessibility preferences, and how to test them.
Every enzUI widget publishes its role, name, value and state to assistive technology and can be reached from the keyboard. Screen readers see the tree through AccessKit, bridged to AT-SPI. Most of this needs no app code; this page covers the parts an app does own, and how to check them.
The accessibility bridge
enzui_widgets::app_setup::run installs the accessibility collector and request bridge when enzui-core's accesskit feature is on. The app owns the route that lets a screen reader act on widgets:
// in subscription():
enzui_core::app_runtime::accessibility_wake_subscription(Message::A11yWake)
// in update():
let task = match message {
Message::A11yWake(receipt) => apply_accessibility_wake(receipt),
// ... the app's other messages
};
Task::batch([task, apply_pending_accessibility_actions()])These helpers from enzui_widgets::a11y_actions apply the same widget operations that pointer and keyboard input use, in the window that asked. Do not install iced's tree builder or request handler separately; the runtime rejects a competing owner. The full counter is on Building an app.
Names and identity
- Controls take their accessible name from their label. Icon-only buttons need one:
enz_toolbar_icon(..).label(..)sets the name and tooltip together. - Give controls stable ids with
.id(Id::new(..))when their labels are translated, so identity does not follow the displayed text. enz_image(..).alt_text(..),enz_animated_svg(..).label(..)andcanvas_view::enz_canvasname pictures and drawings.- Text that elides publishes its full value, so a screen reader still reads it whole.
Warnings under the enzui::a11y log target (on by default) name controls that share an id or have no name.
Keyboard traversal
app_setup::run installs Tab and Shift+Tab traversal. It handles bare Tab and Shift+Tab that no widget consumed, wraps at both ends, and targets the window that produced the key. A focused editor or modal that captures Tab keeps it, and Ctrl, Alt and Logo chords stay available to the app. iced's stock focus_next / focus_previous can leave no control focused at an end; the framework's traversal does not.
- A terminal or editor that needs Tab can move chrome navigation to a chord:
app_setup::run_with_traversal(program, TraversalBinding::Chord(my_decode)), for example Ctrl+F6 and Ctrl+Shift+F6. TraversalBinding::Disabledis only for a host that owns the whole traversal route.- A host with its own event loop composes
app_setup::with_focus_traversal(program, binding)withenzui_core::app_runtime::run.
Traversal scrolls the destination into view through enclosing scroll viewports. For programmatic navigation, use focus::focus_and_reveal_id in a window-scoped task; focus::reveal_id_all and focus::reveal_focused_all reveal without moving focus.
Focused radio groups, sliders, tab strips, trees and lists handle their own arrow keys, and Enter and Space activation belongs to the widget. Dialogs move focus in when opened and return it to the invoker when dismissed; see Dialogs, menus and popovers.
Access keys
.mnemonic(true) on a builder underlines the letter after _ in its label ("_Save"), and Alt plus that letter activates it. menu_bar supports access keys and F10.
Announcements and structure
- Live regions:
enzui_core::live_regionnames the vocabulary (status or alert, polite or assertive) for regions whose changes a screen reader should read. Toasts, banners and status dots already publish live-region roles keyed off their tone, so a status shown in a toast needs nothing more. - Headings:
heading_outlinedescribes the document outline a frame publishes and audits it: one page-level heading per screen, no skipped levels, every heading named. - Alerts:
enz_confirm_dialogmakes alert status explicit; a destructive tone does not make a dialog an alert.
Following the user's preferences
With ThemeIntegration the app follows the desktop's accessibility settings without code:
| Preference | Effect |
|---|---|
| High contrast | Every palette becomes Palette::high_contrast(); accent, state colours and focus ring reach 7:1, glass turns opaque, grain disappears |
| Reduced motion | Every widget lands its changes at once; animated images and SVG show their first frame |
| Text size | typography.text_scale multiplies every text rung |
| Reduced transparency | Glass paints its opaque panel |
The theme file's stroke.focus_ring widens focus rings for every app (the default is 2). See Theme file.
Right-to-left layouts mirror the app shell and most widgets while focus and accessibility order stay logical; see Localization.
Inspecting a running app
ENZUI_DIAGNOSTICS=1paints accessibility findings over the window (elided text, and controls wrapped in hit-target or contrast probes), plus layout-spill and overlap findings, and logs one report underenzui::trace::diagnostics.- Any AT-SPI inspector, such as Accerciser or Orca's flat review, shows what a screen reader reads.
Testing
The same tree is available headlessly. With enzui-core's test-frame feature in dev-dependencies:
collect_frame(view, size)returns the accessibility tree; assert roles, names, values and states.AccessibilityScanCollectorruns theENZUI_DIAGNOSTICSaudit as a test, finding targets under 24 px (HitTargetScanProbe) and text below its contrast ratio (ContrastScanProbe).
The traversal test helper
enzui_core::keyboard_traversal_validation drives an app's real update, view and subscription with Tab presses and reads back which control holds focus. Implement KeyboardTraversalHost for your app, then call assert_tab_moves_focus(&mut host, size), or wrap::assert_traversal_wraps(&mut host, size, &keys) to also prove the ring wraps at both ends.
This test, from the repository, checks the counter on Building an app through the setup route's traversal:
use enzui_core::focus_traversal::Traversing;
use enzui_core::keyboard_traversal_validation::KeyboardTraversalHost;
use enzui_core::keyboard_traversal_validation::wrap::{TraversalKeys, assert_traversal_wraps};
use enzui_widgets::app_setup::{TraversalBinding, with_focus_traversal};
use iced::Program;
struct Counter<P> {
program: P,
state: App,
window: iced::window::Id,
}
impl<P> KeyboardTraversalHost for Counter<P>
where
P: Program<State = App, Message = Traversing<Message>>,
{
type Message = Traversing<Message>;
type Theme = iced::Theme;
fn subscription(&self) -> iced::Subscription<Self::Message> {
self.program.subscription(&self.state)
}
fn update(&mut self, message: Self::Message) -> iced::Task<Self::Message> {
self.program.update(&mut self.state, message)
}
fn view(&self) -> iced::Element<'_, Self::Message, iced::Theme, iced_test::renderer::Renderer> {
self.state.view().map(Traversing::User)
}
fn window(&self) -> Option<iced::window::Id> {
Some(self.window)
}
}
let program = with_focus_traversal(
iced::application(App::new, App::update, App::view)
.title("Counter")
.theme(App::theme)
.subscription(App::subscription),
TraversalBinding::default(),
);
let (state, _boot) = program.boot();
let mut host = Counter { program, state, window: iced::window::Id::unique() };
let report = assert_traversal_wraps(
&mut host,
iced::Size::new(600.0, 400.0),
&TraversalKeys::tab().expecting_message("Traverse"),
);
assert_eq!(report.focusables, 2);Without the setup route's traversal, the app decodes nothing for Tab and the assertion fails. More testing helpers are on Testing.