Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(mentions): close the phone @ menu on one Escape or Android Back (#8750)

gbirman585205b49c01
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
index 81b215be9b..1b4a320a93 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
@@ -110,6 +110,19 @@ vi.mock('@ui', () => ({
}));
const originalScrollIntoView = Element.prototype.scrollIntoView;
+const mockNoEmails = () =>
+ vi.mocked(useEmailSearchMention).mockReturnValue({
+ emails: () => [],
+ totalCount: () => 0,
+ hasMore: () => false,
+ isLoadingMore: () => false,
+ loadMore: async () => {},
+ });
+const manyUsers: IUser[] = Array.from({ length: 20 }, (_, i) => ({
+ id: `macro|person${i}@macro.com`,
+ name: `Person ${i}`,
+ email: `person${i}@macro.com`,
+}));
afterEach(() => {
mocks.crmEnabled = false;
@@ -233,6 +246,51 @@ it.each([false, true])(
}
);
+it('closes the mobile menu on the first Escape', () => {
+ mocks.mobile = true;
+ Element.prototype.scrollIntoView = vi.fn();
+ mockNoEmails();
+ const menu = createMenuOperations();
+ render(() => (
+ <MentionsMenu
+ menu={menu}
+ editor={createEditor()}
+ users={() => manyUsers}
+ sources={['users']}
+ />
+ ));
+
+ menu.openMenu();
+ expect(menu.isOpen()).toBe(true);
+ expect(screen.queryByText(/View all/)).toBeNull();
+ fireEvent.keyDown(document, { key: 'Escape' });
+ expect(menu.isOpen()).toBe(false);
+ expect(screen.queryByText(/View all/)).toBeNull();
+});
+
+it('leaves a category list on the first desktop Escape and closes on the second', () => {
+ Element.prototype.scrollIntoView = vi.fn();
+ mockNoEmails();
+ const menu = createMenuOperations();
+ render(() => (
+ <MentionsMenu
+ menu={menu}
+ editor={createEditor()}
+ users={() => manyUsers}
+ sources={['users']}
+ />
+ ));
+
+ menu.openMenu();
+ fireEvent.keyDown(document, { key: 'ArrowRight' });
+ expect(screen.getByText('Back to everything')).toBeTruthy();
+ fireEvent.keyDown(document, { key: 'Escape' });
+ expect(menu.isOpen()).toBe(true);
+ expect(screen.queryByText('Back to everything')).toBeNull();
+ fireEvent.keyDown(document, { key: 'Escape' });
+ expect(menu.isOpen()).toBe(false);
+});
+
it('only paginates an open mobile menu and resumes on reopen', async () => {
mocks.mobile = true;
mocks.crmEnabled = true;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index d9193daf74..4733962fd3 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -553,6 +553,9 @@ function MentionsMenuInner(props: MentionsMenuProps) {
setMenuOpen(false);
};
+ // Phones only show the full list, so there is no grouped view to go back to.
+ const canExitViewAll = () => controller.isViewAllMode() && !isMobile();
+
useMenuKeyboardNavigation({
isActive: menuOpen,
onUp: () => {
@@ -562,7 +565,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
controller.selectNext();
},
onLeft: () => {
- if (controller.isViewAllMode()) {
+ if (canExitViewAll()) {
controller.exitViewAll();
}
},
@@ -596,7 +599,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
setMenuOpen(false);
},
onClose: () => {
- if (controller.isViewAllMode()) {
+ if (canExitViewAll()) {
controller.exitViewAll();
} else {
closeMenu();