Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): close tabs with middle click (#95343)

Dylan Martinef8461184452
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md b/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md
index c272b2b26bbe..a0c5844a028b 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md
+++ b/products/desktop/packages/ui/src/features/browser-tabs/AGENTS.md
@@ -111,6 +111,7 @@ differ. Desktop ships first.
### Closing
- Closing the active tab focuses its neighbour.
+- Middle-clicking any tab closes it, including a pinned tab.
- Closing the last tab of a **secondary** window closes the window. Closing the
last tab of the **primary** window replaces it with a fresh `/activity` tab.
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.test.tsx b/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.test.tsx
index 30b2a1cf3a55..b3797097147f 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.test.tsx
+++ b/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.test.tsx
@@ -66,6 +66,19 @@ describe("TabStrip", () => {
expect(props.onSelect).not.toHaveBeenCalled();
});
+ it.each([
+ ["an unpinned", false],
+ ["a pinned", true],
+ ])("closes %s tab without selecting it on middle-click", (_label, pinned) => {
+ const props = setup({ tabs: [{ ...tabs[0], pinned }, tabs[1]] });
+ const tab = pinned
+ ? screen.getByLabelText("Overview (pinned)")
+ : screen.getByText("Overview");
+ fireEvent(tab, new MouseEvent("auxclick", { bubbles: true, button: 1 }));
+ expect(props.onClose).toHaveBeenCalledWith("t1");
+ expect(props.onSelect).not.toHaveBeenCalled();
+ });
+
it("calls onNewTab when the new-tab button is clicked", async () => {
const props = setup();
await userEvent.click(screen.getByLabelText("New tab"));
diff --git a/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.tsx b/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.tsx
index 31d2b72e49b7..599be5458acb 100644
--- a/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.tsx
+++ b/products/desktop/packages/ui/src/features/browser-tabs/TabStrip.tsx
@@ -177,6 +177,12 @@ function SortableTabPill({
const pill = (
<div
ref={ref}
+ onAuxClick={(event) => {
+ if (event.button !== 1) return;
+ event.preventDefault();
+ event.stopPropagation();
+ onClose(tab.id);
+ }}
className={
tab.pinned
? "no-drag flex shrink-0 items-center"