Skip to content

Commit 62ea1c1

Browse files
authored
#7935 Fix: ContextMenu mouseup selects what's behind on the canvas (#7936)
fix ContextMenu propagating mouseup to EngineStream
1 parent ca9f96d commit 62ea1c1

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/components/ContextMenu.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Dialog } from '@headlessui/react'
2-
import type { RefObject } from 'react'
2+
import type { RefObject, MouseEvent } from 'react'
33
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
44
import toast from 'react-hot-toast'
55
import { useHotkeys } from 'react-hotkeys-hook'
@@ -55,6 +55,19 @@ export function ContextMenu({
5555
[guard, setPosition, setOpen]
5656
)
5757

58+
const onDialogMouseUp = useCallback((e: MouseEvent) => {
59+
// Prevent mouseup event to propagate to EngineStream's handleMouseUp which would update the selection depending
60+
// on what's behind the ContextMenu at the position of the mouse.
61+
// Bug without this:
62+
// - Open ContextMenu
63+
// - Click on an item in the ContextMenu and see how what's behind will get selected.
64+
e.stopPropagation()
65+
}, [])
66+
67+
const onCloseDialog = useCallback(() => {
68+
setOpen(false)
69+
}, [])
70+
5871
const dialogPositionStyle = useMemo(() => {
5972
if (!dialogRef.current)
6073
return {
@@ -107,7 +120,7 @@ export function ContextMenu({
107120
}, [menuTargetElement?.current])
108121

109122
return (
110-
<Dialog open={open} onClose={() => setOpen(false)}>
123+
<Dialog open={open} onClose={onCloseDialog} onMouseUp={onDialogMouseUp}>
111124
<div
112125
className="fixed inset-0 z-50 w-screen h-screen"
113126
onContextMenu={(e) => {

0 commit comments

Comments
 (0)