Skip to content

Commit

Permalink
Merge pull request #25 from sunhwan/master
Browse files Browse the repository at this point in the history
deactivate top menu bar when mouse leaves

@sunhwan nice work
  • Loading branch information
prabhuignoto authored Mar 24, 2021
2 parents 63a0d62 + 6e11a85 commit 1880091
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/components/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
:is-touch-device="isMobileDevice"
:on-selected="handleSelected"
:highlight-first-element="highlightFirstElement"
@deactivate="handleDeactivateMenu"
@activate="handleActivateMenu"
@activate-next="handleActivateDir"
@activate-previous="handleActivateDir"
Expand Down Expand Up @@ -186,6 +187,7 @@ export default defineComponent({
activeMenuSelection.value = -1;
activeMenuBarId.value = "";
highlightFirstElement.value = false;
handleDeactivateMenu();
}
};
Expand Down Expand Up @@ -303,6 +305,17 @@ export default defineComponent({
);
};
const handleDeactivateMenu = () => {
// keep the menubar when the sub menu is being displayed
if (!menuActive.value) {
menuItems.value = menuItems.value.map((item) =>
Object.assign({}, item, {
showMenu: false,
})
);
}
};
const handleOnShowMenu = (state: boolean, id: string) => {
menuActive.value = state;
if (state) {
Expand All @@ -322,6 +335,8 @@ export default defineComponent({
dockPosition.value === DockPosition.RIGHT
) {
return menuBarActive.value ? "expanded" : "not-expanded";
} else {
return "";
}
});
Expand All @@ -347,7 +362,7 @@ export default defineComponent({
menuItems.value = result.navigateMenu.items;
} else if ("navigateMenubar" in result) {
highlightFirstElement.value = true;
let {
const {
navigateMenubar: { nextId },
} = result;
activeMenuBarId.value = nextId;
Expand All @@ -374,6 +389,7 @@ export default defineComponent({
expandClass,
handleActivateDir,
handleActivateMenu,
handleDeactivateMenu,
handleDrag,
handleDragCancel,
handleDragEnd,
Expand Down
14 changes: 11 additions & 3 deletions src/components/MenuBarItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
:class="[...menuBarStyle, 'menu-bar-item-container']"
:style="{ background: bgColor }"
tabindex="0"
@mouseenter="setMenuViewable()"
@mouseenter="setMenuViewable(true)"
@mouseleave="setMenuViewable(false)"
@keyup="handleKeyUp"
>
<span
Expand Down Expand Up @@ -131,6 +132,7 @@ export default defineComponent({
},
emits: [
"show",
"deactivate",
"activate",
"selected",
"activate-next",
Expand All @@ -157,7 +159,13 @@ export default defineComponent({
});
// activate menu
const setMenuViewable = () => emit("activate", props.id);
const setMenuViewable = (viewable: boolean) => {
if (viewable) {
emit("activate", props.id);
} else {
emit("deactivate", props.id);
}
}
// toggle menu
const toggleMenu = (event: MouseEvent | TouchEvent) => {
Expand All @@ -171,7 +179,7 @@ export default defineComponent({
const highlightIndex = ref(-1);
const computeMenuStyle = () => {
let newStyle: {
const newStyle: {
top?: string;
left?: string;
right?: string;
Expand Down

0 comments on commit 1880091

Please sign in to comment.