diff --git a/frontend/src/components/context_menu.rs b/frontend/src/components/context_menu.rs index 6934db4..9abf309 100644 --- a/frontend/src/components/context_menu.rs +++ b/frontend/src/components/context_menu.rs @@ -1,4 +1,5 @@ use leptos::*; +use leptos_use::on_click_outside; #[component] pub fn ContextMenu( @@ -8,6 +9,10 @@ pub fn ContextMenu( on_close: Callback<()>, on_action: Callback<(String, String)>, // (Action, Hash) ) -> impl IntoView { + let container_ref = create_node_ref::(); + + let _ = on_click_outside(container_ref, move |_| on_close.call(())); + let handle_action = move |action: &str| { let hash = torrent_hash.clone(); let action_str = action.to_string(); @@ -22,16 +27,8 @@ pub fn ContextMenu( } view! { - // Backdrop to catch clicks outside -
-
impl IntoView { set_active_dropdown.set(0); }; - view! { - // Transparent overlay to close dropdowns when clicking outside - -
-
+ // Refs for click outside detection + let down_ref = create_node_ref::(); + let up_ref = create_node_ref::(); + let theme_ref = create_node_ref::(); + let _ = on_click_outside(down_ref, move |_| if active_dropdown.get_untracked() == 1 { close_all() }); + let _ = on_click_outside(up_ref, move |_| if active_dropdown.get_untracked() == 2 { close_all() }); + let _ = on_click_outside(theme_ref, move |_| if active_dropdown.get_untracked() == 3 { close_all() }); + + view! {
// --- DOWNLOAD SPEED DROPDOWN --- -
+
impl IntoView {
// --- UPLOAD SPEED DROPDOWN --- -
+
impl IntoView {
-
+