From 7486d3dde05c5edc3ce25a67cdad2f2c70cab1f3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 20 Jun 2023 08:01:41 +0100 Subject: [PATCH] Close context menu when using mouse wheel or menu touching scrollbars --- .../components/grid/layout/GridScrollWrapper.svelte | 6 ++++++ .../src/components/grid/overlays/ScrollOverlay.svelte | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/frontend-core/src/components/grid/layout/GridScrollWrapper.svelte b/packages/frontend-core/src/components/grid/layout/GridScrollWrapper.svelte index 04f0960057..7599135c63 100644 --- a/packages/frontend-core/src/components/grid/layout/GridScrollWrapper.svelte +++ b/packages/frontend-core/src/components/grid/layout/GridScrollWrapper.svelte @@ -12,6 +12,7 @@ bounds, hoveredRowId, hiddenColumnsWidth, + menu, } = getContext("grid") export let scrollVertically = false @@ -30,6 +31,11 @@ const handleWheel = e => { e.preventDefault() debouncedHandleWheel(e.deltaX, e.deltaY, e.clientY) + + // If a context menu was visible, hide it + if ($menu.visible) { + menu.actions.close() + } } const debouncedHandleWheel = domDebounce((deltaX, deltaY, clientY) => { const { top, left } = $scroll diff --git a/packages/frontend-core/src/components/grid/overlays/ScrollOverlay.svelte b/packages/frontend-core/src/components/grid/overlays/ScrollOverlay.svelte index 654a7529b5..315c3d21e5 100644 --- a/packages/frontend-core/src/components/grid/overlays/ScrollOverlay.svelte +++ b/packages/frontend-core/src/components/grid/overlays/ScrollOverlay.svelte @@ -16,6 +16,7 @@ scrollTop, height, isDragging, + menu, } = getContext("grid") // State for dragging bars @@ -45,6 +46,13 @@ $: availWidth = renderWidth - barWidth $: barLeft = ScrollBarSize + availWidth * ($scrollLeft / $maxScrollLeft) + // Helper to close the context menu if it's open + const closeMenu = () => { + if ($menu.visible) { + menu.actions.close() + } + } + // V scrollbar drag handlers const startVDragging = e => { e.preventDefault() @@ -53,6 +61,7 @@ document.addEventListener("mousemove", moveVDragging) document.addEventListener("mouseup", stopVDragging) isDraggingV = true + closeMenu() } const moveVDragging = domDebounce(e => { const delta = e.clientY - initialMouse @@ -77,6 +86,7 @@ document.addEventListener("mousemove", moveHDragging) document.addEventListener("mouseup", stopHDragging) isDraggingH = true + closeMenu() } const moveHDragging = domDebounce(e => { const delta = e.clientX - initialMouse