From a7795df4bdf13793d2dcf2e2b36ed8fc3a8b29f7 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 24 Nov 2026 05:04:28 +0000 Subject: [PATCH 1/2] fix(web): Esc in pull request search clears it instead of leaving the page --- .../PullRequestListFilters.browser.test.tsx | 86 +++++++++++++++++++ .../pullRequest/PullRequestListFilters.tsx | 17 +++- .../PullRequestsColumn.browser.test.tsx | 83 +++++++++++++++++- .../pullRequest/PullRequestsColumn.tsx | 8 +- 4 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx diff --git a/apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx new file mode 100644 index 0000000000000..9d96ddfd231f4 --- /dev/null +++ b/apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx @@ -0,0 +1,86 @@ +import { useState } from "react"; +import { page, userEvent } from "vite-plus/test/browser"; +import { expect, it, vi } from "vite-plus/test"; + +import { act, render } from "../../../test/render"; +import { registerCommands } from "../../shortcuts/dispatcher"; +import { PullRequestSearchInput } from "./PullRequestListFilters"; + +import "~/index.css"; + +function SearchHarness({ onSubmit }: { onSubmit: (value: string) => void }) { + const [value, setValue] = useState(""); + return ( + + ); +} + +it("Escape in the search clears it before the page's Escape leaves", async () => { + const onSubmit = vi.fn(); + await using _screen = await render(); + // Mirrors the /pull-requests observer, which leaves on an unclaimed Escape. + const leave = vi.fn(); + using stack = new DisposableStack(); + stack.defer( + registerCommands( + {}, + { + observe: (event, consumed) => { + if (!consumed && !event.repeat && !event.isComposing && event.key === "Escape") leave(); + }, + }, + ), + ); + const search = page.getByRole("searchbox", { name: "Search pull requests" }); + // Safari ends the composition just before the confirming keydown. + const pressDuringComposition = (key: string) => + act(() => { + for (const composition of [{ isComposing: true }, { keyCode: 229 }]) { + search.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); + search + .element() + .dispatchEvent(new KeyboardEvent("keydown", { key, ...composition, bubbles: true })); + } + }); + await expect.element(search).toHaveAttribute("type", "text"); + await userEvent.fill(search, "label:bug"); + + await pressDuringComposition("Enter"); + await pressDuringComposition("Escape"); + expect(onSubmit).not.toHaveBeenCalled(); + await expect.element(search).toHaveValue("label:bug"); + await userEvent.keyboard("{Enter}"); + expect(onSubmit.mock.calls).toEqual([["label:bug"]]); + + // An Escape another scope already claimed, like the close sweep, keeps the query. + window.addEventListener("keydown", (event) => event.preventDefault(), { + capture: true, + once: true, + }); + await userEvent.keyboard("{Escape}"); + await expect.element(search).toHaveValue("label:bug"); + // A modified Escape is left to the user's keybindings. + await userEvent.keyboard("{Shift>}{Escape}{/Shift}"); + await expect.element(search).toHaveValue("label:bug"); + expect(leave).toHaveBeenCalledOnce(); + leave.mockClear(); + + await userEvent.keyboard("{Escape}"); + await expect.element(search).toHaveValue(""); + await expect.element(search).toHaveFocus(); + await userEvent.tab(); + await expect.element(search).toHaveValue(""); + + await userEvent.click(search); + await pressDuringComposition("Escape"); + expect(leave).not.toHaveBeenCalled(); + + await userEvent.keyboard("{Escape}"); + expect(leave).toHaveBeenCalledOnce(); +}); diff --git a/apps/web/src/components/pullRequest/PullRequestListFilters.tsx b/apps/web/src/components/pullRequest/PullRequestListFilters.tsx index 479bd481e03aa..58dc689343bd1 100644 --- a/apps/web/src/components/pullRequest/PullRequestListFilters.tsx +++ b/apps/web/src/components/pullRequest/PullRequestListFilters.tsx @@ -116,8 +116,10 @@ export function PullRequestSearchInput({ {busy ? : } + {/* Native search inputs clear on Escape even during IME composition. */} setDraft(value)} onBlur={() => setDraft(null)} @@ -129,9 +131,16 @@ export function PullRequestSearchInput({ } }} onKeyDown={(event) => { - if (event.key === "Enter" && !event.nativeEvent.isComposing) { - onSubmit(event.currentTarget.value); - } + const composing = event.nativeEvent.isComposing || event.keyCode === 229; + if (event.key === "Enter" && !composing) onSubmit(event.currentTarget.value); + if (event.key !== "Escape" || event.defaultPrevented) return; + if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return; + if (!composing && !event.currentTarget.value) return; + // The pull requests page leaves on an Escape that reaches it. + event.stopPropagation(); + if (composing) return; + setDraft(""); + onChange(""); }} placeholder={placeholder} aria-label={label} diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx index 1e4de32289e69..34388acf71d55 100644 --- a/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx @@ -1,9 +1,13 @@ -import { createRef, type RefObject } from "react"; +import { createRef, type RefObject, useState } from "react"; +import { page, userEvent } from "vite-plus/test/browser"; import { describe, expect, it } from "vite-plus/test"; import { render } from "../../../test/render"; +import { PullRequestSearchInput } from "./PullRequestListFilters"; import { PullRequestsColumn } from "./PullRequestsColumn"; +import "~/index.css"; + function createColumn(maximizedAway: boolean, scrollRef: RefObject) { return ( { .toHaveFocus(); }); }); + +function CondensedSearchColumn({ scrollRef }: { scrollRef: RefObject }) { + const [query, setQuery] = useState("label:bug"); + return ( +
+ {}} + searchValue={query} + involvement="all" + state="open" + host={undefined} + hostMenuOptions={[]} + onInvolvement={() => {}} + onState={() => {}} + onHost={() => {}} + searchInput={ + {}} + /> + } + sortMenu={null} + filtersMenu={null} + savedViewsMenu={null} + rightPanelControl={null} + titlebarControls={null} + rightPanelOpen={false} + maximizedAway={false} + listBody={
} + scrollRef={scrollRef} + /> + +
+ ); +} + +async function renderCondensed() { + await using stack = new AsyncDisposableStack(); + const scrollRef = createRef(); + const screen = stack.use(await render()); + scrollRef.current?.scrollTo({ top: 1000 }); + const searches = page.getByRole("searchbox", { name: "Search pull requests" }); + // The topbar copy comes first and mounts once the header condenses. + await expect.element(searches.nth(1)).toBeInTheDocument(); + const environment = stack.move(); + return Object.assign(screen, { + [Symbol.asyncDispose]: () => environment.disposeAsync(), + topbarSearch: searches.nth(0), + }); +} + +describe("PullRequestsColumn condensed search", () => { + it("keeps the topbar search focused when Escape clears the query that kept it open", async () => { + await using screen = await renderCondensed(); + + await userEvent.click(screen.topbarSearch); + await userEvent.keyboard("{Escape}"); + await expect.element(screen.topbarSearch).toHaveValue(""); + await expect.element(screen.topbarSearch).toHaveFocus(); + }); + + it("collapses the topbar search when its query clears after focus left it", async () => { + await using screen = await renderCondensed(); + + await userEvent.click(screen.topbarSearch); + await userEvent.click(page.getByRole("button", { name: "Clear query" })); + await expect + .element(page.getByRole("button", { name: "Search pull requests" })) + .toBeInTheDocument(); + }); +}); diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.tsx index d4ca6d0d3b7e2..6cd38913860f2 100644 --- a/apps/web/src/components/pullRequest/PullRequestsColumn.tsx +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.tsx @@ -48,10 +48,14 @@ function ExpandableSearch({
onFocusWithin?.(true)} + onFocus={() => { + onFocusWithin?.(true); + // Open while focused, so Escape clearing the query does not unmount the field. + onOpenChange(true); + }} onBlur={() => { onFocusWithin?.(false); - if (searchValue.length === 0) onOpenChange(false); + onOpenChange(false); }} > {searchInput} From 3056546f4b5020d2fbeb0789459b3cad0625f8c2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 24 Nov 2026 05:35:17 +0000 Subject: [PATCH 2/2] test(web): fold pull request search Escape cases into one column test Co-Authored-By: Claude Opus 5.5 --- .../PullRequestListFilters.browser.test.tsx | 86 ------------------ .../PullRequestsColumn.browser.test.tsx | 91 ++++++++++++------- 2 files changed, 59 insertions(+), 118 deletions(-) delete mode 100644 apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx diff --git a/apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx deleted file mode 100644 index 9d96ddfd231f4..0000000000000 --- a/apps/web/src/components/pullRequest/PullRequestListFilters.browser.test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { useState } from "react"; -import { page, userEvent } from "vite-plus/test/browser"; -import { expect, it, vi } from "vite-plus/test"; - -import { act, render } from "../../../test/render"; -import { registerCommands } from "../../shortcuts/dispatcher"; -import { PullRequestSearchInput } from "./PullRequestListFilters"; - -import "~/index.css"; - -function SearchHarness({ onSubmit }: { onSubmit: (value: string) => void }) { - const [value, setValue] = useState(""); - return ( - - ); -} - -it("Escape in the search clears it before the page's Escape leaves", async () => { - const onSubmit = vi.fn(); - await using _screen = await render(); - // Mirrors the /pull-requests observer, which leaves on an unclaimed Escape. - const leave = vi.fn(); - using stack = new DisposableStack(); - stack.defer( - registerCommands( - {}, - { - observe: (event, consumed) => { - if (!consumed && !event.repeat && !event.isComposing && event.key === "Escape") leave(); - }, - }, - ), - ); - const search = page.getByRole("searchbox", { name: "Search pull requests" }); - // Safari ends the composition just before the confirming keydown. - const pressDuringComposition = (key: string) => - act(() => { - for (const composition of [{ isComposing: true }, { keyCode: 229 }]) { - search.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); - search - .element() - .dispatchEvent(new KeyboardEvent("keydown", { key, ...composition, bubbles: true })); - } - }); - await expect.element(search).toHaveAttribute("type", "text"); - await userEvent.fill(search, "label:bug"); - - await pressDuringComposition("Enter"); - await pressDuringComposition("Escape"); - expect(onSubmit).not.toHaveBeenCalled(); - await expect.element(search).toHaveValue("label:bug"); - await userEvent.keyboard("{Enter}"); - expect(onSubmit.mock.calls).toEqual([["label:bug"]]); - - // An Escape another scope already claimed, like the close sweep, keeps the query. - window.addEventListener("keydown", (event) => event.preventDefault(), { - capture: true, - once: true, - }); - await userEvent.keyboard("{Escape}"); - await expect.element(search).toHaveValue("label:bug"); - // A modified Escape is left to the user's keybindings. - await userEvent.keyboard("{Shift>}{Escape}{/Shift}"); - await expect.element(search).toHaveValue("label:bug"); - expect(leave).toHaveBeenCalledOnce(); - leave.mockClear(); - - await userEvent.keyboard("{Escape}"); - await expect.element(search).toHaveValue(""); - await expect.element(search).toHaveFocus(); - await userEvent.tab(); - await expect.element(search).toHaveValue(""); - - await userEvent.click(search); - await pressDuringComposition("Escape"); - expect(leave).not.toHaveBeenCalled(); - - await userEvent.keyboard("{Escape}"); - expect(leave).toHaveBeenCalledOnce(); -}); diff --git a/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx index 34388acf71d55..fbf4c55d763c4 100644 --- a/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestsColumn.browser.test.tsx @@ -1,8 +1,9 @@ import { createRef, type RefObject, useState } from "react"; import { page, userEvent } from "vite-plus/test/browser"; -import { describe, expect, it } from "vite-plus/test"; +import { describe, expect, it, vi } from "vite-plus/test"; -import { render } from "../../../test/render"; +import { act, render } from "../../../test/render"; +import { registerCommands } from "../../shortcuts/dispatcher"; import { PullRequestSearchInput } from "./PullRequestListFilters"; import { PullRequestsColumn } from "./PullRequestsColumn"; @@ -62,7 +63,13 @@ describe("PullRequestsColumn find shortcut", () => { }); }); -function CondensedSearchColumn({ scrollRef }: { scrollRef: RefObject }) { +function CondensedSearchColumn({ + scrollRef, + onSubmit, +}: { + scrollRef: RefObject; + onSubmit: (value: string) => void; +}) { const [query, setQuery] = useState("label:bug"); return (
@@ -83,7 +90,7 @@ function CondensedSearchColumn({ scrollRef }: { scrollRef: RefObject {}} + onSubmit={onSubmit} /> } sortMenu={null} @@ -96,43 +103,63 @@ function CondensedSearchColumn({ scrollRef }: { scrollRef: RefObject} scrollRef={scrollRef} /> - +
); } -async function renderCondensed() { - await using stack = new AsyncDisposableStack(); - const scrollRef = createRef(); - const screen = stack.use(await render()); - scrollRef.current?.scrollTo({ top: 1000 }); - const searches = page.getByRole("searchbox", { name: "Search pull requests" }); - // The topbar copy comes first and mounts once the header condenses. - await expect.element(searches.nth(1)).toBeInTheDocument(); - const environment = stack.move(); - return Object.assign(screen, { - [Symbol.asyncDispose]: () => environment.disposeAsync(), - topbarSearch: searches.nth(0), - }); -} - describe("PullRequestsColumn condensed search", () => { - it("keeps the topbar search focused when Escape clears the query that kept it open", async () => { - await using screen = await renderCondensed(); + it("Escape clears the topbar search before the page's Escape leaves", async () => { + const onSubmit = vi.fn(); + const scrollRef = createRef(); + await using _screen = await render( + , + ); + // Mirrors the /pull-requests observer, which leaves on an unclaimed Escape. + const leave = vi.fn(); + using stack = new DisposableStack(); + stack.defer( + registerCommands( + {}, + { + observe: (event, consumed) => { + if (!consumed && !event.repeat && !event.isComposing && event.key === "Escape") leave(); + }, + }, + ), + ); + scrollRef.current?.scrollTo({ top: 1000 }); + const searches = page.getByRole("searchbox", { name: "Search pull requests" }); + // The topbar copy comes first and mounts once the header condenses. + await expect.element(searches.nth(1)).toBeInTheDocument(); + const search = searches.nth(0); + // Safari ends the composition just before the confirming keydown, reporting only keyCode 229. + const pressDuringComposition = (key: string) => + act(() => { + for (const composition of [{ isComposing: true }, { keyCode: 229 }]) { + search.element().dispatchEvent(new CompositionEvent("compositionend", { bubbles: true })); + search + .element() + .dispatchEvent(new KeyboardEvent("keydown", { key, ...composition, bubbles: true })); + } + }); + + await userEvent.click(search); + await pressDuringComposition("Enter"); + await pressDuringComposition("Escape"); + expect(onSubmit).not.toHaveBeenCalled(); + expect(leave).not.toHaveBeenCalled(); + await expect.element(search).toHaveValue("label:bug"); - await userEvent.click(screen.topbarSearch); await userEvent.keyboard("{Escape}"); - await expect.element(screen.topbarSearch).toHaveValue(""); - await expect.element(screen.topbarSearch).toHaveFocus(); - }); + await expect.element(search).toHaveValue(""); + await expect.element(search).toHaveFocus(); + expect(leave).not.toHaveBeenCalled(); - it("collapses the topbar search when its query clears after focus left it", async () => { - await using screen = await renderCondensed(); + await userEvent.keyboard("{Escape}"); + expect(leave).toHaveBeenCalledOnce(); - await userEvent.click(screen.topbarSearch); - await userEvent.click(page.getByRole("button", { name: "Clear query" })); + await userEvent.click(page.getByRole("button", { name: "Elsewhere" })); await expect .element(page.getByRole("button", { name: "Search pull requests" })) .toBeInTheDocument();