fix(desktop): keep context submenu open while scrolling
This commit is contained in:
1 parent
2980e32c9d
commit
7ae36ee832
4 files changed
+96
-5
No files matched your search
@@ -70,7 +70,16 @@ function onPointerDownOutside(e: PointerEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
function isScrollInsideMenu(e: Event): boolean {
|
||||
const target = e.target;
|
||||
if (!(target instanceof Node)) return false;
|
||||
return !!(menuRef.value?.contains(target) || subRef.value?.contains(target));
|
||||
}
|
||||
|
||||
function onScroll(e: Event) {
|
||||
// Submenus (and tall main menus) are scrollable; ignore their own scroll
|
||||
// so wheel/trackpad scrolling does not dismiss the menu.
|
||||
if (isScrollInsideMenu(e)) return;
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -262,7 +271,7 @@ onBeforeUnmount(() => {
|
||||
<slot :onContextMenu="onContextMenu" />
|
||||
<!-- Main menu -->
|
||||
<Teleport to="body">
|
||||
<div v-if="show" ref="menuRef" :style="{ position: 'fixed', left: x + 'px', top: y + 'px', zIndex: 9999 }" class="bg-popover text-popover-foreground min-w-40 w-max max-w-[calc(100vw-16px)] rounded-md p-1 overflow-y-auto ring-1 ring-foreground/10 shadow-lg">
|
||||
<div v-if="show" ref="menuRef" data-dbx-context-menu :style="{ position: 'fixed', left: x + 'px', top: y + 'px', zIndex: 9999 }" class="bg-popover text-popover-foreground min-w-40 w-max max-w-[calc(100vw-16px)] rounded-md p-1 overflow-y-auto ring-1 ring-foreground/10 shadow-lg">
|
||||
<template v-for="(item, index) in activeItems" :key="index">
|
||||
<template v-if="item.visible !== false">
|
||||
<div v-if="item.separator" class="-mx-1 my-1 flex items-center px-1">
|
||||
@@ -287,6 +296,7 @@ onBeforeUnmount(() => {
|
||||
<div
|
||||
v-if="show && activeSubIndex !== null && activeItems[activeSubIndex]?.children?.length"
|
||||
ref="subRef"
|
||||
data-dbx-context-menu
|
||||
:style="{ position: 'fixed', left: subX + 'px', top: subY + 'px', zIndex: 10000, maxHeight: 'min(420px, calc(100vh - 16px))' }"
|
||||
class="bg-popover text-popover-foreground min-w-56 w-max max-w-[calc(100vw-16px)] rounded-md p-1 overflow-y-auto ring-1 ring-foreground/10 shadow-lg"
|
||||
@mouseenter="onSubMouseEnter"
|
||||
|
||||
Reference in new issue
Block a user