mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
Merge pull request #4148 from dotCooCoo/fix/disabled-list-headings
ui-contract: a disabled list's section headings and rows ignore accessibility actions
This commit is contained in:
2 files changed
+94
-5
No files matched your search
@@ -68,7 +68,7 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
rect,
|
||||
enabled: enabled && self.source.enabled(at),
|
||||
focusable: false,
|
||||
clickable: true,
|
||||
clickable: enabled && self.source.enabled(at),
|
||||
active: false,
|
||||
face: None,
|
||||
label: "",
|
||||
@@ -77,10 +77,10 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
access::report_sub(ctx, &decl);
|
||||
}
|
||||
|
||||
/// AccessKit requests on an item row's node or on a section row's collection node (`report_section_node`): Focus
|
||||
/// moves the lead to the row and key focus to the collection; Click also picks an item and activates it when the
|
||||
/// collection activates on click, or activates a section it does not select. Expand and Collapse open and
|
||||
/// close rows with children.
|
||||
/// AccessKit requests on an item row's node or on a section row's collection node (`report_section_node`), while the
|
||||
/// collection is enabled: Focus moves the lead to the row and key focus to the collection; Click also picks an item and
|
||||
/// activates it when the collection activates on click, or activates a section it does not select. Expand and
|
||||
/// Collapse open and close rows with children.
|
||||
pub(super) fn node_by_access(
|
||||
&mut self,
|
||||
comp: &C,
|
||||
@@ -90,6 +90,9 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
place: Placement,
|
||||
) {
|
||||
use craft_behavior::AccessAction;
|
||||
if !cx.core.resolved.enabled {
|
||||
return;
|
||||
}
|
||||
let (_, built) = self.built(layout, place.rect, place.offset);
|
||||
let rows: Vec<(u64, usize)> = built
|
||||
.into_iter()
|
||||
|
||||
@@ -140,6 +140,92 @@ fn accessibility_click_respects_current_toggle_availability() {
|
||||
assert_eq!(seen.borrow().iter().filter(|event| matches!(event, CollectionEvent::Toggle(_))).count(), 1);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn accessibility_actions_respect_a_section_headings_availability() {
|
||||
use craft_behavior::{DisplayOrder, ItemSource};
|
||||
use craft_ui::testing::access::Declared;
|
||||
use craft_ui::testing::focus::AccessActionKind;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
|
||||
const ROWS: [&str; 2] = ["Inks", "Cyan"];
|
||||
struct Source {
|
||||
heading_enabled: bool,
|
||||
}
|
||||
impl DisplayOrder<usize> for Source {
|
||||
fn len(&self) -> usize {
|
||||
ROWS.len()
|
||||
}
|
||||
fn key(&self, at: usize) -> usize {
|
||||
at
|
||||
}
|
||||
fn has_children(&self, at: usize) -> bool {
|
||||
at == 0
|
||||
}
|
||||
fn is_section(&self, at: usize) -> bool {
|
||||
at == 0
|
||||
}
|
||||
fn section_stop(&self, at: usize) -> bool {
|
||||
at == 0
|
||||
}
|
||||
fn section_stops_before(&self, at: usize) -> usize {
|
||||
usize::from(at > 0)
|
||||
}
|
||||
fn enabled(&self, at: usize) -> bool {
|
||||
at != 0 || self.heading_enabled
|
||||
}
|
||||
fn text(&self, at: usize) -> Option<Cow<'_, str>> {
|
||||
Some(Cow::Borrowed(ROWS[at]))
|
||||
}
|
||||
}
|
||||
impl ItemSource<usize> for Source {}
|
||||
|
||||
let enabled = Rc::new(Cell::new((true, true)));
|
||||
let gates = enabled.clone();
|
||||
let seen = Rc::new(RefCell::new(Vec::new()));
|
||||
let held = seen.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let (list_enabled, heading_enabled) = gates.get();
|
||||
let source = Source { heading_enabled };
|
||||
let out = List::new("Plates").enabled(list_enabled).show_items(ui, &source, &mut |key, _| ListRow::new(ROWS[*key]));
|
||||
held.borrow_mut().extend(out.events);
|
||||
});
|
||||
let acted = |event: &CollectionEvent<usize, RowEvent>| {
|
||||
matches!(
|
||||
event,
|
||||
CollectionEvent::Activate(_) | CollectionEvent::Open(_) | CollectionEvent::Selection { .. } | CollectionEvent::LeadMoved { .. }
|
||||
)
|
||||
};
|
||||
for (list_enabled, heading_enabled, denied) in [(false, true, "disabled list"), (true, false, "disabled section")] {
|
||||
enabled.set((true, true));
|
||||
fixture.settle();
|
||||
let heading = fixture.by_label("Inks").expect("the heading");
|
||||
assert!(fixture.tree().declares_key(heading.node, Declared::Click));
|
||||
seen.borrow_mut().clear();
|
||||
enabled.set((list_enabled, heading_enabled));
|
||||
fixture.access(AccessActionKind::Click, &heading).settle();
|
||||
fixture.access(AccessActionKind::Expand, &heading).settle();
|
||||
assert!(!seen.borrow().iter().any(acted), "accessibility acted on the heading of a {denied}: {:?}", seen.borrow());
|
||||
let heading = fixture.by_label("Inks").expect("disabled heading remains visible to accessibility");
|
||||
assert!(!fixture.tree().declares_key(heading.node, Declared::Click), "the heading of a {denied} still offers accessibility Click");
|
||||
}
|
||||
enabled.set((true, true));
|
||||
fixture.settle();
|
||||
let row = fixture.by_label("Cyan").expect("the row");
|
||||
seen.borrow_mut().clear();
|
||||
enabled.set((false, true));
|
||||
fixture.access(AccessActionKind::Click, &row).settle();
|
||||
assert!(!seen.borrow().iter().any(acted), "accessibility acted on a row of a disabled list: {:?}", seen.borrow());
|
||||
enabled.set((true, true));
|
||||
fixture.settle();
|
||||
let heading = fixture.by_label("Inks").expect("the enabled heading");
|
||||
seen.borrow_mut().clear();
|
||||
fixture.access(AccessActionKind::Click, &heading).settle();
|
||||
fixture.access(AccessActionKind::Expand, &heading).settle();
|
||||
assert!(seen.borrow().iter().any(|event| matches!(event, CollectionEvent::Activate(0))), "Click activates the enabled heading");
|
||||
assert!(seen.borrow().iter().any(|event| matches!(event, CollectionEvent::Open(_))), "Expand opens the enabled heading");
|
||||
}
|
||||
|
||||
/// The rects of the three rows of a list shown with `rows`.
|
||||
fn row_rects(rows: RowHeight) -> Vec<egui::Rect> {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
|
||||
Reference in new issue
Block a user