diff --git a/ui/src/ui/chat/grouped-render.test.ts b/ui/src/ui/chat/grouped-render.test.ts index 24f0645b649..4dd75f0060b 100644 --- a/ui/src/ui/chat/grouped-render.test.ts +++ b/ui/src/ui/chat/grouped-render.test.ts @@ -303,6 +303,14 @@ function openDeleteConfirm(deleteButton: HTMLButtonElement) { deleteButton.dispatchEvent(new MouseEvent("click", { bubbles: true })); } +function clickDeleteButtonIconPath(deleteButton: HTMLButtonElement) { + const icon = document.createElementNS("http://www.w3.org/2000/svg", "svg"); + const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); + icon.appendChild(path); + deleteButton.appendChild(icon); + path.dispatchEvent(new MouseEvent("click", { bubbles: true })); +} + function setupArmedDeleteConfirm() { const flushAnimationFrames = stubAnimationFrameQueue(); const addListenerSpy = vi.spyOn(document, "addEventListener"); @@ -455,6 +463,15 @@ describe("grouped chat rendering", () => { expect(fixture.onDelete).not.toHaveBeenCalled(); }); + it("removes the delete confirm outside-click listener when the delete button icon toggles it", () => { + const fixture = setupArmedDeleteConfirm(); + + clickDeleteButtonIconPath(fixture.deleteButton); + + expectDeleteConfirmDismissed(fixture); + expect(fixture.onDelete).not.toHaveBeenCalled(); + }); + it("does not attach the delete confirm outside-click listener after an immediate toggle", () => { const flushAnimationFrames = stubAnimationFrameQueue(); const addListenerSpy = vi.spyOn(document, "addEventListener"); diff --git a/ui/src/ui/chat/grouped-render.ts b/ui/src/ui/chat/grouped-render.ts index 87f59f0cabd..53fe34d903a 100644 --- a/ui/src/ui/chat/grouped-render.ts +++ b/ui/src/ui/chat/grouped-render.ts @@ -676,7 +676,7 @@ function renderDeleteButton(onDelete: () => void, side: DeleteConfirmSide) { } function closeOnOutside(evt: MouseEvent) { const target = evt.target; - if (target instanceof Node && !popover.contains(target) && target !== btn) { + if (target instanceof Node && !popover.contains(target) && !btn.contains(target)) { dismissPopover(); } }