From 875c557bb00f2ce29c8eb10f5e89fb947198826a Mon Sep 17 00:00:00 2001 From: Badcuban <108198679+badcuban@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:23:28 -0500 Subject: [PATCH] fix(web): Escape closes only an agent pill's menu after a long press After a long press opened an agent pill's menu in the model picker's phone drawer, Escape closed the whole drawer. The mouse press the browser sends when the finger lifts lands outside the menu. The pill already cancelled the close that press asked for, but the press still moved the keyboard focus from the menu to the page, so Escape went to the drawer. The pill now also prevents that press's default, which keeps the focus in the menu. The long-press test checks that the press is taken and that Escape leaves the drawer open. --- .../src/components/ChatView.agents.browser.tsx | 17 +++++++++++++++-- apps/web/src/components/chat/RoomAgentsBar.tsx | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/ChatView.agents.browser.tsx b/apps/web/src/components/ChatView.agents.browser.tsx index d5aed0e21..c80763c3e 100644 --- a/apps/web/src/components/ChatView.agents.browser.tsx +++ b/apps/web/src/components/ChatView.agents.browser.tsx @@ -1848,11 +1848,15 @@ describe("ChatView (full app): agent browser tabs and rooms", () => { await new Promise((resolve) => setTimeout(resolve, holdMs)); element.dispatchEvent(new PointerEvent("pointerup", finger)); const under = document.elementFromPoint(at.clientX, at.clientY) ?? element; - for (const type of ["mousedown", "mouseup", "click"]) { + // A real mouse press moves the keyboard focus to what it lands on, + // unless the page takes the press. + const pressTaken = !under.dispatchEvent(new MouseEvent("mousedown", at)); + for (const type of ["mouseup", "click"]) { under.dispatchEvent(new MouseEvent(type, at)); } // Let what those did reach the page. await new Promise((resolve) => setTimeout(resolve, 100)); + return { pressTaken }; }; const mounted = await mountChatView({ viewport: PHONE_VIEWPORT, @@ -1905,12 +1909,21 @@ describe("ChatView (full app): agent browser tabs and rooms", () => { // The hold opens the menu, and lifting the finger leaves it open, // without picking the pill or closing the drawer. - await touch(astra, 700); + const lift = await touch(astra, 700); expect(astra.hasAttribute("data-menu-open")).toBe(true); expect(menuItem("Renameā¦")).not.toBeNull(); expect(pill(astraId)?.getAttribute("aria-checked")).toBe("false"); expect(sheet()).not.toBeNull(); + // The lift's press is taken, so the keyboard focus stays in the menu: + // Escape closes the menu, not the drawer around it. + expect(lift.pressTaken).toBe(true); + await userEvent.keyboard("{Escape}"); + await vi.waitFor(() => expect(astra.hasAttribute("data-menu-open")).toBe(false)); + expect(sheet()).not.toBeNull(); + await touch(astra, 700); + expect(astra.hasAttribute("data-menu-open")).toBe(true); + // A tap outside the menu still closes it, and only it. await new Promise((resolve) => setTimeout(resolve, 500)); await touch(document.querySelector('[data-slot="menu-backdrop"]')!, 40); diff --git a/apps/web/src/components/chat/RoomAgentsBar.tsx b/apps/web/src/components/chat/RoomAgentsBar.tsx index f0fcd619f..3d992ce15 100644 --- a/apps/web/src/components/chat/RoomAgentsBar.tsx +++ b/apps/web/src/components/chat/RoomAgentsBar.tsx @@ -333,9 +333,12 @@ function AgentPill(props: {