From 1fb2186343dd9ade5daccbffe16eadd40790259e Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 07:24:47 +0100 Subject: [PATCH 01/13] Menus: Enter or Space on a focused opener opens its menu A Click or Press opener only fired on a pointer press, so a menu button reached with Tab could not open its menu from the keyboard. A key or AccessKit activation of the opener now opens it too. --- .../ui-contract/src/contract/overlay/opener.rs | 7 +++++-- crates/ui-contract/src/runtime/egui/response.rs | 6 ++++++ crates/ui-widgets/tests/it/menu/openers.rs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/contract/overlay/opener.rs b/crates/ui-contract/src/contract/overlay/opener.rs index e530d4461..152f57cd7 100644 --- a/crates/ui-contract/src/contract/overlay/opener.rs +++ b/crates/ui-contract/src/contract/overlay/opener.rs @@ -67,6 +67,9 @@ impl Opener { // The opener's `Response` carries the press path's verdict, for a root with its own egui widget and for an // arena member alike: whether the open press is on it and whether a click released on it. let pressed_on = response::is_pressed(anchor); + // Enter or Space on a focused opener, or an AccessKit click, opens a click or press opener's layer as the + // pointer does. + let by_key = response::key_clicked(anchor); let request = keys::context_request(&anchor.ctx, anchor.id); let (fired, opening, pressed, clicked) = pointer::with_pass_raw(&anchor.ctx, |pass| { let Some(frame) = pass.frame.as_ref() else { return (false, Opening::Plain, false, false) }; @@ -78,8 +81,8 @@ impl Opener { // then held; a `Click` opener's release completes the click that press began. let primary = pressed_on && frame.press.is_some_and(|press| press.button == PointerButton::Primary); let fired = match trigger { - Trigger::Click => primary, - Trigger::Press => primary || by_pointer, + Trigger::Click => primary || by_key, + Trigger::Press => primary || by_pointer || by_key, Trigger::Context => by_pointer || request.is_some(), Trigger::Hover | Trigger::Hold | Trigger::Manual => false, }; diff --git a/crates/ui-contract/src/runtime/egui/response.rs b/crates/ui-contract/src/runtime/egui/response.rs index 3a4a3bedc..2e17b513c 100644 --- a/crates/ui-contract/src/runtime/egui/response.rs +++ b/crates/ui-contract/src/runtime/egui/response.rs @@ -10,6 +10,12 @@ pub(crate) fn clicked(response: &Response) -> bool { response.flags.intersects(Flags::CLICKED | Flags::FAKE_PRIMARY_CLICKED) } +/// Whether a key or AccessKit activation clicked the component of `response` in this pass (Enter or Space on its focused +/// stop), not the pointer. +pub(crate) fn key_clicked(response: &Response) -> bool { + response.flags.contains(Flags::FAKE_PRIMARY_CLICKED) +} + /// Whether the press path released a pointer click on the component of `response`: a root's own widget or a /// member's shape, never a key or AccessKit activation. pub(crate) fn pointer_clicked(response: &Response) -> bool { diff --git a/crates/ui-widgets/tests/it/menu/openers.rs b/crates/ui-widgets/tests/it/menu/openers.rs index 888f4165e..bd7415b13 100644 --- a/crates/ui-widgets/tests/it/menu/openers.rs +++ b/crates/ui-widgets/tests/it/menu/openers.rs @@ -148,3 +148,19 @@ fn a_menu_button_hangs_its_arrow_under_the_end_of_its_glyph() { } } } + + +/// Space on a focused icon button that opens a menu opens the menu, as a click does. +#[trial] +fn space_on_a_focused_menu_opener_opens_its_menu() { + let mut fixture = Fixture::new(|ui| { + let opener = IconButton::new(IconId::new("menu")).popup(PopupKind::Menu).label("Panel menu").show(ui); + Menu::new("Panel menu").opened_by(&opener, Trigger::Click).show(ui, |ui, _| { + MenuItem::new("Clear All").show(ui); + }); + }); + fixture.settle(); + fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle(); + fixture.key(egui::Key::Space, egui::Modifiers::NONE).settle(); + assert!(fixture.by_label("Clear All").is_some(), "Space on the focused opener opens the menu"); +} From eab1234897c4c3db7100eff28557c15dd773428e Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 05:24:02 +0100 Subject: [PATCH 02/13] Overlays: a popup with no opener closes when its owner goes disabled An explicit opener that goes disabled already closes its popup (AnchorGone). A popup that hangs from its own component now does the same when that component is disabled. From the DesignCraft port's SDK provider writer. --- crates/ui-contract/src/contract/overlay/ui.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ui-contract/src/contract/overlay/ui.rs b/crates/ui-contract/src/contract/overlay/ui.rs index 4f428911d..b9dd2a927 100644 --- a/crates/ui-contract/src/contract/overlay/ui.rs +++ b/crates/ui-contract/src/contract/overlay/ui.rs @@ -154,6 +154,11 @@ impl<'a> OverlayUi<'a> { return None; }; let (kind, peers) = (overlay.popup, overlay.opener.is_none()); + // A popup with no recorded opener hangs from this component: when the component goes disabled, its anchor is + // gone, as for an explicit opener that goes disabled (`dismissal`). + if open && peers && overlay.dismiss.anchor_gone && !self.resolved.enabled { + crate::runtime::overlay::request_close(self.ctx, popup.id, CloseReason::AnchorGone); + } let ctx = self.ctx.clone(); with_popups(&ctx, |popups| { popups.anchors.push((self.owner, PopupShown { id: popup.id, kind, open })); From bacdbc494f428bb4b6372577e309b3e9c38e4d6c Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 06:56:31 +0100 Subject: [PATCH 03/13] Select: tests for a disabled owner retiring its held popup From the DesignCraft port's SDK provider writer: a Select whose parent or itself goes disabled while an option is held closes its list before the release, commits nothing, and recovers. --- crates/ui-widgets/tests/it/pickers/mod.rs | 1 + .../tests/it/pickers/select_disabled_owner.rs | 92 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs diff --git a/crates/ui-widgets/tests/it/pickers/mod.rs b/crates/ui-widgets/tests/it/pickers/mod.rs index 6985b7f5d..05504dcc0 100644 --- a/crates/ui-widgets/tests/it/pickers/mod.rs +++ b/crates/ui-widgets/tests/it/pickers/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod combo_list; pub(crate) mod date; pub(crate) mod icon_picker; +pub(crate) mod select_disabled_owner; pub(crate) mod select_list; pub(crate) mod select_measure; pub(crate) mod select_steps; diff --git a/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs b/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs new file mode 100644 index 000000000..adac6e7c1 --- /dev/null +++ b/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs @@ -0,0 +1,92 @@ +//! A disabled implicit Select owner naturally retires its held popup before the pointer is released. + +use craft_behavior::EditEvent; +use craft_ui::contract::{Bind, Entry, Props as _, Role, Show as _}; +use craft_ui::pickers::Select; +use craft_ui::testing::{Fixture, Room, Story, StoryData, StoryOutput, trial}; +use egui::{Key, Modifiers, Ui}; + +fn select(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let parent_enabled = *data.value("parent_enabled", true); + let control_enabled = *data.value("control_enabled", true); + ui.add_enabled_ui(parent_enabled, |ui| { + let entries = [ + Entry::new(1u8, "One"), + Entry::new(2u8, "Two"), + Entry::new(3u8, "Three"), + Entry::new(4u8, "Four"), + Entry::new(5u8, "Five"), + Entry::new(6u8, "Six"), + Entry::new(7u8, "Seven"), + Entry::new(8u8, "Eight"), + Entry::new(9u8, "Nine"), + Entry::new(10u8, "Ten"), + Entry::new(11u8, "Eleven"), + Entry::new(12u8, "Twelve"), + ]; + let out = Select::new("Pick", Bind::bound(data.value("value", 1u8)), &entries).enabled(control_enabled).show(ui); + data.note("terminal_edits", Vec::<&'static str>::new()).extend(out.events.iter().filter_map(|event| match event { + EditEvent::Commit { .. } => Some("commit"), + EditEvent::Set { .. } => Some("set"), + _ => None, + })); + out.into() + }) + .inner +} + +fn value(fixture: &mut Fixture) -> u8 { + *fixture.data().value("value", 1u8) +} + +fn terminal_edits(fixture: &mut Fixture) -> usize { + fixture.data().note("terminal_edits", Vec::<&'static str>::new()).len() +} + +fn held_popup_retires(disabled: &'static str) { + let mut fixture = Fixture::story(&Story::new("disabled_implicit_select", select)); + fixture.room(Room::Window.size()).settle(); + let trigger = *fixture.by_role(Role::COMBO_BOX).first().expect("the genuine current Select"); + fixture.click(&trigger).settle(); + assert_eq!(fixture.tree().with_role(Role::LIST_BOX_OPTION).len(), 12, "all twelve real AX options were opened before disable"); + let option = fixture.by_label("Two").expect("the real second option"); + fixture.press(&option); + assert!(fixture.ctx().input(|input| input.pointer.primary_down()), "the real option press is still physically held"); + assert_eq!(terminal_edits(&mut fixture), 0, "the held option has not committed or set a value"); + + *fixture.data().value(disabled, true) = false; + fixture.idle(2); + let current = *fixture.by_role(Role::COMBO_BOX).first().expect("the same disabled Select is still installed"); + assert_eq!(current.node, trigger.node, "disabling does not substitute the owner's identity"); + assert!(fixture.tree().is_disabled_key(current.node), "the real disabled state reached the current owner"); + assert!(fixture.ctx().input(|input| input.pointer.primary_down()), "retirement is checked before any pointer release"); + assert_eq!(fixture.tree().with_role(Role::LIST_BOX_OPTION).len(), 0, "a disabled implicit owner retires all popup options after two ordinary idle frames, before release"); + assert!(fixture.tree().with_role(Role::LIST_BOX).is_empty(), "the actual popup shell is retired too"); + assert_eq!(value(&mut fixture), 1, "disable preserves the original bound value"); + assert_eq!(terminal_edits(&mut fixture), 0, "retirement produces no Commit or Set"); + + fixture.release(&option).idle(2); + fixture.key(Key::Enter, Modifiers::NONE).idle(2); + assert_eq!(value(&mut fixture), 1, "late release and Enter cannot commit the retired option"); + assert_eq!(terminal_edits(&mut fixture), 0, "late inputs emit no terminal edit"); + *fixture.data().value(disabled, true) = true; + fixture.idle(2); + assert!(fixture.tree().with_role(Role::LIST_BOX_OPTION).is_empty(), "re-enabling does not resurrect the old popup"); + let recovered = *fixture.by_role(Role::COMBO_BOX).first().expect("the re-enabled owner"); + assert_eq!(recovered.node, trigger.node, "normal recovery keeps the same owner identity"); + fixture.click(&recovered).settle(); + let next = fixture.by_label("Two").expect("a newly opened, real option"); + fixture.click(&next).settle(); + assert_eq!(value(&mut fixture), 2, "a later genuine pick still works"); + assert_eq!(terminal_edits(&mut fixture), 1, "only the new complete pick produces a terminal edit"); +} + +#[trial] +fn a_parent_disabled_select_retires_its_held_popup_before_release() { + held_popup_retires("parent_enabled"); +} + +#[trial] +fn an_explicitly_disabled_select_retires_its_held_popup_before_release() { + held_popup_retires("control_enabled"); +} From 6b06b2d8334730bc6958912eff206ece01c43aaa Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 11:23:29 +0100 Subject: [PATCH 04/13] Select: Enter on the field right after Escape reopens the list during its exit fade The list keys of a dropdown went to the list of a layer that was already playing its exit fade, so an Enter pressed right after Escape chose a row of the leaving list instead of reaching the field. A closing layer no longer takes its opener's list keys, as it already no longer takes Escape. --- .../src/runtime/focus/registration.rs | 14 +++++++++----- .../ui-widgets/tests/it/pickers/select_list.rs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/runtime/focus/registration.rs b/crates/ui-contract/src/runtime/focus/registration.rs index d03d2bb75..ba0817710 100644 --- a/crates/ui-contract/src/runtime/focus/registration.rs +++ b/crates/ui-contract/src/runtime/focus/registration.rs @@ -182,13 +182,17 @@ impl Group { /// The innermost open `KeepAnchor` layer opened from the stop `opener`, the collection the layer names for its /// opener's list keys (`FocusPolicy::list`) and the layer's policy. `None` while no such layer is open, or it names no -/// collection or one that registered no stop in the last pass (a list not shown leaves the keys with the opener). +/// collection or one that registered no stop in the last pass (a list not shown leaves the keys with the opener). A +/// layer playing its exit fade is closed: the opener keeps its keys, so an Enter right after Escape opens the list +/// again instead of activating the row of the list that is leaving. pub(crate) fn dropdown_target(ctx: &Context, opener: StopKey) -> Option<(Id, Id, FocusPolicy)> { with(ctx, |state| { - let layer = - *state.last_scope_order.iter().rev().find(|id| { - state.last_scopes.get(*id).is_some_and(|scope| scope.policy.initial == Initial::KeepAnchor && scope.opener == Some(opener)) - })?; + let layer = *state.last_scope_order.iter().rev().find(|id| { + state + .last_scopes + .get(*id) + .is_some_and(|scope| scope.policy.initial == Initial::KeepAnchor && !scope.closing && scope.opener == Some(opener)) + })?; let policy = state.last_scopes.get(&layer)?.policy; let shown = |list: &Id| state.last_stops.iter().any(|rec| rec.stop.id == *list); policy.list.filter(shown).map(|list| (layer, list, policy)) diff --git a/crates/ui-widgets/tests/it/pickers/select_list.rs b/crates/ui-widgets/tests/it/pickers/select_list.rs index c3de17d64..d927ee527 100644 --- a/crates/ui-widgets/tests/it/pickers/select_list.rs +++ b/crates/ui-widgets/tests/it/pickers/select_list.rs @@ -61,6 +61,23 @@ fn keys_in_the_open_list_move_the_value_and_escape_puts_it_back() { assert_eq!(value(&mut fixture), 1, "and puts back the value from before the list opened"); } +/// The list that Escape closed is closed for its field's keys while it still fades out: the Enter that follows at once +/// is the field's own and opens the list again, rather than choosing a row of the list that is leaving. +#[trial] +fn enter_on_the_field_right_after_escape_opens_the_list_again_during_its_exit_fade() { + let mut fixture = focused(); + fixture.key(Key::ArrowDown, Modifiers::ALT); + fixture.settle(); + assert!(list_open(&mut fixture), "Alt+Down opens the list"); + fixture.key(Key::ArrowDown, Modifiers::NONE); + fixture.key(Key::Escape, Modifiers::NONE); + assert_eq!(value(&mut fixture), 1, "Escape puts back the value from before the list opened"); + fixture.key(Key::Enter, Modifiers::NONE); + fixture.settle(); + assert!(list_open(&mut fixture), "Enter on the focused field opens the list again before the old one has faded out"); + assert_eq!(value(&mut fixture), 1, "and picks no row of the list that was leaving"); +} + #[trial] fn typing_on_the_closed_select_opens_the_list_on_the_first_match() { let mut fixture = focused(); From 4433da1c52a3820005a83bb604a1e0d871dc4f17 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 13:21:11 +0100 Subject: [PATCH 05/13] Menus: Return in a pointer-opened menu runs the lit row, or none A menu the pointer opens puts the key focus on its first row without lighting it. Enter or Space as the first key went to that focused row, so Return in a text field's edit menu ran Undo and took back the typing, even with another row lit under the pointer. The first key now runs the row the pointer lit; with none lit it only closes the menu, and the field keeps its typing run, as a native menu does. Menus driven by the keyboard, and AccessKit activations, are unchanged. --- crates/ui-widgets/src/menu/item.rs | 28 ++++++++++++--- crates/ui-widgets/src/menu/level.rs | 5 +++ crates/ui-widgets/tests/it/text/edit_menu.rs | 38 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/crates/ui-widgets/src/menu/item.rs b/crates/ui-widgets/src/menu/item.rs index 3cbf04c0c..0a3f72c88 100644 --- a/crates/ui-widgets/src/menu/item.rs +++ b/crates/ui-widgets/src/menu/item.rs @@ -241,6 +241,8 @@ pub struct MenuItem<'a> { #[prop(name = "entry_checked")] entry: Option, ran: bool, + /// The row took a key activation it does not run: the first key in a menu the pointer opened (`update`). + withheld: bool, opens: bool, open: bool, active: bool, @@ -267,6 +269,7 @@ impl<'a> MenuItem<'a> { keep_open: false, entry: None, ran: false, + withheld: false, opens: false, open: false, active: false, @@ -550,9 +553,13 @@ impl Component for MenuItem<'_> { } }; let takes_over = hovered && (!heading || rested >= AIM_REST); + // Enter or Space as the first key in a menu the pointer opened reaches the focused row, which the pointer may never + // have lit: it runs the row the pointer lit, or with none lit it only closes the menu, as a native menu does. + let lit = level.active_enabled(); + let first_key = key_started && !self.submenu && cx.activation().is_some_and(|activation| activation.by_key) && lit != Some(cx.id); // The focused row of a menu that the pointer opened is not active: the keyboard makes it so when focus lands on // it or the keyboard starts driving the menu. - if enabled && focused && keyboard && (focus_gained || key_started) && level.activate_row(cx.id) { + if enabled && focused && keyboard && (focus_gained || key_started) && !first_key && level.activate_row(cx.id) { frame::request_repaint(&ctx); } // A disabled row is never active. @@ -562,7 +569,19 @@ impl Component for MenuItem<'_> { frame::request_repaint_after(&ctx, AIM_REST - rested); } let typed = enabled && level.take_run(cx.id); - let asked = enabled && (typed || cx.activation().is_some()); + self.withheld = first_key; + if first_key { + match lit { + Some(row) => level.run(row), + None => { + if let Some(menu) = crate::runtime::focus::running_menu(&ctx) { + crate::runtime::focus::return_from_pick(&ctx, crate::runtime::focus::PickedIn::Menus(menu)); + crate::runtime::overlay::request_close(&ctx, menu, crate::runtime::overlay::CloseReason::Requested); + } + } + } + } + let asked = enabled && (typed || (cx.activation().is_some() && !first_key)); if self.submenu { self.opens = asked || (enabled && forward) || (enabled && takes_over); if self.opens { @@ -605,9 +624,10 @@ impl Component for MenuItem<'_> { self.ran = asked; } - /// A submenu row never runs: it opens its submenu, and the menus stay open. + /// A submenu row never runs: it opens its submenu, and the menus stay open. Nor does a row whose key activation it + /// withheld: the row the pointer lit runs instead, or none. fn activated(&self, cx: &Cx<'_, Self>) -> bool { - !self.submenu && cx.activation().is_some() + !self.submenu && !self.withheld && cx.activation().is_some() } fn flags(&self) -> Flags { diff --git a/crates/ui-widgets/src/menu/level.rs b/crates/ui-widgets/src/menu/level.rs index 08094a0bf..f9ffee315 100644 --- a/crates/ui-widgets/src/menu/level.rs +++ b/crates/ui-widgets/src/menu/level.rs @@ -318,6 +318,11 @@ impl MenuLevel { self.with(|state| state.active) } + /// The active row while it is enabled. + pub(super) fn active_enabled(&self) -> Option { + self.with(|state| state.active.filter(|active| state.shown.iter().any(|row| row.id == *active && row.enabled))) + } + /// Moves the active row by `mv` among the enabled rows as the user last saw them, without moving the focus (the /// keys of a field that drives the menu): Up and Down wrap, Home and Page Up go to the first, End and Page Down to /// the last. Returns whether it moved. diff --git a/crates/ui-widgets/tests/it/text/edit_menu.rs b/crates/ui-widgets/tests/it/text/edit_menu.rs index 66adef1a5..008fbe5ff 100644 --- a/crates/ui-widgets/tests/it/text/edit_menu.rs +++ b/crates/ui-widgets/tests/it/text/edit_menu.rs @@ -101,6 +101,44 @@ fn escape_closes_the_edit_menu_and_the_field_keeps_its_typing_run() { assert_eq!(*rig.text.borrow(), "hello", "the field's own Escape still restores the value from before its run"); } +/// Return in an edit menu the pointer opened, before the pointer lit a row, runs no row (it ran the first one, Undo, +/// and took back the typing): it closes the menu and the field keeps its typing run, as a native menu does. +#[trial] +fn return_in_the_edit_menu_with_no_row_lit_only_closes_it() { + let mut rig = rig(); + rig.fixture.type_text("abc"); + rig.fixture.settle(); + rig.right_click_in_the_field(); + assert!(rig.menu_open(), "the edit menu is open"); + rig.fixture.key(Key::Enter, Modifiers::NONE); + rig.fixture.settle(); + assert!(!rig.menu_open(), "Return closes the menu"); + assert_eq!(*rig.text.borrow(), "helloabc", "and runs none of its rows"); + assert!(rig.focus_in_the_field(), "the focus is back in the field"); + rig.fixture.type_text("d"); + rig.fixture.settle(); + assert_eq!(*rig.text.borrow(), "helloabcd", "typing goes on in the field"); +} + +/// Return in an edit menu the pointer opened runs the row the pointer lit, not the first row the menu focused. +#[trial] +fn return_in_the_edit_menu_runs_the_row_the_pointer_lit() { + let mut rig = rig(); + rig.fixture.type_text("abc"); + rig.fixture.settle(); + rig.right_click_in_the_field(); + let select_all = rig.fixture.by_label("Select All").expect("the Select All row").center(); + rig.fixture.frame(vec![pointer::moved(select_all)]); + rig.fixture.settle(); + rig.fixture.key(Key::Enter, Modifiers::NONE); + rig.fixture.settle(); + assert!(!rig.menu_open(), "Return closes the menu"); + assert_eq!(*rig.text.borrow(), "helloabc", "Undo, the first row, did not run"); + rig.fixture.type_text("x"); + rig.fixture.settle(); + assert_eq!(*rig.text.borrow(), "x", "Select All ran: typing replaced the whole text"); +} + #[trial] fn an_edit_command_fired_from_elsewhere_reaches_the_focused_field() { let mut rig = rig(); From 2f0e675d3fdcbc0e00fc03704db2159f9de5308d Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 15:01:43 +0100 Subject: [PATCH 06/13] Menus: a trial that a menu opened by Space runs its first row on Return --- crates/ui-widgets/tests/it/menu/openers.rs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/ui-widgets/tests/it/menu/openers.rs b/crates/ui-widgets/tests/it/menu/openers.rs index bd7415b13..7045ee2c3 100644 --- a/crates/ui-widgets/tests/it/menu/openers.rs +++ b/crates/ui-widgets/tests/it/menu/openers.rs @@ -164,3 +164,28 @@ fn space_on_a_focused_menu_opener_opens_its_menu() { fixture.key(egui::Key::Space, egui::Modifiers::NONE).settle(); assert!(fixture.by_label("Clear All").is_some(), "Space on the focused opener opens the menu"); } + +/// A menu opened from the keyboard is driven by the keyboard: Space on the focused opener opens it with its first row +/// lit, and Return then runs that row and closes the menu. +#[trial] +fn return_in_a_menu_opened_by_space_runs_its_first_row() { + let ran = Rc::new(Cell::new(None::<&'static str>)); + let seen = ran.clone(); + let mut fixture = Fixture::new(move |ui| { + let opener = IconButton::new(IconId::new("menu")).popup(PopupKind::Menu).label("Panel menu").show(ui); + Menu::new("Panel menu").opened_by(&opener, Trigger::Click).show(ui, |ui, _| { + for row in ["Clear All", "Reset"] { + if MenuItem::new(row).show(ui).ran { + seen.set(Some(row)); + } + } + }); + }); + fixture.settle(); + fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle(); + fixture.key(egui::Key::Space, egui::Modifiers::NONE).settle(); + assert!(fixture.by_label("Clear All").is_some(), "Space on the focused opener opens the menu"); + fixture.key(egui::Key::Enter, egui::Modifiers::NONE).settle(); + assert_eq!(ran.get(), Some("Clear All"), "Return runs the menu's first row"); + assert!(menu_rect(&fixture).is_none(), "running the row closes the menu"); +} From 427edf5c494bdeff2ddb34662550ad21f0cb8fd6 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 15:02:26 +0100 Subject: [PATCH 07/13] rustfmt --- crates/ui-widgets/tests/it/menu/openers.rs | 1 - crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/tests/it/menu/openers.rs b/crates/ui-widgets/tests/it/menu/openers.rs index 7045ee2c3..4b7c052b3 100644 --- a/crates/ui-widgets/tests/it/menu/openers.rs +++ b/crates/ui-widgets/tests/it/menu/openers.rs @@ -149,7 +149,6 @@ fn a_menu_button_hangs_its_arrow_under_the_end_of_its_glyph() { } } - /// Space on a focused icon button that opens a menu opens the menu, as a click does. #[trial] fn space_on_a_focused_menu_opener_opens_its_menu() { diff --git a/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs b/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs index adac6e7c1..840f6b4bd 100644 --- a/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs +++ b/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs @@ -60,7 +60,11 @@ fn held_popup_retires(disabled: &'static str) { assert_eq!(current.node, trigger.node, "disabling does not substitute the owner's identity"); assert!(fixture.tree().is_disabled_key(current.node), "the real disabled state reached the current owner"); assert!(fixture.ctx().input(|input| input.pointer.primary_down()), "retirement is checked before any pointer release"); - assert_eq!(fixture.tree().with_role(Role::LIST_BOX_OPTION).len(), 0, "a disabled implicit owner retires all popup options after two ordinary idle frames, before release"); + assert_eq!( + fixture.tree().with_role(Role::LIST_BOX_OPTION).len(), + 0, + "a disabled implicit owner retires all popup options after two ordinary idle frames, before release" + ); assert!(fixture.tree().with_role(Role::LIST_BOX).is_empty(), "the actual popup shell is retired too"); assert_eq!(value(&mut fixture), 1, "disable preserves the original bound value"); assert_eq!(terminal_edits(&mut fixture), 0, "retirement produces no Commit or Set"); From 3364345d54dea0c68be4c360e896a2f1af41d821 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 15:05:56 +0100 Subject: [PATCH 08/13] Select disabled-owner tests: plainer messages --- .../ui-widgets/tests/it/pickers/select_disabled_owner.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs b/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs index 840f6b4bd..5a25c1e60 100644 --- a/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs +++ b/crates/ui-widgets/tests/it/pickers/select_disabled_owner.rs @@ -46,9 +46,9 @@ fn terminal_edits(fixture: &mut Fixture) -> usize { fn held_popup_retires(disabled: &'static str) { let mut fixture = Fixture::story(&Story::new("disabled_implicit_select", select)); fixture.room(Room::Window.size()).settle(); - let trigger = *fixture.by_role(Role::COMBO_BOX).first().expect("the genuine current Select"); + let trigger = *fixture.by_role(Role::COMBO_BOX).first().expect("the Select"); fixture.click(&trigger).settle(); - assert_eq!(fixture.tree().with_role(Role::LIST_BOX_OPTION).len(), 12, "all twelve real AX options were opened before disable"); + assert_eq!(fixture.tree().with_role(Role::LIST_BOX_OPTION).len(), 12, "the twelve options are open before the owner is disabled"); let option = fixture.by_label("Two").expect("the real second option"); fixture.press(&option); assert!(fixture.ctx().input(|input| input.pointer.primary_down()), "the real option press is still physically held"); @@ -65,7 +65,7 @@ fn held_popup_retires(disabled: &'static str) { 0, "a disabled implicit owner retires all popup options after two ordinary idle frames, before release" ); - assert!(fixture.tree().with_role(Role::LIST_BOX).is_empty(), "the actual popup shell is retired too"); + assert!(fixture.tree().with_role(Role::LIST_BOX).is_empty(), "the popup shell closes too"); assert_eq!(value(&mut fixture), 1, "disable preserves the original bound value"); assert_eq!(terminal_edits(&mut fixture), 0, "retirement produces no Commit or Set"); @@ -81,7 +81,7 @@ fn held_popup_retires(disabled: &'static str) { fixture.click(&recovered).settle(); let next = fixture.by_label("Two").expect("a newly opened, real option"); fixture.click(&next).settle(); - assert_eq!(value(&mut fixture), 2, "a later genuine pick still works"); + assert_eq!(value(&mut fixture), 2, "a later pick still works"); assert_eq!(terminal_edits(&mut fixture), 1, "only the new complete pick produces a terminal edit"); } From 715b5a34182b1c8bfff979e5b0bcb07ed06b9093 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 23 Nov 2026 21:07:54 +0100 Subject: [PATCH 09/13] Menus: Return in a pointer-opened menu opens no submenu the pointer did not light The first key in a menu the pointer opened left submenu rows out of the rule that it runs the lit row or none, so when the focused first row opened a submenu, Return opened it instead of running the lit row or only closing the menu. Submenu rows now follow the same rule: a Return on the lit submenu row still opens its submenu. --- crates/ui-widgets/src/menu/item.rs | 3 +- crates/ui-widgets/tests/it/menu/openers.rs | 38 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/crates/ui-widgets/src/menu/item.rs b/crates/ui-widgets/src/menu/item.rs index 0a3f72c88..5bcdfc888 100644 --- a/crates/ui-widgets/src/menu/item.rs +++ b/crates/ui-widgets/src/menu/item.rs @@ -556,7 +556,8 @@ impl Component for MenuItem<'_> { // Enter or Space as the first key in a menu the pointer opened reaches the focused row, which the pointer may never // have lit: it runs the row the pointer lit, or with none lit it only closes the menu, as a native menu does. let lit = level.active_enabled(); - let first_key = key_started && !self.submenu && cx.activation().is_some_and(|activation| activation.by_key) && lit != Some(cx.id); + // A submenu row is no exception: the first key opens no submenu the pointer did not light. + let first_key = key_started && cx.activation().is_some_and(|activation| activation.by_key) && lit != Some(cx.id); // The focused row of a menu that the pointer opened is not active: the keyboard makes it so when focus lands on // it or the keyboard starts driving the menu. if enabled && focused && keyboard && (focus_gained || key_started) && !first_key && level.activate_row(cx.id) { diff --git a/crates/ui-widgets/tests/it/menu/openers.rs b/crates/ui-widgets/tests/it/menu/openers.rs index 4b7c052b3..a977bee67 100644 --- a/crates/ui-widgets/tests/it/menu/openers.rs +++ b/crates/ui-widgets/tests/it/menu/openers.rs @@ -188,3 +188,41 @@ fn return_in_a_menu_opened_by_space_runs_its_first_row() { assert_eq!(ran.get(), Some("Clear All"), "Return runs the menu's first row"); assert!(menu_rect(&fixture).is_none(), "running the row closes the menu"); } + +/// A menu the pointer opened puts its first row in focus without lighting it; when that row opens a submenu, Return +/// with no row lit only closes the menu and opens no submenu, and with a row lit under the pointer it runs that row. +#[trial] +fn return_in_a_pointer_opened_menu_whose_first_row_opens_a_submenu() { + let ran = Rc::new(Cell::new(None::<&'static str>)); + let seen = ran.clone(); + let mut fixture = Fixture::new(move |ui| { + let opener = Button::new("Open").show(ui); + Menu::new("Main").opened_by(&opener, Trigger::Click).show(ui, |ui, _| { + Menu::submenu_row(ui, "Recent", |ui, _| { + MenuItem::new("Report.txt").show(ui); + }); + for row in ["Clear All", "Reset"] { + if MenuItem::new(row).show(ui).ran { + seen.set(Some(row)); + } + } + }); + }); + fixture.settle(); + let open = |fixture: &mut Fixture| { + let opener = fixture.by_label("Open").expect("the opener"); + fixture.advance(1.0).click(&opener).settle(); + assert!(fixture.by_label("Clear All").is_some(), "a click on the opener opens the menu"); + }; + open(&mut fixture); + fixture.key(egui::Key::Enter, egui::Modifiers::NONE).settle(); + assert!(fixture.by_label("Clear All").is_none(), "Return with no row lit closes the menu"); + assert!(fixture.by_label("Report.txt").is_none(), "and opens no submenu"); + assert_eq!(ran.get(), None, "and runs no row"); + open(&mut fixture); + let reset = fixture.by_label("Reset").expect("the Reset row").center(); + fixture.frame(vec![pointer::moved(reset)]).settle(); + fixture.key(egui::Key::Enter, egui::Modifiers::NONE).settle(); + assert_eq!(ran.get(), Some("Reset"), "Return runs the row the pointer lit"); + assert!(fixture.by_label("Clear All").is_none(), "and the run closes the menu"); +} From 53dd357b399ccb737390e7627c8c01614a76a660 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Tue, 24 Nov 2026 14:49:42 +0100 Subject: [PATCH 10/13] menu: the first-key rule of a pointer-opened menu covers icon rows The rule that Return or Space as the first key in a menu the pointer opened runs the lit row, or with none lit only closes the menu, lived in MenuItem::update. MenuIconRow reads the same RowInput and still picked its focused icon on that key. RowInput::of now decides and answers the withheld first key, and RowInput::activate skips a withheld row, so MenuItem and MenuIconRow share one rule. MenuIconRow picks no icon and reports no activation on a withheld key. Trial: a pointer-opened menu whose focused first row is an icon row; Return with nothing lit closes the menu and runs nothing, and with a row lit runs that row and picks no icon. --- crates/ui-widgets/src/menu/icon_row.rs | 16 +++++-- crates/ui-widgets/src/menu/item.rs | 51 ++++++++++++--------- crates/ui-widgets/tests/it/menu/icon_row.rs | 48 ++++++++++++++++++- 3 files changed, 89 insertions(+), 26 deletions(-) diff --git a/crates/ui-widgets/src/menu/icon_row.rs b/crates/ui-widgets/src/menu/icon_row.rs index f327f81ea..98b2d6841 100644 --- a/crates/ui-widgets/src/menu/icon_row.rs +++ b/crates/ui-widgets/src/menu/icon_row.rs @@ -70,12 +70,14 @@ pub struct MenuIconRow<'a> { common: Common, icons: &'a [MenuIcon<'a>], picked: Option, + /// The row took a key activation it does not run: the first key in a menu the pointer opened (`RowInput::of`). + withheld: bool, } impl<'a> MenuIconRow<'a> { /// A row named `label` of `icons`. pub fn new(label: impl Into