From 8bd0e81ad92cf02befcad2659bad40cb6351c0ba Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sat, 28 Nov 2026 22:25:02 +0000 Subject: [PATCH 1/2] fix(web): snapshot tooltips open at once from adjacent actions Switch SnapShotCopyButton and SnapShotContentsButton in SnapShotAttachmentDetails.tsx from standalone Base UI Tooltip wrappers to SharedTooltipTrigger so moving across adjacent controls in ExpandedImageDialog and ComposerAttachmentStrip switches the shared tooltip immediately without waiting a fresh hover delay. --- .../chat/ExpandedImageDialog.browser.test.tsx | 92 +++++++++++++- .../chat/SnapShotAttachmentDetails.tsx | 118 +++++++++--------- 2 files changed, 148 insertions(+), 62 deletions(-) diff --git a/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx b/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx index 6707dcd85382b..10086f280c1f7 100644 --- a/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx +++ b/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx @@ -4,7 +4,8 @@ import { describe, expect, it, vi } from "vite-plus/test"; import { cdp, page, userEvent } from "vite-plus/test/browser"; import "~/index.css"; -import { render } from "../../../test/render"; +import { act, fakeTimers, render } from "../../../test/render"; +import { SharedTooltipProvider } from "../ui/shared-tooltip"; import { ExpandedImageDialog } from "./ExpandedImageDialog"; const PIXEL = @@ -344,4 +345,93 @@ describe("ExpandedImageDialog", () => { } }, ); + + it("shares hover tooltip timing across snapshot contents, Draw on image, and Copy snapshot", async () => { + const file = new File([await (await fetch(PIXEL)).blob()], "shot.png", { type: "image/png" }); + const onCopySnapshot = vi.fn(async () => {}); + await using screen = await render( + + null), + }, + onCopySnapshot, + }, + ], + index: 0, + }} + onClose={vi.fn()} + /> + , + // The dialog renders no links and reads no route. + { router: false }, + ); + + const contentsButton = screen.getByRole("button", { name: "No accessibility data" }); + const drawButton = screen.getByRole("button", { name: "Draw on image" }); + const copyButton = screen.getByRole("button", { name: "Copy snapshot" }); + await expect.element(drawButton).toBeVisible(); + + { + using _timers = fakeTimers(); + await userEvent.hover(drawButton); + await act(() => vi.advanceTimersByTime(600)); + expect(page.getByText("Draw on image").element()).toBeVisible(); + + await userEvent.hover(copyButton); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("Copy snapshot").element()).toBeVisible(); + expect(page.getByText("Draw on image").query()).toBeNull(); + + await userEvent.hover(contentsButton); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("No accessibility data").element()).toBeVisible(); + expect(page.getByText("Copy snapshot").query()).toBeNull(); + + await userEvent.hover(drawButton); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("Draw on image").element()).toBeVisible(); + expect(page.getByText("No accessibility data").query()).toBeNull(); + + await userEvent.unhover(drawButton); + await act(() => vi.advanceTimersByTime(100)); + } + + // Clicking SnapShotContentsButton dismisses its tooltip, opens the popover, and leaves no stuck tooltip on close. + await userEvent.hover(contentsButton); + await expect.element(page.getByText("No accessibility data")).toBeVisible(); + await userEvent.click(contentsButton); + await expect.element(page.getByText("Accessibility data")).toBeVisible(); + await expect.element(page.getByText("No accessibility data")).not.toBeInTheDocument(); + await userEvent.click(contentsButton); + await expect.element(page.getByText("Accessibility data")).not.toBeInTheDocument(); + expect(page.getByText("No accessibility data").query()).toBeNull(); + + // Keyboard focus opens the shared tooltip immediately on both snapshot buttons. + await userEvent.unhover(contentsButton); + (drawButton.element() as HTMLElement).focus(); + await userEvent.keyboard("{Shift>}{Tab}{/Shift}"); + await expect.element(contentsButton).toHaveFocus(); + await expect.element(page.getByText("No accessibility data")).toBeVisible(); + await userEvent.keyboard("{Tab}{Tab}"); + await expect.element(copyButton).toHaveFocus(); + await expect.element(page.getByText("Copy snapshot")).toBeVisible(); + + // Triggering Copy snapshot disables the button and suppresses its tooltip until copied resets. + await userEvent.keyboard("{Enter}"); + await vi.waitFor(() => expect(onCopySnapshot).toHaveBeenCalledOnce()); + await expect.element(copyButton).toBeDisabled(); + await expect.element(page.getByText("Copy snapshot")).not.toBeInTheDocument(); + await expect.element(copyButton).toBeEnabled(); + }); }); diff --git a/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx b/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx index 58fae303d963a..09d900de020e1 100644 --- a/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx +++ b/apps/web/src/components/chat/SnapShotAttachmentDetails.tsx @@ -8,7 +8,7 @@ import { cn } from "../../lib/utils"; import { RenderErrorBoundary } from "../RenderErrorBoundary"; import { Button } from "../ui/button"; import { Popover, PopoverPopup, PopoverTitle, PopoverTrigger } from "../ui/popover"; -import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; +import { SharedTooltipTrigger } from "../ui/shared-tooltip"; import { ANCHORED_COPY_TOAST_TIMEOUT_MS, showAnchoredCopyErrorToast, @@ -88,42 +88,39 @@ export function SnapShotCopyButton({ const [copied, setCopied] = useState(false); return ( - - { - event.stopPropagation(); - void onCopy().then( - () => { - setCopied(true); - setTimeout(() => setCopied(false), ANCHORED_COPY_TOAST_TIMEOUT_MS); - }, - (error: unknown) => - showAnchoredCopyErrorToast( - ref, - error instanceof Error ? error : new Error(String(error)), - ), - ); - }} - size="xs" - variant="ghost-muted" - /> - } - > - {copied ? ( - - - Copy snapshot - - + { + event.stopPropagation(); + void onCopy().then( + () => { + setCopied(true); + setTimeout(() => setCopied(false), ANCHORED_COPY_TOAST_TIMEOUT_MS); + }, + (error: unknown) => + showAnchoredCopyErrorToast( + ref, + error instanceof Error ? error : new Error(String(error)), + ), + ); + }} + size="xs" + variant="ghost-muted" + /> + } + label={Copy snapshot} + side={side} + > + {copied ? ( + ); } @@ -146,30 +143,29 @@ export function SnapShotContentsButton({ return ( - - event.stopPropagation()} - size="icon-micro" - variant="overlay" - /> - } - /> - } - > - - {tooltip} - + event.stopPropagation()} + size="icon-micro" + variant="overlay" + /> + } + /> + } + label={tooltip} + side={side} + > +
From a0fda4852f240ce015a34be64ca2e59da73c6edb Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 28 Nov 2026 23:05:41 +0000 Subject: [PATCH 2/2] test(web): narrow snapshot tooltip test to the hover-timing regression The popover, keyboard-focus and disabled-while-copied steps re-tested SharedTooltipTrigger itself, not this change. Co-Authored-By: Claude Opus 5.5 --- .../chat/ExpandedImageDialog.browser.test.tsx | 67 +++++-------------- 1 file changed, 15 insertions(+), 52 deletions(-) diff --git a/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx b/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx index 10086f280c1f7..1104af19a15f3 100644 --- a/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx +++ b/apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx @@ -346,9 +346,8 @@ describe("ExpandedImageDialog", () => { }, ); - it("shares hover tooltip timing across snapshot contents, Draw on image, and Copy snapshot", async () => { + it("snapshot actions share tooltip timing with Draw on image", async () => { const file = new File([await (await fetch(PIXEL)).blob()], "shot.png", { type: "image/png" }); - const onCopySnapshot = vi.fn(async () => {}); await using screen = await render( { mimeType: "image/png", save: vi.fn(async () => null), }, - onCopySnapshot, + onCopySnapshot: vi.fn(async () => {}), }, ], index: 0, @@ -382,56 +381,20 @@ describe("ExpandedImageDialog", () => { const copyButton = screen.getByRole("button", { name: "Copy snapshot" }); await expect.element(drawButton).toBeVisible(); - { - using _timers = fakeTimers(); - await userEvent.hover(drawButton); - await act(() => vi.advanceTimersByTime(600)); - expect(page.getByText("Draw on image").element()).toBeVisible(); - - await userEvent.hover(copyButton); - await act(() => vi.advanceTimersByTime(1)); - expect(page.getByText("Copy snapshot").element()).toBeVisible(); - expect(page.getByText("Draw on image").query()).toBeNull(); - - await userEvent.hover(contentsButton); - await act(() => vi.advanceTimersByTime(1)); - expect(page.getByText("No accessibility data").element()).toBeVisible(); - expect(page.getByText("Copy snapshot").query()).toBeNull(); - - await userEvent.hover(drawButton); - await act(() => vi.advanceTimersByTime(1)); - expect(page.getByText("Draw on image").element()).toBeVisible(); - expect(page.getByText("No accessibility data").query()).toBeNull(); - - await userEvent.unhover(drawButton); - await act(() => vi.advanceTimersByTime(100)); - } + using _timers = fakeTimers(); + await userEvent.hover(drawButton); + await act(() => vi.advanceTimersByTime(600)); + expect(page.getByText("Draw on image").element()).toBeVisible(); + + // Moving across adjacent actions swaps the tooltip at once instead of waiting out the delay again. + await userEvent.hover(copyButton); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("Copy snapshot").element()).toBeVisible(); + expect(page.getByText("Draw on image").query()).toBeNull(); - // Clicking SnapShotContentsButton dismisses its tooltip, opens the popover, and leaves no stuck tooltip on close. await userEvent.hover(contentsButton); - await expect.element(page.getByText("No accessibility data")).toBeVisible(); - await userEvent.click(contentsButton); - await expect.element(page.getByText("Accessibility data")).toBeVisible(); - await expect.element(page.getByText("No accessibility data")).not.toBeInTheDocument(); - await userEvent.click(contentsButton); - await expect.element(page.getByText("Accessibility data")).not.toBeInTheDocument(); - expect(page.getByText("No accessibility data").query()).toBeNull(); - - // Keyboard focus opens the shared tooltip immediately on both snapshot buttons. - await userEvent.unhover(contentsButton); - (drawButton.element() as HTMLElement).focus(); - await userEvent.keyboard("{Shift>}{Tab}{/Shift}"); - await expect.element(contentsButton).toHaveFocus(); - await expect.element(page.getByText("No accessibility data")).toBeVisible(); - await userEvent.keyboard("{Tab}{Tab}"); - await expect.element(copyButton).toHaveFocus(); - await expect.element(page.getByText("Copy snapshot")).toBeVisible(); - - // Triggering Copy snapshot disables the button and suppresses its tooltip until copied resets. - await userEvent.keyboard("{Enter}"); - await vi.waitFor(() => expect(onCopySnapshot).toHaveBeenCalledOnce()); - await expect.element(copyButton).toBeDisabled(); - await expect.element(page.getByText("Copy snapshot")).not.toBeInTheDocument(); - await expect.element(copyButton).toBeEnabled(); + await act(() => vi.advanceTimersByTime(1)); + expect(page.getByText("No accessibility data").element()).toBeVisible(); + expect(page.getByText("Copy snapshot").query()).toBeNull(); }); });