Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): keep a row menu open when other elements scroll

Yudhi Armyndharisce38fb9f43c9
diff --git a/dashboard/src/components/chats/ChatRowMenu.tsx b/dashboard/src/components/chats/ChatRowMenu.tsx
index b48023651..3f88b3dab 100644
--- a/dashboard/src/components/chats/ChatRowMenu.tsx
+++ b/dashboard/src/components/chats/ChatRowMenu.tsx
@@ -111,19 +111,21 @@ function ChatRowMenu({ chat, actions }: { chat: Chat; actions: ChatRowActions })
setOpen(false);
triggerRef.current?.focus();
};
- // A fixed popover would drift from its row, so a scroll of the list or a resize closes it.
- const onMove = (event: Event) => {
- if (!popoverRef.current?.contains(event.target as Node)) setOpen(false);
+ // A fixed popover would drift from its row, so a resize closes it, and so does a scroll of anything the row
+ // sits in. The scroll of another element (the open thread following a live message) does not move the row.
+ const onScroll = (event: Event) => {
+ if ((event.target as Node).contains(rootRef.current)) setOpen(false);
};
+ const onResize = () => setOpen(false);
document.addEventListener('mousedown', onPress);
document.addEventListener('keydown', onEscape, true);
- document.addEventListener('scroll', onMove, true);
- window.addEventListener('resize', onMove);
+ document.addEventListener('scroll', onScroll, true);
+ window.addEventListener('resize', onResize);
return () => {
document.removeEventListener('mousedown', onPress);
document.removeEventListener('keydown', onEscape, true);
- document.removeEventListener('scroll', onMove, true);
- window.removeEventListener('resize', onMove);
+ document.removeEventListener('scroll', onScroll, true);
+ window.removeEventListener('resize', onResize);
};
}, [open]);
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index ad365c796..d42d2d13e 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -710,6 +710,23 @@ test("dismissing a dialog the room's menu opened, or the menu itself, returns fo
assert.equal(focusedName(), 'More actions', 'focus fell to the page after Escape');
});
+test('a row menu stays open while the open thread scrolls, which does not move its row', async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ const { container } = renderPage();
+ fireEvent.click(await screen.findByText('Alice'));
+ await waitFor(() => assert.ok(container.querySelector('.room-messages'), 'the thread did not open'));
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for Alice' }));
+ assert.ok(container.querySelector('.chat-row-menu-popover'), 'the menu did not open');
+
+ // A message that arrives makes the open thread scroll to its end.
+ fireEvent.scroll(container.querySelector('.room-messages') as HTMLElement);
+ assert.ok(container.querySelector('.chat-row-menu-popover'), 'a scroll of the thread closed the menu');
+
+ // The list the row sits in does move it.
+ fireEvent.scroll(container.querySelector('.chats-list') as HTMLElement);
+ assert.equal(container.querySelector('.chat-row-menu-popover'), null, 'the menu stayed open, adrift from its row');
+});
+
test("a row's menu is placed by physical edges, so a right-to-left page keeps the position it computed", async () => {
const { screen, fireEvent } = rtl;
const { container } = renderPage();