ui-contract: an accessibility click on an item of a collection that activates on a click activates it, as a pointer click does

This commit is contained in:
bflatastic
2026-11-23 04:08:25 +07:00
parent 5c8ac4b471
commit d8dd9d94e3
2 changed files with 33 additions and 3 deletions
@@ -1,7 +1,7 @@
//! AccessKit nodes and requests of item rows, section rows and toggle cells.
use super::{ITEM_NODE, ItemsHooks, Placement, SECTION, TOGGLE_CELL, key_hash, section_part};
use crate::contract::collection::{CollectionEvent, LeadSource, OpenChange};
use crate::contract::collection::{ActivateOn, CollectionEvent, LeadSource, OpenChange};
use crate::contract::cx::Pointer as _;
use crate::contract::{Collection, Cx};
use crate::runtime::access::{self, Role};
@@ -74,8 +74,8 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
}
/// 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 does that and picks an item or activates a
/// section, as a press does; Expand and Collapse open and close a row that has children.
/// moves the lead to the row and key focus to the collection; Click does that and picks an item (and activates it
/// in a collection that activates on a click) or activates a section, as a press does; Expand and Collapse open and close a row that has children.
pub(super) fn node_by_access(&mut self, comp: &C, cx: &mut Cx<'_, C>, layout: &C::ItemLayout, place: Placement) {
use craft_behavior::AccessAction;
let (_, built) = self.built(layout, place.rect, place.offset);
@@ -109,6 +109,10 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
self.events.push(CollectionEvent::Activate(key));
} else {
self.pick(comp, at, false, false);
if comp.items().activate == ActivateOn::Click {
self.activation_clicks = 1;
self.events.push(CollectionEvent::Activate(key));
}
}
}
}
+26
View File
@@ -615,6 +615,32 @@ fn a_cell_field_stands_in_its_cell_takes_the_click_and_reports_its_edit() {
assert_eq!(*typed.borrow(), Some(12.0), "the field's edit reaches the output");
}
/// A screen reader's click on an item of a list that activates on a click picks and activates it, as a pointer click
/// does; one on a list that activates on a double click only picks it.
#[trial]
fn an_access_click_activates_an_item_where_a_click_does() {
use craft_ui::contract::ActivateOn;
use craft_ui::testing::focus::AccessActionKind;
for (activate, activates) in [(ActivateOn::Click, true), (ActivateOn::DoubleClick, false)] {
let events = Rc::new(RefCell::new(Vec::new()));
let held = events.clone();
let mut fixture = Fixture::new(move |ui| {
let keys = [0_usize, 1, 2];
let source = keyed(&keys, |key: &usize| *key).with_text(|key| std::borrow::Cow::Borrowed(NAMES[*key]));
let out = List::new("Swatches").activate(activate).show_items(ui, &source, &mut |key, _| ListRow::new(NAMES[*key]));
held.borrow_mut().extend(out.events);
});
fixture.room(Vec2::new(300.0, 200.0)).settle();
events.borrow_mut().clear();
let row = fixture.by_label(NAMES[1]).expect("the second row");
fixture.access(AccessActionKind::Click, &row).settle();
let events = events.borrow();
assert!(events.iter().any(|event| matches!(event, CollectionEvent::Selection { .. })), "{activate:?}: the click picks: {events:?}");
let activated = events.iter().any(|event| matches!(event, CollectionEvent::Activate(1)));
assert_eq!(activated, activates, "{activate:?}: {events:?}");
}
}
/// A link in the label's column is only as wide as its text, as a label is: a press on it follows the link, and a
/// press past it acts on the row (selects it, and would start its drag), as production's rows named by a link did.
#[trial]