Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/web/src/components/ChatView.agents.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/chat/RoomAgentsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,12 @@ function AgentPill(props: {
<Menu
open={menuOpen}
onOpenChange={(open, details) => {
// The finger that held the pill, lifting.
// The finger that held the pill, lifting. Its press must not
// close the menu, nor take the keyboard focus out of it:
// Escape would then close the picker around the menu instead.
if (!open && details.reason === "outside-press" && holdStillDown()) {
details.cancel();
details.event.preventDefault();
return;
}
setMenuOpen(open);
Expand Down
Loading