Skip to content

Build your personal knowledge base with Trilium Notes

fix(menu): make a tapped submenu row active on a phone

Claudeca15ed0548ad
diff --git a/apps/client/src/menus/context_menu.spec.ts b/apps/client/src/menus/context_menu.spec.ts
index a72edf903a..d4dcb87efd 100644
--- a/apps/client/src/menus/context_menu.spec.ts
+++ b/apps/client/src/menus/context_menu.spec.ts
@@ -884,6 +884,32 @@ describe("contextMenu", () => {
}
});
+ it("keeps the keys on a phone's row that a tap folded, not on the hidden child", async () => {
+ layout.onMobile = true;
+ try {
+ const picked: string[] = [];
+ await openMenu((title) => picked.push(title));
+ key("End");
+ await vi.waitFor(() => expect(activeRow()).toBe("Templates"));
+ key("Enter");
+ await vi.waitFor(() => expect(activeRow()).toBe("Meeting"));
+ const parent = menuElement()?.querySelector<HTMLElement>("li.dropdown-submenu");
+ expect(parent).toBeTruthy();
+
+ parent?.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0 }));
+ await vi.waitFor(() => expect(parent?.classList.contains("submenu-open")).toBe(false));
+ expect(activeRow()).toBe("Templates");
+
+ key("ArrowUp");
+ await vi.waitFor(() => expect(activeRow()).toBe("Paste"));
+ key("Enter");
+ expect(picked).not.toContain("Meeting");
+ expect(picked.at(-1)).toBe("Paste");
+ } finally {
+ layout.onMobile = false;
+ }
+ });
+
it("runs the active row on Enter, with focus back where it was", async () => {
const picked: string[] = [];
const { contextMenu, editor } = await openMenu((title) => {
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index 978c814083..106c01a1fa 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -451,9 +451,11 @@ function MenuRow<T>({ level, item, state }: { level: number, item: MenuCommandIt
e.stopPropagation();
if (disabled) return;
- // Pressed again, an unfolded row folds its submenu back.
+ // Pressed again, an unfolded row folds its submenu back. The keys go on from this
+ // row, as a folded or replaced submenu's rows are gone.
if (hasSubmenu && isMobile()) {
state.openSubmenu(level, open ? undefined : item, e.currentTarget, true);
+ state.setActive(level, item);
return;
}
if (hasSubmenu) state.openSubmenu(level, item, e.currentTarget, true);