();
+ 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.keyboard("{Escape}");
+ await expect.element(search).toHaveValue("");
+ await expect.element(search).toHaveFocus();
+ expect(leave).not.toHaveBeenCalled();
+
+ await userEvent.keyboard("{Escape}");
+ expect(leave).toHaveBeenCalledOnce();
+
+ await userEvent.click(page.getByRole("button", { name: "Elsewhere" }));
+ 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}