menu: Fix #1545 Popover change broken submenu click in dropdown menu. (#1563)

This bug was caused by #1545.
This commit is contained in:
Jason Lee 2025-11-11 22:18:26 +08:00 committed by GitHub
parent 3cd94ea0be
commit a185d8ed24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 16 deletions

View file

@ -89,6 +89,7 @@ where
Popover::new(SharedString::from(format!("popover:{}", self.id)))
.appearance(false)
.overlay_closable(false)
.trigger(self.trigger)
.trigger_style(self.style)
.anchor(self.anchor)

View file

@ -35,6 +35,7 @@ pub struct Popover {
trigger_style: Option<StyleRefinement>,
mouse_button: MouseButton,
appearance: bool,
overlay_closable: bool,
on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
}
@ -52,6 +53,7 @@ impl Popover {
children: vec![],
mouse_button: MouseButton::Left,
appearance: true,
overlay_closable: true,
default_open: false,
open: None,
on_open_change: None,
@ -121,6 +123,12 @@ impl Popover {
self
}
/// Set whether clicking outside the popover will dismiss it, default is `true`.
pub fn overlay_closable(mut self, closable: bool) -> Self {
self.overlay_closable = closable;
self
}
/// Set the content builder for content of the Popover.
///
/// This callback will called every time on render the popover.
@ -373,24 +381,17 @@ impl RenderOnce for Popover {
)
})
.children(self.children)
.when(self.appearance, |this| {
let state = state.clone();
this.on_mouse_down_out(move |_, window, cx| {
state.update(cx, |state, cx| {
state.toggle_open(window, cx);
});
cx.notify(parent_view_id);
.when(self.overlay_closable, |this| {
this.on_mouse_down_out({
let state = state.clone();
move |_, window, cx| {
state.update(cx, |state, cx| {
state.dismiss(window, cx);
});
cx.notify(parent_view_id);
}
})
})
.on_mouse_down_out({
let state = state.clone();
move |_, window, cx| {
state.update(cx, |state, cx| {
state.dismiss(window, cx);
});
cx.notify(parent_view_id);
}
})
.refine_style(&self.style),
),
)