Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
///
/// ```
Expand Down
40 changes: 40 additions & 0 deletions tests/it/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading