From 1c7b39e15dad6d2cddc83171fe948d592deb0f68 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Mon, 23 Nov 2026 23:28:32 +0000 Subject: [PATCH 1/2] fix(web): Esc in theme search clears it without closing the dialog --- .../ThemeImportDialog.browser.test.tsx | 44 +++++++++++++++++++ .../settings/ThemeSearchSection.tsx | 9 +++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx index fd5b90f9c6c19..0df570ad65d1c 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx @@ -63,6 +63,50 @@ describe("ThemeImportDialog", () => { expect.objectContaining({ sortBy: "downloadCount" }), ); }); + + it("clears the search on Escape before closing the dialog", async () => { + searchOpenVsxThemes.mockReset(); + searchOpenVsxThemes.mockResolvedValue([]); + const onOpenChange = vi.fn(); + await using _screen = await render( + true} + onImportedMany={() => {}} + />, + ); + const search = page.getByRole("searchbox", { name: "Search Open VSX themes" }); + await expect.element(search).toHaveAttribute("type", "text"); + await userEvent.fill(search, "nord"); + const pressEscape = (init: KeyboardEventInit) => + search + .element() + .dispatchEvent( + new KeyboardEvent("keydown", { bubbles: true, cancelable: true, key: "Escape", ...init }), + ); + + for (const composition of [ + { isComposing: true, keyCode: 27 }, + { isComposing: false, keyCode: 229 }, + ]) { + // Safari ends the composition just before the Escape keydown. + await act(() => { + search.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); + pressEscape(composition); + }); + await expect.element(search).toHaveValue("nord"); + } + expect(onOpenChange).not.toHaveBeenCalled(); + + await userEvent.keyboard("{Escape}"); + await expect.element(search).toHaveValue(""); + pressEscape({ repeat: true }); + expect(onOpenChange).not.toHaveBeenCalled(); + + await userEvent.keyboard("{Escape}"); + expect(onOpenChange).toHaveBeenCalledWith(false); + }); }); const theme = (name: string, accent = "#3b82f6", css?: string) => ({ diff --git a/apps/web/src/components/settings/ThemeSearchSection.tsx b/apps/web/src/components/settings/ThemeSearchSection.tsx index 47e73e4939237..fa54b9a88b59d 100644 --- a/apps/web/src/components/settings/ThemeSearchSection.tsx +++ b/apps/web/src/components/settings/ThemeSearchSection.tsx @@ -321,18 +321,25 @@ export function ThemeSearchSection({ {isSearching ? : } + {/* Native search inputs clear on Escape even during IME composition. */} changeQuery(event.currentTarget.value)} onKeyDown={(event) => { if (event.nativeEvent.isComposing || event.keyCode === 229) return; + if (event.key === "Escape" && (query || event.repeat)) { + event.preventDefault(); + event.stopPropagation(); + changeQuery(""); + } if (event.key === "Enter" && !isSearching && installingId === null) themeSearch.searchNow(); }} placeholder={gt("Search themes...")} + role="searchbox" size="lg" - type="search" + type="text" value={query} /> From a3b4f56f328fdf7b233ea7401788b84ddf04dbc7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 24 Nov 2026 00:10:43 +0000 Subject: [PATCH 2/2] test(web): keep only the theme search Escape cases that guard the fix Co-Authored-By: Claude Opus 5.5 --- .../ThemeImportDialog.browser.test.tsx | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx index 0df570ad65d1c..805899095444a 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx @@ -79,29 +79,16 @@ describe("ThemeImportDialog", () => { const search = page.getByRole("searchbox", { name: "Search Open VSX themes" }); await expect.element(search).toHaveAttribute("type", "text"); await userEvent.fill(search, "nord"); - const pressEscape = (init: KeyboardEventInit) => - search - .element() - .dispatchEvent( - new KeyboardEvent("keydown", { bubbles: true, cancelable: true, key: "Escape", ...init }), - ); - - for (const composition of [ - { isComposing: true, keyCode: 27 }, - { isComposing: false, keyCode: 229 }, - ]) { - // Safari ends the composition just before the Escape keydown. - await act(() => { - search.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); - pressEscape(composition); - }); - await expect.element(search).toHaveValue("nord"); - } - expect(onOpenChange).not.toHaveBeenCalled(); - await userEvent.keyboard("{Escape}"); await expect.element(search).toHaveValue(""); - pressEscape({ repeat: true }); + search.element().dispatchEvent( + new KeyboardEvent("keydown", { + bubbles: true, + cancelable: true, + key: "Escape", + repeat: true, + }), + ); expect(onOpenChange).not.toHaveBeenCalled(); await userEvent.keyboard("{Escape}");