From ee36c0596297a734b3ba15388e1611a00d865f9e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 25 Nov 2026 08:49:52 -0800 Subject: [PATCH] ui-contract: a folded control focused in an arena reports focus on its owner's node A control shown with `PaintUi::inner` folds its node into its owner's, and the report step sets the owner's node as the focused node when the control has focus. When the control is a member of an arena, such as a docked panel's body, the arena-member rule that followed set focus on the control's own hidden node instead, so assistive technology saw no focused node. `ColorArea` shows its picker this way. In a docked panel, Tab from the color wheel's hue ring moved focus to the square's picker with no node focused, and the "Saturation and brightness" node was never reached. The arena-member rule now skips a folded control, whose owner's node stands for its focus. --- crates/color-ui/tests/it/color_parts.rs | 44 +++++++++++++++++++ .../ui-contract/src/contract/steps/report.rs | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/crates/color-ui/tests/it/color_parts.rs b/crates/color-ui/tests/it/color_parts.rs index 9f66a42e1..8bb2598d3 100644 --- a/crates/color-ui/tests/it/color_parts.rs +++ b/crates/color-ui/tests/it/color_parts.rs @@ -202,6 +202,50 @@ impl WheelRig { } } +/// The names focus takes from the hue ring of a wheel shown in an arena (a split area's body) between two buttons, +/// one per Tab in `keys` (with its modifiers). +fn arena_tab_walk(inner: WheelInner, keys: &[Modifiers]) -> Vec> { + let mut fixture = Fixture::new(move |ui| { + let _ = craft_ui::buttons::Button::new("Before").show(ui); + let limits = |_: &usize| craft_ui::contract::SizeLimits::default(); + let rules = craft_ui::docking::tree::FrameRules::new(&limits); + let area = Rect::from_min_size(ui.max_rect().min + vec2(0.0, 40.0), vec2(400.0, 340.0)); + let _ = craft_ui::docking::SplitArea::pair("Panels", craft_behavior::Axis::X, (0usize, 1usize), 0.99, rules).show_at(ui, area, |ui, _| { + let _ = ColorWheel::new("Color wheel", Bind::given(ModelValues::new("hsb", &[200.0, 50.0, 50.0]))).inner(inner).show(ui); + }); + let _ = craft_ui::buttons::Button::new("After").show(ui); + }); + fixture.room(vec2(420.0, 420.0)); + fixture.settle(); + let hue = fixture.by_label("Hue").expect("the ring"); + fixture.access(AccessActionKind::Focus, &hue); + fixture.idle(2); + let focused = |fixture: &Fixture| { + let tree = fixture.tree(); + tree.name_of(craft_ui::testing::access::focused_key(tree)).map(str::to_owned) + }; + assert_eq!(focused(&fixture).as_deref(), Some("Hue"), "{inner:?}: the ring takes focus"); + keys.iter() + .map(|mods| { + fixture.key(Key::Tab, *mods); + fixture.idle(2); + focused(&fixture) + }) + .collect() +} + +/// In an arena, as in a docked panel, Tab from the hue ring lands on the saturation and brightness control, also when a +/// square shows it through its own folded picker, then goes on past the wheel; Shift-Tab comes back the same way. +#[trial] +fn in_an_arena_tab_from_the_ring_reaches_the_saturation_and_brightness_control() { + let (on, back) = (Modifiers::NONE, Modifiers::SHIFT); + for inner in [WheelInner::Triangle, WheelInner::Square] { + let walk = arena_tab_walk(inner, &[on, on, back, back]); + let expected = ["Saturation and brightness", "After", "Saturation and brightness", "Hue"].map(|name| Some(name.to_owned())); + assert_eq!(walk, expected, "{inner:?}"); + } +} + /// A square wheel hands a press between the square and the ring to the square; its named markers speak their colour, /// pick on a click, and a press held on one still drags the ring; Shift snaps a ring drag to 45 degrees, in both /// variants. diff --git a/crates/ui-contract/src/contract/steps/report.rs b/crates/ui-contract/src/contract/steps/report.rs index 5976dc39f..a4d623a33 100644 --- a/crates/ui-contract/src/contract/steps/report.rs +++ b/crates/ui-contract/src/contract/steps/report.rs @@ -239,7 +239,8 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_> } else if let Some(editor) = &core.editor { crate::runtime::access::text::fold_editor(ctx, editor.widget, id); } - if core.member_of.is_some() && flags.contains(Flags::FOCUSED) { + // An arena member's focus is its own node; a folded child's is its owner's, set above. + if inner_of.is_none() && core.member_of.is_some() && flags.contains(Flags::FOCUSED) { access::set_focus(ctx, id); } let facts = core.env.facts_of(id);