diff --git a/crates/ui-contract/src/contract/overlay/ui.rs b/crates/ui-contract/src/contract/overlay/ui.rs index 97d75344b..613d743f8 100644 --- a/crates/ui-contract/src/contract/overlay/ui.rs +++ b/crates/ui-contract/src/contract/overlay/ui.rs @@ -159,6 +159,11 @@ impl<'a> OverlayUi<'a> { }; // An in-place editor is part of its owner: the owner's node reports no popup of it. let (kind, peers, reported) = (overlay.popup, overlay.opener.is_none(), overlay.role != LayerRole::InPlaceEditor); + // 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| { if reported { diff --git a/crates/ui-contract/src/runtime/focus.rs b/crates/ui-contract/src/runtime/focus.rs index 1bac55998..50a405e4f 100644 --- a/crates/ui-contract/src/runtime/focus.rs +++ b/crates/ui-contract/src/runtime/focus.rs @@ -1253,6 +1253,14 @@ pub fn keyboard_in_menu(ctx: &Context) -> bool { focused_rec(ctx).is_some_and(|rec| menu_scope(ctx, rec.scope).is_some()) && with(ctx, |state| state.visible) } +/// Whether the focused stop took the focus when its scope opened (a menu's first row as the menu showed) and has kept +/// it since: no key, press or request (an AccessKit `Focus`, the app's [`request`]) has moved it. A menu row reads it +/// to tell a key that reached the row its menu's opening focused, which may not be meant for it, from a key on a row +/// the user or assistive technology chose. +pub fn focus_came_with_open(ctx: &Context) -> bool { + focused_rec(ctx).is_some_and(|rec| origin(ctx, &rec) == Some(FocusOrigin::Open)) +} + /// The innermost menu scope around the component whose body is running: the menu a row being shown sits in. #[doc(hidden)] pub fn running_menu(ctx: &Context) -> Option { diff --git a/crates/ui-contract/src/runtime/focus/registration.rs b/crates/ui-contract/src/runtime/focus/registration.rs index a83dc80a2..d5f175b52 100644 --- a/crates/ui-contract/src/runtime/focus/registration.rs +++ b/crates/ui-contract/src/runtime/focus/registration.rs @@ -208,13 +208,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/src/menu/icon_row.rs b/crates/ui-widgets/src/menu/icon_row.rs index ac5587adf..bedb44edf 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