diff --git a/crates/ui/src/components/popover_menu.rs b/crates/ui/src/components/popover_menu.rs index 58d11503aa..4be7ee5c4c 100644 --- a/crates/ui/src/components/popover_menu.rs +++ b/crates/ui/src/components/popover_menu.rs @@ -169,6 +169,7 @@ pub struct PopoverMenuFrameState { impl Element for PopoverMenu { type BeforeLayout = PopoverMenuFrameState; + type AfterLayout = (); type BeforePaint = Option; fn before_layout(&mut self, cx: &mut ElementContext) -> (gpui::LayoutId, Self::BeforeLayout) { @@ -214,10 +215,34 @@ impl Element for PopoverMenu { }) } + fn after_layout( + &mut self, + bounds: Bounds, + before_layout: &mut Self::BeforeLayout, + cx: &mut ElementContext, + ) -> (Option>, Self::AfterLayout) { + let mut focus_target_bounds = None; + + if let Some(child) = before_layout.child_element.as_mut() { + if let Some(child_focus_target_bounds) = child.after_layout(cx) { + focus_target_bounds = Some(child_focus_target_bounds); + } + } + + if let Some(menu) = before_layout.menu_element.as_mut() { + if let Some(menu_focus_target_bounds) = menu.after_layout(cx) { + focus_target_bounds = Some(menu_focus_target_bounds); + } + } + + (focus_target_bounds, ()) + } + fn before_paint( &mut self, _bounds: Bounds, before_layout: &mut Self::BeforeLayout, + _after_layout: &mut Self::AfterLayout, cx: &mut ElementContext, ) -> Option { self.with_element_state(cx, |_this, element_state, cx| { @@ -241,6 +266,7 @@ impl Element for PopoverMenu { &mut self, _: Bounds, before_layout: &mut Self::BeforeLayout, + _after_layout: &mut Self::AfterLayout, child_hitbox: &mut Option, cx: &mut ElementContext, ) {