Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deactivate top menu bar when mouse leaves #25

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions 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 = (id?: string) => {
sunhwan marked this conversation as resolved.
Show resolved Hide resolved
// 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 Down Expand Up @@ -374,6 +387,7 @@ export default defineComponent({
expandClass,
handleActivateDir,
handleActivateMenu,
handleDeactivateMenu,
handleDrag,
handleDragCancel,
handleDragEnd,
Expand Down
12 changes: 10 additions & 2 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 Down