Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/web/src/components/RightPanelTabs.logic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, expect, it } from "vite-plus/test";

import { shouldCloseRightPanelTabOnAuxClick } from "./RightPanelTabs.logic";

describe("shouldCloseRightPanelTabOnAuxClick", () => {
it("closes right panel tabs only for middle mouse clicks", () => {
expect(shouldCloseRightPanelTabOnAuxClick(0)).toBe(false);
expect(shouldCloseRightPanelTabOnAuxClick(1)).toBe(true);
expect(shouldCloseRightPanelTabOnAuxClick(2)).toBe(false);
});
});
3 changes: 3 additions & 0 deletions apps/web/src/components/RightPanelTabs.logic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function shouldCloseRightPanelTabOnAuxClick(button: number): boolean {
return button === 1;
}
16 changes: 16 additions & 0 deletions apps/web/src/components/RightPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useTheme } from "~/hooks/useTheme";

import { PreviewPanelShell, type PreviewPanelMode } from "./preview/PreviewPanelShell";
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
import { shouldCloseRightPanelTabOnAuxClick } from "./RightPanelTabs.logic";

interface RightPanelTabsProps {
mode: PreviewPanelMode;
Expand Down Expand Up @@ -330,6 +331,19 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
},
[props],
);
const handleTabMouseDown = useCallback((event: ReactMouseEvent) => {
if (!shouldCloseRightPanelTabOnAuxClick(event.button)) return;
event.preventDefault();
}, []);
const handleTabAuxClick = useCallback(
(event: ReactMouseEvent, surface: RightPanelSurface) => {
if (!shouldCloseRightPanelTabOnAuxClick(event.button)) return;
event.preventDefault();
event.stopPropagation();
props.onCloseSurface(surface);
},
[props],
);

useEffect(() => {
const activeTab = tabListRef.current?.querySelector<HTMLElement>("[data-active-tab='true']");
Expand Down Expand Up @@ -365,6 +379,8 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
<div
key={surface.id}
data-active-tab={active}
onMouseDown={handleTabMouseDown}
onAuxClick={(event) => handleTabAuxClick(event, surface)}
onContextMenu={(event) => void handleTabContextMenu(event, surface)}
className={cn(
"group flex h-7 min-w-25 max-w-44 shrink-0 items-center gap-1.5 rounded-md px-2 text-sm",
Expand Down
Loading