From e8e2fd1c401738564453a37d63e1f659329d00e5 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 06:49:57 +0100 Subject: [PATCH] List rows: a group row's triangle is named after the row's accessible name --- crates/ui-widgets/src/list/row/show.rs | 8 ++++++-- crates/ui-widgets/tests/it/list.rs | 27 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/src/list/row/show.rs b/crates/ui-widgets/src/list/row/show.rs index 35ca35602..59ba3bc4b 100644 --- a/crates/ui-widgets/src/list/row/show.rs +++ b/crates/ui-widgets/src/list/row/show.rs @@ -466,7 +466,8 @@ impl Component for ListRow<'_> { access.expanded(open); if !self.disclosure_by_host { let pattern = if open { &words.collapse } else { &words.expand }; - access.node(DISCLOSURE, Role::BUTTON).name = Name::Text(named(pattern, label)); + // the triangle names the row as a screen reader hears it + access.node(DISCLOSURE, Role::BUTTON).name = Name::Text(named(pattern, self.accessible_name.as_deref().unwrap_or(label))); } } let selected = @@ -590,7 +591,10 @@ impl Component for ListRow<'_> { && placed.disclosure.is_some() && !self.disclosure_by_host { - ui.face(DISCLOSURE, Disclosure::new(Bind::given(open)).node(false).label(cx.resolved.label.to_owned())); + ui.face( + DISCLOSURE, + Disclosure::new(Bind::given(open)).node(false).label(self.accessible_name.clone().unwrap_or_else(|| cx.resolved.label.to_owned())), + ); } { let draw = ui.draw(); diff --git a/crates/ui-widgets/tests/it/list.rs b/crates/ui-widgets/tests/it/list.rs index 8d451418d..566608732 100644 --- a/crates/ui-widgets/tests/it/list.rs +++ b/crates/ui-widgets/tests/it/list.rs @@ -1704,6 +1704,33 @@ fn a_filter_matches_any_of_a_rows_texts_and_keeps_the_ancestors_of_a_match() { } } +/// A group row's triangle is named after the row as a screen reader hears it: a row drawn "March" whose accessible +/// name is "March 2025" has the triangle "Expand March 2025", so two rows with one caption are told apart. A row +/// without an accessible name keeps naming its triangle after its label. +#[trial] +fn a_triangle_is_named_after_the_rows_accessible_name() { + const MONTHS: [(&str, Option<&str>); 3] = [("March", Some("March 2025")), ("March", Some("March 2026")), ("April", None)]; + let mut fixture = Fixture::new(move |ui| { + let keys = [0_usize, 1, 2]; + let source = keyed(&keys, |key: &usize| *key); + let list = List::new("Months").tree(true); + let _ = list.show_items(ui, &source, &mut |key, _| { + let (title, name) = MONTHS[*key]; + let row = ListRow::new(title).depth(0).group(false); + match name { + Some(name) => row.accessible_name(name), + None => row, + } + }); + }); + fixture.room(Vec2::new(300.0, 200.0)); + fixture.settle(); + assert!(fixture.by_label("Expand March 2025").is_some(), "the first March's triangle names its year"); + assert!(fixture.by_label("Expand March 2026").is_some(), "the second March's triangle names its year"); + assert!(fixture.by_label("Expand March").is_none(), "no triangle is named by the drawn caption alone"); + assert!(fixture.by_label("Expand April").is_some(), "a row without an accessible name names its triangle after its label"); +} + /// A row that a rename request names stays listed while its rename runs, though the query excludes it, and goes when /// the rename ends. #[trial]