From 6a8be8a5955bbc151a3fe5de8aabbf9449ad9f9c Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Mon, 23 Nov 2026 22:55:01 +0000 Subject: [PATCH] fix(web): Esc in Find in PDF clears it without closing the sheet --- .../files/PdfViewer.browser.test.tsx | 50 ++++++++++++++++++- apps/web/src/components/files/PdfViewer.tsx | 11 +++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/files/PdfViewer.browser.test.tsx b/apps/web/src/components/files/PdfViewer.browser.test.tsx index 81bf3bcf91364..1563088cf32f4 100644 --- a/apps/web/src/components/files/PdfViewer.browser.test.tsx +++ b/apps/web/src/components/files/PdfViewer.browser.test.tsx @@ -1,5 +1,8 @@ import { expect, it, vi } from "vite-plus/test"; -import { render } from "../../../test/render"; +import { userEvent } from "vite-plus/test/browser"; + +import { RightPanelSheet } from "~/components/RightPanelSheet"; +import { act, render } from "../../../test/render"; import "~/index.css"; // Vite serves the worker module through its transform with an inline source map (6.8 MB for @@ -333,3 +336,48 @@ it("follows a link to another page and exposes a web link", async () => { URL.revokeObjectURL(url); } }); + +it("Escape in Find in PDF clears it without closing the panel sheet", async () => { + const url = URL.createObjectURL(testPdf()); + const onCloseSheet = vi.fn(); + try { + await using screen = await render( + + + , + ); + const find = screen.getByRole("searchbox", { name: "Find in PDF" }); + await find.fill("quarterly"); + for (const composition of [ + { key: "Escape", isComposing: true, keyCode: 27 }, + { key: "Escape", isComposing: false, keyCode: 229 }, + ]) { + // Safari ends the composition just before the Escape keydown. + await act(() => { + find.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); + find + .element() + .dispatchEvent(new KeyboardEvent("keydown", { ...composition, bubbles: true })); + }); + await expect.element(find).toHaveValue("quarterly"); + } + expect(find.element().getAttribute("type")).toBe("text"); + + await userEvent.keyboard("{Escape}"); + await expect.element(find).toHaveValue(""); + // Holding Escape repeats the keydown, which must not also close the sheet. + await act(() => { + find + .element() + .dispatchEvent( + new KeyboardEvent("keydown", { key: "Escape", repeat: true, bubbles: true }), + ); + }); + expect(onCloseSheet).not.toHaveBeenCalled(); + + await userEvent.keyboard("{Escape}"); + await vi.waitFor(() => expect(onCloseSheet).toHaveBeenCalledOnce()); + } finally { + URL.revokeObjectURL(url); + } +}); diff --git a/apps/web/src/components/files/PdfViewer.tsx b/apps/web/src/components/files/PdfViewer.tsx index 9842a621c0302..3f0368d67cfb4 100644 --- a/apps/web/src/components/files/PdfViewer.tsx +++ b/apps/web/src/components/files/PdfViewer.tsx @@ -522,10 +522,12 @@ export default function PdfViewer(props: {
+ {/* Native search inputs clear on Escape even during IME composition. */} { + if (event.key !== "Escape" || event.nativeEvent.isComposing || event.keyCode === 229) + return; + if (!query && !event.repeat) return; + event.stopPropagation(); + setQuery(""); + }} />
{query ? (