From 18331f5a8b18a8cc1571fd58c4a029f0fed3f19e Mon Sep 17 00:00:00 2001 From: Adamulek123 Date: Sun, 8 Nov 2026 23:02:26 +0100 Subject: [PATCH 1/5] fix(web): dismiss lingering PR image tooltips on scroll --- .../PullRequestSummaryTab.browser.test.tsx | 52 ++++++++++++++++++- .../pullRequest/PullRequestSummaryTab.tsx | 11 ++-- .../pullRequest/PullRequestTimelineTab.tsx | 28 +++++----- apps/web/src/components/ui/tooltip.tsx | 24 +++++++-- 4 files changed, 93 insertions(+), 22 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx index 98db15d1429c..dbe3bd3f88d3 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx @@ -1,10 +1,20 @@ import { SourceControlProviderKind } from "@t3tools/contracts"; import { EnvironmentId, ProjectId, type PullRequestDetailView } from "@t3tools/contracts"; import { expect, it, vi } from "vite-plus/test"; -import { userEvent } from "vite-plus/test/browser"; +import { page, userEvent } from "vite-plus/test/browser"; +import "../../index.css"; const state = vi.hoisted(() => ({ update: vi.fn(), canUpdate: true })); +vi.mock(import("~/assets/assetUrls"), async (original) => ({ + ...(await original()), + useAssetUrlState: () => ({ + _tag: "Success", + expiresAt: Number.MAX_SAFE_INTEGER, + url: `data:image/svg+xml,${encodeURIComponent('')}`, + }), +})); + vi.mock(import("~/state/use-atom-command"), async (original) => ({ ...(await original()), useAtomCommand: (() => state.update) as never, @@ -92,6 +102,46 @@ const detail: PullRequestDetailView = { }, }; +it.each(["pointer", "keyboard"])( + "dismisses a media tooltip after %s preview and PR scroll", + async (input) => { + setup(); + const url = "https://github.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"; + await using screen = await render({ + ...detail, + body: `![Screenshot](${url})\n\n${"Paragraph\n\n".repeat(40)}`, + }); + const scroller = screen.container.querySelector( + "[data-pull-request-summary-scroll]", + )!; + scroller.style.height = "600px"; + const link = screen.getByRole("button", { name: "Preview Screenshot", exact: true }); + await expect.element(screen.getByAltText("Screenshot")).toBeVisible(); + if (input === "pointer") { + await userEvent.click(link); + } else { + await act(() => (link.element() as HTMLElement).focus()); + await userEvent.keyboard("{Enter}"); + } + await expect.element(page.getByRole("dialog")).toBeVisible(); + // Leave the opener while the dialog is up: scrolling must not depend on mouseleave. + await userEvent.hover(page.getByRole("button", { name: "Close image preview" })); + await userEvent.keyboard("{Escape}"); + await expect.element(page.getByRole("dialog")).not.toBeInTheDocument(); + expect(document.activeElement).toBe(link.element()); + await vi.waitFor(() => + expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toBe(url), + ); + await act(() => { + scroller.scrollTop = 100; + }); + await vi.waitFor(() => + expect(document.querySelector('[data-slot="tooltip-popup"]')).toBeNull(), + ); + expect(document.activeElement).toBe(link.element()); + }, +); + // The comment filter persists to localStorage, so tests that touch it start and end empty. const tab = (value = detail) => ( diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index b98a48a817b0..d955aca40256 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -43,7 +43,7 @@ import { MenuTrigger, } from "../ui/menu"; import { toastManager } from "../ui/toast"; -import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; +import { Tooltip, TooltipPopup, TooltipTrigger, TooltipScrollDismissArea } from "../ui/tooltip"; import { PullRequestActorLabel, PullRequestCheckStatusIcon, @@ -733,7 +733,12 @@ export function PullRequestSummaryTab({ }; return ( -
+
} label="Reviewers"> @@ -1029,6 +1034,6 @@ export function PullRequestSummaryTab({ )}
-
+ ); } diff --git a/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx b/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx index 36dca98e2317..6c468f95418b 100644 --- a/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx @@ -31,7 +31,7 @@ import { Button } from "../ui/button"; import { PullRequestEditButton } from "./PullRequestEditButton"; import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible"; import { toastManager } from "../ui/toast"; -import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; +import { Tooltip, TooltipPopup, TooltipTrigger, TooltipScrollDismissArea } from "../ui/tooltip"; import { buildPullRequestTimeline, groupPullRequestTimelineConversations, @@ -784,17 +784,19 @@ export function PullRequestTimelineTab({ // Virtualized: a large pull request has thousands of events, and mounting every one stalls // the page. The connector line is drawn by the content container, behind the rows. return ( - - ref={(list: LegendListRef | null) => scrollerRef(list?.getScrollableNode() ?? null)} - data={rows} - extraData={{ editable, reactions, newestCommitAt }} - keyExtractor={rowKey} - renderItem={renderRow} - estimatedItemSize={140} - className="scrollbar-gutter-both h-full px-4" - contentContainerClassName="relative mx-auto w-full max-w-3xl before:absolute before:bottom-10 before:left-[15px] before:top-6 before:w-px before:bg-border/45" - ListHeaderComponent={
} - ListFooterComponent={
} - /> + + + ref={(list: LegendListRef | null) => scrollerRef(list?.getScrollableNode() ?? null)} + data={rows} + extraData={{ editable, reactions, newestCommitAt }} + keyExtractor={rowKey} + renderItem={renderRow} + estimatedItemSize={140} + className="scrollbar-gutter-both h-full px-4" + contentContainerClassName="relative mx-auto w-full max-w-3xl before:absolute before:bottom-10 before:left-[15px] before:top-6 before:w-px before:bg-border/45" + ListHeaderComponent={
} + ListFooterComponent={
} + /> + ); } diff --git a/apps/web/src/components/ui/tooltip.tsx b/apps/web/src/components/ui/tooltip.tsx index ff8b9e8f1644..620e3f422074 100644 --- a/apps/web/src/components/ui/tooltip.tsx +++ b/apps/web/src/components/ui/tooltip.tsx @@ -19,7 +19,7 @@ const TooltipProvider = TooltipPrimitive.Provider; type TooltipActionsRef = RefObject; -// The compiler freezes context values; update hovered tooltips through calls instead of shared ref writes. +// The compiler freezes context values; update tracked tooltips through calls instead of shared ref writes. function createTooltipHoverTracker() { let hovered: { trigger: HTMLElement; actionsRef: TooltipActionsRef } | null = null; return { @@ -29,9 +29,12 @@ function createTooltipHoverTracker() { release(actionsRef: TooltipActionsRef) { if (hovered?.actionsRef === actionsRef) hovered = null; }, - dismissUnfocused() { + dismiss(dismissFocused: boolean) { const tooltip = hovered; - if (!tooltip || tooltip.trigger.contains(tooltip.trigger.ownerDocument.activeElement)) { + if ( + !tooltip || + (!dismissFocused && tooltip.trigger.contains(tooltip.trigger.ownerDocument.activeElement)) + ) { return; } hovered = null; @@ -45,7 +48,14 @@ type TooltipHoverTracker = ReturnType; const TooltipHoverContext = createContext(null); const TooltipScrollContext = createContext(null); -function TooltipScrollDismissArea({ onScrollCapture, ...props }: ComponentProps<"div">) { +function TooltipScrollDismissArea({ + onScrollCapture, + dismissFocused = false, + ...props +}: ComponentProps<"div"> & { + /** PR scrolling also dismisses tooltips reopened by media preview focus restoration. */ + dismissFocused?: boolean; +}) { const [tracker] = useState(createTooltipHoverTracker); return ( @@ -53,7 +63,7 @@ function TooltipScrollDismissArea({ onScrollCapture, ...props }: ComponentProps< {...props} onScrollCapture={(event) => { onScrollCapture?.(event); - tracker.dismissUnfocused(); + tracker.dismiss(dismissFocused); }} /> @@ -96,6 +106,10 @@ function TooltipTrigger(props: TooltipPrimitive.Trigger.Props) { props.onMouseEnter?.(event); tracker.hover(event.currentTarget, actionsRef); }} + onFocus={(event) => { + props.onFocus?.(event); + tracker.hover(event.currentTarget, actionsRef); + }} /> ); } From 7bf5b9b54ea40b6b76441a5cfc15c3f2d254df10 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Wed, 11 Nov 2026 14:42:46 +0000 Subject: [PATCH 2/5] test(web): cover the keyboard path for PR tooltip scroll dismissal --- .../PullRequestSummaryTab.browser.test.tsx | 70 ++++++++----------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx index a7aa58a9d77b..812021b012ac 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx @@ -102,45 +102,37 @@ const detail: PullRequestDetailView = { }, }; -it.each(["pointer", "keyboard"])( - "dismisses a media tooltip after %s preview and PR scroll", - async (input) => { - setup(); - const url = "https://github.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"; - await using screen = await render({ - ...detail, - body: `![Screenshot](${url})\n\n${"Paragraph\n\n".repeat(40)}`, - }); - const scroller = screen.container.querySelector( - "[data-pull-request-summary-scroll]", - )!; - scroller.style.height = "600px"; - const link = screen.getByRole("button", { name: "Preview Screenshot", exact: true }); - await expect.element(screen.getByAltText("Screenshot")).toBeVisible(); - if (input === "pointer") { - await userEvent.click(link); - } else { - await act(() => (link.element() as HTMLElement).focus()); - await userEvent.keyboard("{Enter}"); - } - await expect.element(page.getByRole("dialog")).toBeVisible(); - // Leave the opener while the dialog is up: scrolling must not depend on mouseleave. - await userEvent.hover(page.getByRole("button", { name: "Close image preview" })); - await userEvent.keyboard("{Escape}"); - await expect.element(page.getByRole("dialog")).not.toBeInTheDocument(); - expect(document.activeElement).toBe(link.element()); - await vi.waitFor(() => - expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toBe(url), - ); - await act(() => { - scroller.scrollTop = 100; - }); - await vi.waitFor(() => - expect(document.querySelector('[data-slot="tooltip-popup"]')).toBeNull(), - ); - expect(document.activeElement).toBe(link.element()); - }, -); +// Mouse-opened previews restore focus without focus-visible, so only keyboard reopens the tooltip. +it("dismisses a media tooltip after keyboard preview and PR scroll", async () => { + setup(); + const url = "https://github.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"; + await using screen = await render({ + ...detail, + body: `![Screenshot](${url})\n\n${"Paragraph\n\n".repeat(40)}`, + }); + const scroller = screen.container.querySelector( + "[data-pull-request-summary-scroll]", + )!; + scroller.style.height = "600px"; + const link = screen.getByRole("button", { name: "Preview Screenshot", exact: true }); + await expect.element(screen.getByAltText("Screenshot")).toBeVisible(); + await act(() => (link.element() as HTMLElement).focus()); + await userEvent.keyboard("{Enter}"); + await expect.element(page.getByRole("dialog")).toBeVisible(); + // Leave the opener while the dialog is up: scrolling must not depend on mouseleave. + await userEvent.hover(page.getByRole("button", { name: "Close image preview" })); + await userEvent.keyboard("{Escape}"); + await expect.element(page.getByRole("dialog")).not.toBeInTheDocument(); + expect(document.activeElement).toBe(link.element()); + await vi.waitFor(() => + expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toBe(url), + ); + await act(() => { + scroller.scrollTop = 100; + }); + await vi.waitFor(() => expect(document.querySelector('[data-slot="tooltip-popup"]')).toBeNull()); + expect(document.activeElement).toBe(link.element()); +}); // The comment filter persists to localStorage, so tests that touch it start and end empty. From 75fcf8b2a82fa50a1620c163d807cbcde9984edb Mon Sep 17 00:00:00 2001 From: Adamulek123 Date: Wed, 11 Nov 2026 18:41:04 +0100 Subject: [PATCH 3/5] fix(web): preserve focused tooltips through automatic focus scrolling --- .../components/ui/tooltip.browser.test.tsx | 60 ++++++++++++++ apps/web/src/components/ui/tooltip.tsx | 82 +++++++++++++++---- 2 files changed, 125 insertions(+), 17 deletions(-) diff --git a/apps/web/src/components/ui/tooltip.browser.test.tsx b/apps/web/src/components/ui/tooltip.browser.test.tsx index 24d76784e8a5..a6232356cce4 100644 --- a/apps/web/src/components/ui/tooltip.browser.test.tsx +++ b/apps/web/src/components/ui/tooltip.browser.test.tsx @@ -41,3 +41,63 @@ it.each([ if (c.keptOpen) await expect.element(page.getByText("Description")).toBeVisible(); else await expect.element(page.getByText("Description")).not.toBeInTheDocument(); }); + +it("keeps a focused tooltip tracked when the pointer enters a disabled tooltip", async () => { + await using screen = await render( + + + Focused action + Focused description + + + }>Unavailable action + Disabled description + +
+ , + ); + await userEvent.keyboard("{Tab}"); + await expect.element(page.getByText("Focused description")).toBeVisible(); + await userEvent.hover(screen.getByText("Unavailable action")); + await expect.element(page.getByText("Focused description")).toBeVisible(); + screen.getByTestId("scroller").element().scrollTop = 20; + await expect.element(page.getByText("Focused description")).not.toBeInTheDocument(); + await expect.element(screen.getByRole("button", { name: "Focused action" })).toHaveFocus(); +}); + +it("keeps a tooltip through focus scrolling and dismisses it on the next scroll", async () => { + const onScroll = vi.fn(); + await using screen = await render( + <> + + +
+ + Offscreen action + Offscreen description + +
+ + , + ); + const scroller = screen.getByTestId("scroller").element(); + await userEvent.click(screen.getByRole("button", { name: "Start navigation" })); + await userEvent.keyboard("{Tab}"); + await vi.waitFor(() => { + expect(scroller.scrollTop).toBeGreaterThan(0); + expect(onScroll).toHaveBeenCalled(); + }); + await expect.element(screen.getByRole("button", { name: "Offscreen action" })).toHaveFocus(); + await expect.element(page.getByText("Offscreen description")).toBeVisible(); + scroller.scrollTop += 20; + await expect.element(page.getByText("Offscreen description")).not.toBeInTheDocument(); +}); diff --git a/apps/web/src/components/ui/tooltip.tsx b/apps/web/src/components/ui/tooltip.tsx index b6dcb1625ee2..9b3be86f7820 100644 --- a/apps/web/src/components/ui/tooltip.tsx +++ b/apps/web/src/components/ui/tooltip.tsx @@ -19,31 +19,60 @@ const TooltipProvider = TooltipPrimitive.Provider; type TooltipActionsRef = RefObject; +type TrackedTooltip = { trigger: HTMLElement; actionsRef: TooltipActionsRef }; + // The compiler freezes context values; update tracked tooltips through calls instead of shared ref writes. function createTooltipHoverTracker() { - let hovered: { trigger: HTMLElement; actionsRef: TooltipActionsRef } | null = null; + let hovered: TrackedTooltip | null = null; + let focused: TrackedTooltip | null = null; + let focusScrollFrame: number | null = null; + const settleFocus = () => { + if (focusScrollFrame !== null) cancelAnimationFrame(focusScrollFrame); + focusScrollFrame = null; + }; + const blur = (actionsRef: TooltipActionsRef) => { + if (focused?.actionsRef !== actionsRef) return; + settleFocus(); + focused = null; + }; + const release = (actionsRef: TooltipActionsRef) => { + if (hovered?.actionsRef === actionsRef) hovered = null; + blur(actionsRef); + }; return { hover(trigger: HTMLElement, actionsRef: TooltipActionsRef) { hovered = { trigger, actionsRef }; }, - release(actionsRef: TooltipActionsRef) { - if (hovered?.actionsRef === actionsRef) hovered = null; + focus(trigger: HTMLElement, actionsRef: TooltipActionsRef) { + settleFocus(); + focused = { trigger, actionsRef }; + // Browser focus scrolling is dispatched before the next animation frame. + focusScrollFrame = requestAnimationFrame(() => { + focusScrollFrame = null; + }); }, + blur, + release, + settleFocus, dismiss(dismissFocused: boolean) { - const tooltip = hovered; - if (!tooltip) return; - const focused = tooltip.trigger.ownerDocument.activeElement; - if ( - !dismissFocused && - focused && - tooltip.trigger.contains(focused) && - focused.matches(":focus-visible") - ) { - return; + const focusScrollPending = focusScrollFrame !== null; + settleFocus(); + const tooltips = + hovered?.actionsRef === focused?.actionsRef ? [focused ?? hovered] : [hovered, focused]; + for (const tooltip of tooltips) { + if (!tooltip) continue; + const active = tooltip.trigger.ownerDocument.activeElement; + if ( + active && + tooltip.trigger.contains(active) && + active.matches(":focus-visible") && + (!dismissFocused || focusScrollPending) + ) + continue; + release(tooltip.actionsRef); + // Base UI also cancels delayed hover opens through this action. + tooltip.actionsRef.current?.close(); } - hovered = null; - // Base UI also cancels delayed hover opens through this action. - tooltip.actionsRef.current?.close(); }, }; } @@ -54,6 +83,9 @@ const TooltipScrollContext = createContext(null); function TooltipScrollDismissArea({ onScrollCapture, + onWheelCapture, + onKeyDownCapture, + onPointerDownCapture, dismissFocused = false, ...props }: ComponentProps<"div"> & { @@ -65,6 +97,18 @@ function TooltipScrollDismissArea({
{ + tracker.settleFocus(); + onWheelCapture?.(event); + }} + onKeyDownCapture={(event) => { + tracker.settleFocus(); + onKeyDownCapture?.(event); + }} + onPointerDownCapture={(event) => { + tracker.settleFocus(); + onPointerDownCapture?.(event); + }} onScrollCapture={(event) => { onScrollCapture?.(event); tracker.dismiss(dismissFocused); @@ -112,7 +156,11 @@ function TooltipTrigger(props: TooltipPrimitive.Trigger.Props) { }} onFocus={(event) => { props.onFocus?.(event); - tracker.hover(event.currentTarget, actionsRef); + tracker.focus(event.currentTarget, actionsRef); + }} + onBlur={(event) => { + props.onBlur?.(event); + tracker.blur(actionsRef); }} /> ); From ee6571db6e115c9f1bdc15c2e11919463c42cf7d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 05:43:05 +0000 Subject: [PATCH 4/5] test(web): cover PR tooltip scroll dismissal at the tooltip layer Co-Authored-By: Claude Opus 5.5 --- .../PullRequestSummaryTab.browser.test.tsx | 44 +------- .../components/ui/tooltip.browser.test.tsx | 100 +++++++----------- 2 files changed, 41 insertions(+), 103 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx index 0870394e475c..8ecb158a8f2d 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.browser.test.tsx @@ -5,8 +5,7 @@ import { } from "@t3tools/contracts"; import { EnvironmentId, ProjectId, type PullRequestDetailView } from "@t3tools/contracts"; import { expect, it, vi } from "vite-plus/test"; -import { page, userEvent } from "vite-plus/test/browser"; -import "../../index.css"; +import { userEvent } from "vite-plus/test/browser"; const state = vi.hoisted(() => ({ update: vi.fn(), @@ -14,15 +13,6 @@ const state = vi.hoisted(() => ({ timestampFormat: "locale" as "locale" | "12-hour" | "24-hour", })); -vi.mock(import("~/assets/assetUrls"), async (original) => ({ - ...(await original()), - useAssetUrlState: () => ({ - _tag: "Success", - expiresAt: Number.MAX_SAFE_INTEGER, - url: `data:image/svg+xml,${encodeURIComponent('')}`, - }), -})); - vi.mock(import("~/state/use-atom-command"), async (original) => ({ ...(await original()), useAtomCommand: (() => state.update) as never, @@ -118,38 +108,6 @@ const detail: PullRequestDetailView = { }, }; -// Mouse-opened previews restore focus without focus-visible, so only keyboard reopens the tooltip. -it("dismisses a media tooltip after keyboard preview and PR scroll", async () => { - setup(); - const url = "https://github.com/user-attachments/assets/7195f963-51a9-4331-be74-3e06be760422"; - await using screen = await render({ - ...detail, - body: `![Screenshot](${url})\n\n${"Paragraph\n\n".repeat(40)}`, - }); - const scroller = screen.container.querySelector( - "[data-pull-request-summary-scroll]", - )!; - scroller.style.height = "600px"; - const link = screen.getByRole("button", { name: "Preview Screenshot", exact: true }); - await expect.element(screen.getByAltText("Screenshot")).toBeVisible(); - await act(() => (link.element() as HTMLElement).focus()); - await userEvent.keyboard("{Enter}"); - await expect.element(page.getByRole("dialog")).toBeVisible(); - // Leave the opener while the dialog is up: scrolling must not depend on mouseleave. - await userEvent.hover(page.getByRole("button", { name: "Close image preview" })); - await userEvent.keyboard("{Escape}"); - await expect.element(page.getByRole("dialog")).not.toBeInTheDocument(); - expect(document.activeElement).toBe(link.element()); - await vi.waitFor(() => - expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toBe(url), - ); - await act(() => { - scroller.scrollTop = 100; - }); - await vi.waitFor(() => expect(document.querySelector('[data-slot="tooltip-popup"]')).toBeNull()); - expect(document.activeElement).toBe(link.element()); -}); - // The comment filter persists to localStorage, so tests that touch it start and end empty. const tab = (value = detail) => ( diff --git a/apps/web/src/components/ui/tooltip.browser.test.tsx b/apps/web/src/components/ui/tooltip.browser.test.tsx index a6232356cce4..97dd29645bde 100644 --- a/apps/web/src/components/ui/tooltip.browser.test.tsx +++ b/apps/web/src/components/ui/tooltip.browser.test.tsx @@ -6,68 +6,48 @@ import { render } from "../../../test/render"; import { Tooltip, TooltipPopup, TooltipScrollDismissArea, TooltipTrigger } from "./tooltip"; it.each([ - { focus: "mouse", keptOpen: false }, - { focus: "keyboard", keptOpen: true }, -])("scrolling with a $focus-focused hovered trigger keeps it open: $keptOpen", async (c) => { - const onScroll = vi.fn(); - await using screen = await render( - - - Timeline action - Description - -
- , - ); - const trigger = screen.getByRole("button", { name: "Timeline action" }); - if (c.focus === "mouse") { - // A press closes the tooltip; hovering again reopens it with mouse focus kept. - await userEvent.click(trigger); - await userEvent.unhover(trigger); - } else { - await userEvent.keyboard("{Tab}"); - } - await userEvent.hover(trigger); - await expect.element(trigger).toHaveFocus(); - await expect.element(page.getByText("Description")).toBeVisible(); - - screen.getByTestId("timeline").element().scrollTop = 20; - await vi.waitFor(() => expect(onScroll).toHaveBeenCalledOnce()); + { focus: "mouse", dismissFocused: false, keptOpen: false }, + { focus: "keyboard", dismissFocused: false, keptOpen: true }, + // PR panes: focus restored after an image preview reopens the tooltip without a hover. + { focus: "keyboard", dismissFocused: true, keptOpen: false }, +])( + "scrolling a $focus-focused trigger (dismissFocused: $dismissFocused) keeps it open: $keptOpen", + async (c) => { + const onScroll = vi.fn(); + await using screen = await render( + + + Timeline action + Description + +
+ , + ); + const trigger = screen.getByRole("button", { name: "Timeline action" }); + if (c.focus === "mouse") { + // A press closes the tooltip; hovering again reopens it with mouse focus kept. + await userEvent.click(trigger); + await userEvent.unhover(trigger); + } else { + await userEvent.keyboard("{Tab}"); + } + if (!c.dismissFocused) await userEvent.hover(trigger); + await expect.element(trigger).toHaveFocus(); + await expect.element(page.getByText("Description")).toBeVisible(); - if (c.keptOpen) await expect.element(page.getByText("Description")).toBeVisible(); - else await expect.element(page.getByText("Description")).not.toBeInTheDocument(); -}); + screen.getByTestId("timeline").element().scrollTop = 20; + await vi.waitFor(() => expect(onScroll).toHaveBeenCalledOnce()); -it("keeps a focused tooltip tracked when the pointer enters a disabled tooltip", async () => { - await using screen = await render( - - - Focused action - Focused description - - - }>Unavailable action - Disabled description - -
- , - ); - await userEvent.keyboard("{Tab}"); - await expect.element(page.getByText("Focused description")).toBeVisible(); - await userEvent.hover(screen.getByText("Unavailable action")); - await expect.element(page.getByText("Focused description")).toBeVisible(); - screen.getByTestId("scroller").element().scrollTop = 20; - await expect.element(page.getByText("Focused description")).not.toBeInTheDocument(); - await expect.element(screen.getByRole("button", { name: "Focused action" })).toHaveFocus(); -}); + if (c.keptOpen) await expect.element(page.getByText("Description")).toBeVisible(); + else await expect.element(page.getByText("Description")).not.toBeInTheDocument(); + await expect.element(trigger).toHaveFocus(); + }, +); it("keeps a tooltip through focus scrolling and dismisses it on the next scroll", async () => { const onScroll = vi.fn(); From ec28989e8d62e890f971dcc73079c543bd71092a Mon Sep 17 00:00:00 2001 From: Adamulek123 Date: Sun, 15 Nov 2026 17:52:11 +0100 Subject: [PATCH 5/5] test(web): cover hovered focused tooltip dismissal --- apps/web/src/components/ui/tooltip.browser.test.tsx | 12 ++++++------ apps/web/src/components/ui/tooltip.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/ui/tooltip.browser.test.tsx b/apps/web/src/components/ui/tooltip.browser.test.tsx index 97dd29645bde..f7527e295185 100644 --- a/apps/web/src/components/ui/tooltip.browser.test.tsx +++ b/apps/web/src/components/ui/tooltip.browser.test.tsx @@ -6,12 +6,12 @@ import { render } from "../../../test/render"; import { Tooltip, TooltipPopup, TooltipScrollDismissArea, TooltipTrigger } from "./tooltip"; it.each([ - { focus: "mouse", dismissFocused: false, keptOpen: false }, - { focus: "keyboard", dismissFocused: false, keptOpen: true }, - // PR panes: focus restored after an image preview reopens the tooltip without a hover. - { focus: "keyboard", dismissFocused: true, keptOpen: false }, + { focus: "mouse", hover: true, dismissFocused: false, keptOpen: false }, + { focus: "keyboard", hover: true, dismissFocused: false, keptOpen: true }, + { focus: "keyboard", hover: false, dismissFocused: true, keptOpen: false }, + { focus: "keyboard", hover: true, dismissFocused: true, keptOpen: false }, ])( - "scrolling a $focus-focused trigger (dismissFocused: $dismissFocused) keeps it open: $keptOpen", + "scrolling a $focus-focused trigger (hover: $hover, dismissFocused: $dismissFocused) keeps it open: $keptOpen", async (c) => { const onScroll = vi.fn(); await using screen = await render( @@ -36,7 +36,7 @@ it.each([ } else { await userEvent.keyboard("{Tab}"); } - if (!c.dismissFocused) await userEvent.hover(trigger); + if (c.hover) await userEvent.hover(trigger); await expect.element(trigger).toHaveFocus(); await expect.element(page.getByText("Description")).toBeVisible(); diff --git a/apps/web/src/components/ui/tooltip.tsx b/apps/web/src/components/ui/tooltip.tsx index fa0ba73bff22..8bad36d2e7da 100644 --- a/apps/web/src/components/ui/tooltip.tsx +++ b/apps/web/src/components/ui/tooltip.tsx @@ -89,7 +89,7 @@ function TooltipScrollDismissArea({ dismissFocused = false, ...props }: ComponentProps<"div"> & { - /** PR scrolling also dismisses tooltips reopened by media preview focus restoration. */ + /** Also dismiss keyboard-focused tooltips when the user scrolls. */ dismissFocused?: boolean; }) { const [tracker] = useState(createTooltipHoverTracker);