Skip to content

Commit c657097

Browse files
Aatman Jainclaude
authored andcommitted
fix(web): keep typed Settings text when Esc closes Settings
Settings fields such as thread title instructions and the project name commit on blur. Esc closed the modal and unmounted the focused field without a blur, so the typing was lost, while the close button kept it. Blur the focused field before the modal closes so it commits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d414cb5 commit c657097

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)