From 61909fff032f8d7a66e30c2134391dbaf3231538 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Thu, 30 Apr 2026 00:02:46 -0700 Subject: [PATCH] fix(tab-bar): dismiss tab context menu on window blur for webview clicks (#1274) Electron elements run in a separate process, so clicks inside them don't dispatch pointerdown on the renderer document. Radix DropdownMenu relies on document pointerdown for outside-click detection and therefore misses webview clicks, leaving the menu stuck open. Listening for window blur catches the moment focus leaves the renderer (including into a webview) and closes the menu. Co-authored-by: Orca --- src/renderer/src/components/tab-bar/BrowserTab.tsx | 14 ++++++++++++++ .../src/components/tab-bar/EditorFileTab.tsx | 14 ++++++++++++++ .../src/components/tab-bar/SortableTab.tsx | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/renderer/src/components/tab-bar/BrowserTab.tsx b/src/renderer/src/components/tab-bar/BrowserTab.tsx index 8c2e62b75..3d960dc40 100644 --- a/src/renderer/src/components/tab-bar/BrowserTab.tsx +++ b/src/renderer/src/components/tab-bar/BrowserTab.tsx @@ -97,6 +97,20 @@ export default function BrowserTab({ return () => window.removeEventListener(CLOSE_ALL_CONTEXT_MENUS_EVENT, closeMenu) }, []) + // Why: Electron elements run in a separate process, so clicking + // inside one never dispatches a pointerdown on the renderer document. Radix + // DropdownMenu relies on document pointerdown for outside-click detection, + // so it misses webview clicks. Listening for window blur catches the moment + // focus leaves the renderer (including into a webview). + useEffect(() => { + if (!menuOpen) { + return + } + const dismiss = (): void => setMenuOpen(false) + window.addEventListener('blur', dismiss) + return () => window.removeEventListener('blur', dismiss) + }, [menuOpen]) + return ( <>
window.removeEventListener(CLOSE_ALL_CONTEXT_MENUS_EVENT, closeMenu) }, []) + // Why: Electron elements run in a separate process, so clicking + // inside one never dispatches a pointerdown on the renderer document. Radix + // DropdownMenu relies on document pointerdown for outside-click detection, + // so it misses webview clicks. Listening for window blur catches the moment + // focus leaves the renderer (including into a webview). + useEffect(() => { + if (!menuOpen) { + return + } + const dismiss = (): void => setMenuOpen(false) + window.addEventListener('blur', dismiss) + return () => window.removeEventListener('blur', dismiss) + }, [menuOpen]) + return ( <>
window.removeEventListener(CLOSE_ALL_CONTEXT_MENUS_EVENT, closeMenu) }, []) + // Why: Electron elements run in a separate process, so clicking + // inside one never dispatches a pointerdown on the renderer document. Radix + // DropdownMenu relies on document pointerdown for outside-click detection, + // so it misses webview clicks. Listening for window blur catches the moment + // focus leaves the renderer (including into a webview). + useEffect(() => { + if (!menuOpen) { + return + } + const dismiss = (): void => setMenuOpen(false) + window.addEventListener('blur', dismiss) + return () => window.removeEventListener('blur', dismiss) + }, [menuOpen]) + // Why: while editing, suppress dnd-kit drag listeners and tab-activation/double-click // handlers so typing/clicking inside the inline input doesn't start a drag, re-open the // editor, or steal focus away from the input. We still spread `attributes` unconditionally