Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(tabbar): close the options menu on a press anywhere outside it

Bas Milius9530f70ac44c
diff --git a/src/renderer/components/TabBar.test.tsx b/src/renderer/components/TabBar.test.tsx
index f59a33083..3473f9bf5 100644
--- a/src/renderer/components/TabBar.test.tsx
+++ b/src/renderer/components/TabBar.test.tsx
@@ -115,6 +115,28 @@ describe('TabBar caret menu', () => {
// …and the menu closes behind it, like every other action in this menu.
expect(document.querySelector('.tab-menu')).toBeNull()
})
+
+ it('closes on a press anywhere outside it, including the bar the menu hangs from', async () => {
+ // The dismiss backdrop is below the bar so a click on another tab still switches projects,
+ // which leaves the bar itself unable to close the menu without this.
+ expect(document.querySelector('.tab-menu')).not.toBeNull()
+ await act(async () => {
+ host
+ .querySelector('.tabbar')!
+ .dispatchEvent(new Event('pointerdown', { bubbles: true }))
+ })
+ expect(document.querySelector('.tab-menu')).toBeNull()
+ })
+
+ it('leaves the caret to its own toggle, so pressing it while open does not reopen the menu', async () => {
+ const caret = host.querySelector<HTMLButtonElement>('.tab__caret')!
+ await act(async () => {
+ caret.dispatchEvent(new Event('pointerdown', { bubbles: true }))
+ })
+ expect(document.querySelector('.tab-menu')).not.toBeNull()
+ await click(caret)
+ expect(document.querySelector('.tab-menu')).toBeNull()
+ })
})
describe('TabBar New-project pin', () => {
let root: Root
diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsx
index c112c8b25..b64f74a65 100644
--- a/src/renderer/components/TabBar.tsx
+++ b/src/renderer/components/TabBar.tsx
@@ -212,6 +212,23 @@ export function TabBar({
?.scrollIntoView({ behavior: 'smooth', inline: 'nearest', block: 'nearest' })
}, [activeId, projects.length])
+ // The backdrop deliberately sits BELOW the bar, so a click on another tab switches to it in one
+ // go instead of being swallowed as a dismiss — which leaves the bar itself (its empty stretch,
+ // the brand, the +) unable to close the menu. This covers exactly that gap, and it closes
+ // WITHOUT consuming the event, so the click still lands wherever it was aimed.
+ useEffect(() => {
+ if (!menuId) return
+ const onDown = (e: PointerEvent): void => {
+ const el = e.target as HTMLElement | null
+ // The caret owns its own toggle; closing here first would let its click re-open the menu.
+ if (el?.closest('.tab-menu, .tab__caret')) return
+ closeMenu()
+ }
+ document.addEventListener('pointerdown', onDown, true)
+ return () => document.removeEventListener('pointerdown', onDown, true)
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [menuId])
+
return (
<>
{(menuId || editingId) && (