Skip to content

Commit eb3a600

Browse files
authored
fix(ui): preserve native context menu for chat links (#111618)
1 parent 367fe9a commit eb3a600

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

ui/src/pages/chat/chat-view.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,6 +5441,27 @@ describe("right-click Reply", () => {
54415441
expect(target.text).toBe("x".repeat(499));
54425442
});
54435443

5444+
it("keeps the native context menu for links inside a replyable bubble", () => {
5445+
const container = renderChatView({ onSetReply: vi.fn() });
5446+
const group = document.createElement("div");
5447+
group.className = "chat-group";
5448+
const bubble = document.createElement("div");
5449+
bubble.className = "chat-bubble";
5450+
bubble.dataset.messageText = "hello world";
5451+
const link = document.createElement("a");
5452+
link.href = "https://example.com";
5453+
link.textContent = "Example";
5454+
bubble.appendChild(link);
5455+
group.appendChild(bubble);
5456+
container.querySelector(".chat-thread-inner")!.appendChild(group);
5457+
5458+
const evt = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
5459+
link.dispatchEvent(evt);
5460+
5461+
expect(evt.defaultPrevented).toBe(false);
5462+
expect(document.querySelector(".chat-reply-context-menu")).toBeNull();
5463+
});
5464+
54445465
it("keeps the native context menu when Reply is unavailable", () => {
54455466
const container = renderChatView();
54465467
const section = container.querySelector<HTMLElement>(".card.chat");

ui/src/pages/chat/components/chat-thread.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ function handleChatThreadSelectionPointerUp(event: PointerEvent, props: ChatThre
795795
}
796796

797797
function handleChatContextMenu(event: MouseEvent, props: ChatThreadProps) {
798+
if (event.composedPath().some((target) => target instanceof HTMLAnchorElement)) {
799+
return;
800+
}
798801
const bubble = (event.target as HTMLElement).closest(".chat-bubble");
799802
if (!bubble) {
800803
return;

0 commit comments

Comments
 (0)