Skip to content

Commit f8278d8

Browse files
AatmanAJAatman Jainclaudemaria-rcks
authored
fix(web): keep typed Settings text when Esc closes Settings (#25131)
Co-authored-by: Aatman Jain <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent bb7ed73 commit f8278d8

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
import { page, userEvent } from "vite-plus/test/browser";
3+
4+
import { render } from "../../test/render";
5+
import { useCommitOnBlur } from "../hooks/useCommitOnBlur";
6+
import { AppRouteModal } from "./AppRouteModal";
7+
8+
function CommitOnBlurField({ onCommit }: { onCommit: (next: string) => void }) {
9+
return <input aria-label="Instructions" {...useCommitOnBlur("", onCommit)} />;
10+
}
11+
12+
describe("AppRouteModal", () => {
13+
it("commits a focused field when Esc closes it", async () => {
14+
const onCommit = vi.fn();
15+
await using _screen = await render(
16+
<AppRouteModal label="Settings">
17+
<CommitOnBlurField onCommit={onCommit} />
18+
</AppRouteModal>,
19+
{ router: "/settings/general" },
20+
);
21+
22+
await page.getByRole("textbox", { name: "Instructions" }).fill("Keep titles short");
23+
await userEvent.keyboard("{Escape}");
24+
25+
expect(onCommit).toHaveBeenCalledWith("Keep titles short");
26+
});
27+
});

‎apps/web/src/components/AppRouteModal.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export function AppRouteModal({ label, children }: { label: string; children: Re
2727
// Portaled layers outside this tree (toasts, Clerk, confirm dialogs) are not backdrop presses.
2828
disablePointerDismissal
2929
onOpenChange={(nextOpen) => {
30-
if (!nextOpen) setOpen(false);
30+
if (nextOpen) return;
31+
// Closing unmounts a focused field without a blur, so commit-on-blur rows would
32+
// drop what was typed. Blur first so they commit.
33+
const focused = document.activeElement;
34+
if (focused instanceof HTMLElement && popupRef.current?.contains(focused)) focused.blur();
35+
setOpen(false);
3136
}}
3237
onOpenChangeComplete={(nextOpen) => {
3338
if (!nextOpen) void closeAppModal();

0 commit comments

Comments
 (0)