Skip to content

Commit

Permalink
Fix MenuBar items re-opening on hover when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik committed Jan 15, 2024
1 parent 46b8880 commit 466e1c8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/vizia_core/src/views/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl MenuBar {
);
});

// MenuController { open_menu: None }.build(cx);
(content)(cx);
})
.layout_type(LayoutType::Row)
Expand Down Expand Up @@ -140,12 +139,14 @@ impl View for Submenu {
// cx.focus();
// }
if self.open_on_hover {
// Close any open submenus of the parent
let parent = cx.tree.get_parent(cx.current).unwrap();
cx.emit_custom(
Event::new(MenuEvent::Close)
.target(parent)
.propagate(Propagation::Subtree),
);
// Open this submenu
cx.emit(MenuEvent::Open);
}
}
Expand Down Expand Up @@ -189,6 +190,14 @@ impl View for Submenu {
self.is_open ^= true;
if self.is_open {
cx.emit(MenuEvent::MenuIsOpen);
} else {
// If the parent is a MenuBar then this will reset the is_open state
let parent = cx.tree.get_parent(cx.current).unwrap();
cx.emit_custom(
Event::new(MenuEvent::CloseAll)
.target(parent)
.propagate(Propagation::Direct),
);
}
meta.consume();
}
Expand Down

0 comments on commit 466e1c8

Please sign in to comment.