Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(chat): keep right-click actions open during pointer movement (#10666)
Danila Katalshov98c7eb4f639d
diff --git a/packages/views/chat/components/chat-thread-list.test.tsx b/packages/views/chat/components/chat-thread-list.test.tsxindex f4cbd9c035..cd474c6c34 100644--- a/packages/views/chat/components/chat-thread-list.test.tsx+++ b/packages/views/chat/components/chat-thread-list.test.tsx@@ -1,5 +1,6 @@import { describe, expect, it, vi, beforeEach } from "vitest";import { fireEvent, render, screen } from "@testing-library/react";+import userEvent from "@testing-library/user-event";import { VirtuosoMockContext } from "react-virtuoso";import { I18nProvider } from "@multica/core/i18n/react";import type { Agent, ChatSession } from "@multica/core/types";@@ -325,7 +326,7 @@ describe("ChatThreadList right-click menu", () => {archiveMutate.mockClear();});- it("opens the row's actions at the cursor and acts on that row", async () => {+ it("keeps the row's actions available after pointer departure and acts on that row", async () => {const { onArchive, onSelectSession } = renderList("s1");fireEvent.contextMenu(screen.getByText("Chat s2"), { clientX: 30, clientY: 90 });@@ -334,9 +335,52 @@ describe("ChatThreadList right-click menu", () => {Array.from(menu.querySelectorAll('[role="menuitem"]'), (el) => el.textContent?.trim()),).toEqual([enChat.list.pin, ARCHIVE_LABEL, enChat.header.rename]);+ fireEvent.mouseLeave(menu.parentElement!, { relatedTarget: document.body });+ expect(screen.getByRole("menu")).toBeVisible();+fireEvent.click(screen.getByRole("menuitem", { name: ARCHIVE_LABEL }));expect(onArchive).toHaveBeenCalledTimes(1);expect(onArchive.mock.calls[0]![0]).toMatchObject({ id: "s2" });expect(onSelectSession).not.toHaveBeenCalled();+ expect(screen.queryByRole("menu")).not.toBeInTheDocument();+ });++ it("dismisses with Escape and reopens actions for a different chat", async () => {+ const { onArchive } = renderList("s1");+ fireEvent.contextMenu(screen.getByText("Chat s2"), { clientX: 30, clientY: 90 });+ fireEvent.keyDown(await screen.findByRole("menu"), { key: "Escape" });+ expect(screen.queryByRole("menu")).not.toBeInTheDocument();++ fireEvent.contextMenu(screen.getByText("Chat s3"), { clientX: 40, clientY: 140 });+ fireEvent.click(await screen.findByRole("menuitem", { name: ARCHIVE_LABEL }));+ expect(onArchive).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ id: "s3" }));+ });++ it("dismisses on an outside press without running a row action", async () => {+ const { onArchive, onSelectSession } = renderList("s1");+ fireEvent.contextMenu(screen.getByText("Chat s2"), { clientX: 30, clientY: 90 });+ await screen.findByRole("menu");+ await userEvent.click(document.body);+ expect(screen.queryByRole("menu")).not.toBeInTheDocument();+ expect(onArchive).not.toHaveBeenCalled();+ expect(onSelectSession).not.toHaveBeenCalled();+ });++ it("keeps the modal dismissal layer after pointer departure", async () => {+ const { onArchive, onSelectSession } = renderList("s1");+ fireEvent.contextMenu(screen.getByText("Chat s2"), { clientX: 30, clientY: 90 });+ const menu = await screen.findByRole("menu");+ // The real Base UI backdrop prevents an outside press reaching the row below.+ const backdrop = document.querySelector<HTMLElement>(+ 'div[role="presentation"][data-base-ui-inert]',+ )!;+ expect(backdrop).toBeInTheDocument();++ fireEvent.mouseLeave(menu.parentElement!, { relatedTarget: document.body });+ expect(backdrop).toBeInTheDocument();+ await userEvent.click(backdrop);+ expect(screen.queryByRole("menu")).not.toBeInTheDocument();+ expect(onArchive).not.toHaveBeenCalled();+ expect(onSelectSession).not.toHaveBeenCalled();});});diff --git a/packages/views/common/row-actions-menu.test.tsx b/packages/views/common/row-actions-menu.test.tsxindex bac9bfe423..768da0faca 100644--- a/packages/views/common/row-actions-menu.test.tsx+++ b/packages/views/common/row-actions-menu.test.tsx@@ -1,6 +1,6 @@import { describe, expect, it, vi } from "vitest";import { fireEvent, render, screen } from "@testing-library/react";-import { RowActionsMenu } from "./row-actions-menu";+import { RowActionsMenu, RowActionsPointMenu } from "./row-actions-menu";describe("RowActionsMenu", () => {it("names its trigger so a screen reader can announce the row's actions", () => {@@ -55,3 +55,14 @@ describe("RowActionsMenu", () => {expect(container).toBeEmptyDOMElement();});});++it("does not open an empty cursor menu", () => {+ render(+ <RowActionsPointMenu+ menu={{ open: true, point: { x: 30, y: 40 } }}+ onOpenChange={vi.fn()}+ groups={[[], []]}+ />,+ );+ expect(screen.queryByRole("menu")).not.toBeInTheDocument();+});diff --git a/packages/views/common/row-actions-menu.tsx b/packages/views/common/row-actions-menu.tsxindex cafe17f0e5..19a409eaa2 100644--- a/packages/views/common/row-actions-menu.tsx+++ b/packages/views/common/row-actions-menu.tsx@@ -9,7 +9,7 @@ import {DropdownMenuSeparator,DropdownMenuTrigger,} from "@multica/ui/components/ui/dropdown-menu";-import { usePointAnchor, type RowMenuState } from "./point-menu";+import { nextRowMenuState, usePointAnchor, type RowMenuState } from "./point-menu";export interface RowActionItem {key: string;@@ -101,7 +101,16 @@ export function RowActionsPointMenu({const filled = groups.filter((group) => group.length > 0);return (- <DropdownMenu open={menu.open && filled.length > 0} onOpenChange={onOpenChange}>+ <DropdownMenu+ open={menu.open && filled.length > 0}+ onOpenChange={(open, details) => {+ if (!nextRowMenuState(menu, open, details.reason)) {+ details.cancel();+ return;+ }+ onOpenChange(open);+ }}+ ><DropdownMenuContent align="start" anchor={anchor} className="w-auto"><RowActionGroups groups={filled} /></DropdownMenuContent>