From 07e2594d8b5b9c6ee848586a71b5e07b65905a7c Mon Sep 17 00:00:00 2001 From: matei jordache Date: Wed, 25 Mar 2026 13:36:37 -0700 Subject: [PATCH] add close menu if click outside --- frontend/src/App.jsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 280d8df..cbfa37d 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1055,6 +1055,18 @@ function Flow() { setContextMenu({ x: event.clientX, y: event.clientY }); }, []); + useEffect(() => { + if (!contextMenu) return undefined; + + const handlePointerDown = (event) => { + if (event.target.closest('.context-menu')) return; + setContextMenu(null); + }; + + window.addEventListener('pointerdown', handlePointerDown, true); + return () => window.removeEventListener('pointerdown', handlePointerDown, true); + }, [contextMenu]); + // ── Render ────────────────────────────────────────────────────────── return ( @@ -1089,9 +1101,7 @@ function Flow() { {/* React Flow canvas */} -
{ - if (!e.target.closest('.context-menu')) setContextMenu(null); - }} onDrop={onDropFile} onDragOver={onDragOver}> +