Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(sidebar): keep composing Escape from closing the phone drawer

hadan89777692218bfc93
diff --git a/src/components/SidebarNewRoomPanel.ime.test.ts b/src/components/SidebarNewRoomPanel.ime.test.ts
index 689aad909e..7fbebc9d41 100644
--- a/src/components/SidebarNewRoomPanel.ime.test.ts
+++ b/src/components/SidebarNewRoomPanel.ime.test.ts
@@ -113,3 +113,20 @@ describe("Team dialog with an input method", () => {
expect(onClose).toHaveBeenCalledOnce();
});
});
+
+describe("composing keys stay inside the dialog", () => {
+ // The phone sidebar drawer closes on any Escape that reaches document.
+ it.each(composing)("does not let the $name Escape reach document", ({ init }) => {
+ const outside = vi.fn();
+ document.addEventListener("keydown", outside);
+ try {
+ flushSync(() => root.render(createElement(NewRoomPanel, { onClose: vi.fn() })));
+ for (const input of document.querySelectorAll<HTMLInputElement>("input")) press(input, "Escape", init);
+ flushSync(() => root.render(createElement(TeamDialog, { section: "Research", rename: true, onClose: vi.fn() })));
+ press(document.querySelector<HTMLInputElement>('[role="dialog"] input')!, "Escape", init);
+ expect(outside).not.toHaveBeenCalled();
+ } finally {
+ document.removeEventListener("keydown", outside);
+ }
+ });
+});
diff --git a/src/components/SidebarNewRoomPanel.tsx b/src/components/SidebarNewRoomPanel.tsx
index 013219ef61..ce6137257f 100644
--- a/src/components/SidebarNewRoomPanel.tsx
+++ b/src/components/SidebarNewRoomPanel.tsx
@@ -43,7 +43,7 @@ export function NewRoomPanel({ onClose }: { onClose: () => void }) {
value={name}
onChange={(e) => setName(e.target.value)}
onKeyDown={(e) => {
- if (imeComposing(e.nativeEvent)) return;
+ if (imeComposing(e.nativeEvent)) { e.stopPropagation(); return; }
if (e.key === "Enter") create();
if (e.key === "Escape") onClose();
}}
@@ -55,7 +55,7 @@ export function NewRoomPanel({ onClose }: { onClose: () => void }) {
maxLength={60}
onChange={(e) => setSection(e.target.value)}
onKeyDown={(e) => {
- if (imeComposing(e.nativeEvent)) return;
+ if (imeComposing(e.nativeEvent)) { e.stopPropagation(); return; }
if (e.key === "Enter") create();
if (e.key === "Escape") onClose();
}}
diff --git a/src/components/TeamDialog.tsx b/src/components/TeamDialog.tsx
index 7c7d03aead..001a75d91c 100644
--- a/src/components/TeamDialog.tsx
+++ b/src/components/TeamDialog.tsx
@@ -69,7 +69,7 @@ export function TeamDialog({ section, rename = false, onClose, onRenamed }: {
<div ref={dialog} role="dialog" aria-modal="true" aria-labelledby="team-dialog-title"
className="max-h-[90vh] w-full max-w-[430px] overflow-y-auto rounded-2xl border border-hairline/50 bg-panel p-5 text-ink shadow-2xl"
onKeyDown={(event) => {
- if (imeComposing(event.nativeEvent)) return;
+ if (imeComposing(event.nativeEvent)) { event.stopPropagation(); return; }
if (event.key === "Escape" && !saving) { event.stopPropagation(); onClose(); }
if (event.key === "Tab") {
const controls = dialog.current?.querySelectorAll<HTMLElement>("input:enabled, button:enabled");