diff --git a/src/builder.rs b/src/builder.rs index deaa2d0e..3254c801 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -2244,6 +2244,19 @@ impl<'b, 'f, A: 'static, K> NodeHandle<'b, 'f, A, K> { }) } + /// Makes the node a live region, the `aria-live` of the web: assistive + /// technology announces changes to its content, waiting for a pause in + /// speech when it is [`Polite`](egui::accesskit::Live::Polite). Give it a + /// [`role`](Self::role), such as [`Status`](egui::Role::Status), and a + /// name. + pub fn live(self, live: egui::accesskit::Live) -> Self { + self.draw(move |_, ui| { + let id = ui.node_response().id; + ui.ctx() + .accesskit_node_builder(id, |node| node.set_live(live)); + }) + } + /// TODO(prose): makes the node a group of items the arrow keys move focus through as `nav` says, one Tab stop (the focused item, else the [`selected`](Self::selected) one, else the first enabled); a `Listbox` or `Submenu` nav is reported as [`NavNeedsOverlay`](crate::Problem::NavNeedsOverlay). /// /// ``` diff --git a/tests/it/interaction.rs b/tests/it/interaction.rs index 140ed998..2137f6e9 100644 --- a/tests/it/interaction.rs +++ b/tests/it/interaction.rs @@ -1002,3 +1002,43 @@ fn handlers_compose_in_call_order() { assert_eq!(order[at - 1], "response", "{order:?}"); assert_eq!(order[at - 2], "draw", "{order:?}"); } + +#[test] +fn a_live_node_is_announced_as_a_live_region() { + use egui::accesskit::{Live, Role}; + use egui_kittest::kittest::{NodeT as _, Queryable as _}; + + let harness = crate::support::harness( + vec2(200.0, 100.0), + TextStyle::new( + TextSpec { + size: 16.0, + line_height: 20.0, + family: FontFamily::Proportional, + weight: Weight::Normal, + }, + Color32::BLACK, + ), + (), + |b, _| { + b.div_id("status", tw().sense_hover().w_px(100.0).h_px(40.0), |s| { + s.text(tw(), "Saved"); + }) + .role(egui::Role::Status) + .named("Status") + .live(Live::Polite); + b.div_id("quiet", tw().sense_hover().w_px(100.0).h_px(40.0), |_| {}) + .role(egui::Role::Status) + .named("Quiet"); + }, + ); + let live = |name: &str| { + harness + .get_by_role_and_label(Role::Status, name) + .accesskit_node() + .data() + .live() + }; + assert_eq!(live("Status"), Some(Live::Polite)); + assert_eq!(live("Quiet"), None); +}