Skip to content

Build your personal knowledge base with Trilium Notes

feat(mobile): open a menu's submenus as pages in its place

Elian Dorana86e983ba2ab
diff --git a/apps/client/src/menus/context_menu.spec.ts b/apps/client/src/menus/context_menu.spec.ts
index c96b32bffb..30faab34c0 100644
--- a/apps/client/src/menus/context_menu.spec.ts
+++ b/apps/client/src/menus/context_menu.spec.ts
@@ -651,26 +651,50 @@ describe("contextMenu", () => {
expect(again.isShown).toBe(false);
});
- it("unfolds a submenu under its row on a phone", async () => {
+ it("opens a submenu on a phone as a page in the menu's place, and goes back from its header", async () => {
layout.onMobile = true;
const picked: string[] = [];
- await openMenu((title) => picked.push(title));
+ const contextMenu = await openMenu((title) => picked.push(title));
const parent = row("Templates");
+ /** The pages standing open, each as its title followed by the titles of its rows. */
+ const pages = () => [ ...menuElement()?.querySelectorAll(":scope > .tn-menu-page") ?? [] ].map((page) => [
+ page.querySelector(".tn-master-detail-title")?.textContent,
+ ...[ ...page.querySelectorAll(":scope > .tn-menu-scroll > li") ]
+ .map((item) => item.querySelector(":scope > span")?.textContent)
+ ]);
+ const back = () => {
+ const button = [ ...menuElement()?.querySelectorAll<HTMLElement>(".tn-menu-page-header button") ?? [] ].at(-1);
+ if (!button) throw new Error("expected a back button");
+ press(button);
+ };
hover(parent);
- expect(layers()).toEqual([]);
+ expect(pages()).toEqual([]);
press(parent);
- await vi.waitFor(() => expect(parent.classList.contains("submenu-open")).toBe(true));
- const nested = parent.querySelector(":scope > ul.dropdown-menu");
- expect(nested?.classList.contains("show")).toBe(true);
- expect(nested?.textContent).toBe("Meeting");
- // Unfolding runs nothing.
+ await vi.waitFor(() => expect(pages()).toEqual([ [ "Templates", "Meeting" ] ]));
+ // Opening runs nothing, and neither unfolds rows in the row nor draws a layer beside it.
expect(picked).toEqual([]);
+ expect(parent.querySelector(".dropdown-menu")).toBeNull();
expect(layers()).toEqual([]);
- press(parent);
- await vi.waitFor(() => expect(parent.classList.contains("submenu-open")).toBe(false));
+ press(row("Meeting"));
+ await vi.waitFor(() => expect(pages()).toEqual([ [ "Templates", "Meeting" ], [ "Meeting", "Weekly" ] ]));
+
+ // Back goes up one level at a time, running nothing and keeping the menu up.
+ back();
+ await vi.waitFor(() => expect(pages()).toEqual([ [ "Templates", "Meeting" ] ]));
+ back();
+ await vi.waitFor(() => expect(pages()).toEqual([]));
+ expect(picked).toEqual([]);
+ expect(contextMenu.isShown).toBe(true);
+
+ // A row on a page runs and closes the menu, like any other.
+ press(row("Templates"));
+ press(await vi.waitFor(() => row("Meeting")));
+ press(await vi.waitFor(() => row("Weekly")));
+ expect(picked).toEqual([ "Weekly" ]);
+ expect(contextMenu.isShown).toBe(false);
});
});
@@ -1194,26 +1218,25 @@ describe("contextMenu", () => {
document.removeEventListener("keydown", dialogHeard);
});
- it("unfolds a submenu on a phone as Right and Enter open one, and folds it back on Escape", async () => {
+ it("opens a submenu's page on a phone as Right and Enter open one, and goes back on Escape", async () => {
layout.onMobile = true;
try {
await openMenu();
key("End");
await vi.waitFor(() => expect(activeRow()).toBe("Templates"));
- const parent = menuElement()?.querySelector<HTMLElement>("li.dropdown-submenu");
key("Enter");
await vi.waitFor(() => expect(activeRow()).toBe("Meeting"));
- expect(parent?.classList.contains("submenu-open")).toBe(true);
- expect(parent?.querySelector(":scope > ul.dropdown-menu.show")?.textContent).toContain("Weekly");
- // Unfolded in place, not as a layer beside it.
+ const page = menuElement()?.querySelector(":scope > .tn-menu-page");
+ expect(page?.querySelector(".tn-menu-scroll")?.textContent).toBe("MeetingWeekly");
+ // A page in the menu's place, not a layer beside it.
expect(menuElement()?.querySelector("div.dropdown-submenu")).toBeNull();
key("ArrowDown");
await vi.waitFor(() => expect(activeRow()).toBe("Weekly"));
key("Escape");
await vi.waitFor(() => expect(activeRow()).toBe("Templates"));
- expect(parent?.classList.contains("submenu-open")).toBe(false);
+ expect(menuElement()?.querySelector(".tn-menu-page")).toBeNull();
key("ArrowRight");
await vi.waitFor(() => expect(activeRow()).toBe("Meeting"));
@@ -1222,28 +1245,35 @@ describe("contextMenu", () => {
}
});
- it("keeps the keys on a phone's row that a tap folded, not on the hidden child", async () => {
+ it("moves the keys onto the page a tap opened, and back to its row from the header", 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 press = (target: Element | null | undefined) => {
+ target?.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0 }));
+ target?.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, button: 0 }));
+ };
const parent = menuElement()?.querySelector<HTMLElement>("li.dropdown-submenu");
expect(parent).toBeTruthy();
- parent?.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true, button: 0 }));
- parent?.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, button: 0 }));
- await vi.waitFor(() => expect(parent?.classList.contains("submenu-open")).toBe(false));
+ press(parent);
+ await vi.waitFor(() => expect(menuElement()?.querySelector(".tn-menu-page")).not.toBeNull());
+ // No row of the page is active yet, and the first key lands on its first row
+ // rather than on the hidden level under it.
+ key("ArrowDown");
+ await vi.waitFor(() => expect(activeRow()).toBe("Meeting"));
+
+ const back = menuElement()?.querySelector(".tn-menu-page-header button");
+ expect(back).toBeTruthy();
+ press(back);
+ await vi.waitFor(() => expect(menuElement()?.querySelector(".tn-menu-page")).toBeNull());
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");
+ expect(picked).toEqual([ "Paste" ]);
} finally {
layout.onMobile = false;
}
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index bb45c523c5..b7886fae46 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -548,15 +548,6 @@ body.mobile .dropdown-menu .dropdown-submenu > span {
}
-/* Scoped by the menu: a dropdown's menu stands in the page's body, outside its `.dropdown`. */
-body.mobile .dropdown-menu .dropdown-submenu {
- flex-wrap: wrap;
-
- & > span {
- flex-grow: 1;
- }
-}
-
.dropdown-item span.keyboard-shortcut,
.dropdown-item span.menu-trailing-icon,
.dropdown-item *:not(.keyboard-shortcut) > kbd {
@@ -1747,17 +1738,6 @@ body.mobile .dropdown-menu {
z-index: 3000 !important;
}
-body.mobile .dropdown-submenu > .dropdown-menu {
- position: static !important;
- border: 0 !important;
- padding: 0 !important;
- overflow: hidden !important;
- top: unset !important;
- margin-top: 0 !important;
- width: 100%;
- max-height: none;
-}
-
#context-menu-container,
#context-menu-container .dropdown-menu,
.tabulator-popup-container {
diff --git a/apps/client/src/stylesheets/theme-next/base.css b/apps/client/src/stylesheets/theme-next/base.css
index cfd75d3a38..0ba90f7af8 100644
--- a/apps/client/src/stylesheets/theme-next/base.css
+++ b/apps/client/src/stylesheets/theme-next/base.css
@@ -349,7 +349,7 @@ body.desktop .dropdown-submenu .dropdown-toggle::after {
}
/* Right to left, the end side is the left, so the arrow points the other way. */
-body.desktop[dir=rtl] .dropdown-submenu .dropdown-toggle::after {
+body[dir=rtl] .dropdown-submenu .dropdown-toggle::after {
content: "\ea4d" !important;
}
@@ -464,14 +464,11 @@ body.mobile .dropdown-menu:where(:not(.note-autocomplete-menu)) {
backdrop-filter: var(--dropdown-backdrop-filter);
position: relative;
- .dropdown-toggle::after {
- top: 0.5em;
- right: var(--dropdown-menu-padding-horizontal);
- transform: translateX(50%) rotate(90deg);
- }
-
- .dropdown-item.submenu-open .dropdown-toggle::after {
- transform: rotate(270deg);
+ /* A submenu opens as a page in the menu's place, so its arrow points to the end, as on the
+ desktop, and stands in the row's end padding. */
+ .dropdown-submenu .dropdown-toggle::after {
+ bottom: 0;
+ inset-inline-end: calc(var(--dropdown-menu-padding-horizontal) / 2);
}
.dropdown-item,
@@ -504,53 +501,6 @@ body.mobile .dropdown-menu:where(:not(.note-autocomplete-menu)) {
visibility: hidden;
}
- .dropdown-submenu {
- padding: 0 !important;
- backdrop-filter: unset !important;
-
- /* The submenu sits in a track that grows from 0fr to 1fr, so the expanded
- height is whatever the items measure. The toggle's track is max-content
- rather than auto: an auto track absorbs the slack mid-transition and
- visibly stretches the item. */
- display: grid !important;
- grid-template-rows: max-content 0fr;
- transition: grid-template-rows 100ms ease-in;
-
- .dropdown-toggle {
- padding: var(--dropdown-menu-padding-vertical) var(--dropdown-menu-padding-horizontal);
- }
-
- .dropdown-menu {
- --menu-background-color: --menu-submenu-mobile-background-color;
- --bs-dropdown-divider-margin-y: 0.25rem;
- border-radius: 0;
- display: block !important;
-
- /* Counters align-items: center from style.css, which would let the
- submenu keep its content height instead of following the track. */
- align-self: stretch;
- min-height: 0;
- overflow: hidden;
-
- /* The vertical padding grows with the track; applying it at once would
- hold the collapsed submenu open by that much. */
- padding: 0 0.75rem !important;
- transition: padding 100ms ease-in;
-
- &.show {
- padding-block: 0.5rem !important;
- }
- }
-
- &.submenu-open {
- grid-template-rows: max-content 1fr;
-
- .dropdown-toggle {
- padding-bottom: var(--dropdown-menu-padding-vertical);
- }
- }
- }
-
.dropdown-custom-item:has(.note-color-picker) {
overflow-x: auto;
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index b72e9f72d9..596773d823 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4591,6 +4591,7 @@
"menu": {
"no_matches": "No matches",
"filter": "Filter",
- "filter_placeholder": "Type to filter…"
+ "filter_placeholder": "Type to filter…",
+ "back": "Back"
}
}
diff --git a/apps/client/src/widgets/react/Dropdown.spec.tsx b/apps/client/src/widgets/react/Dropdown.spec.tsx
index 614a3021f7..3ad6284d10 100644
--- a/apps/client/src/widgets/react/Dropdown.spec.tsx
+++ b/apps/client/src/widgets/react/Dropdown.spec.tsx
@@ -418,7 +418,7 @@ describe("Dropdown", () => {
expect(picked).toEqual([ "wrap", "title" ]);
});
- it("stays open on a click on a submenu's row, which unfolds the submenu on a phone", async () => {
+ it("stays open on a click on a submenu's row, or on the header of the page it opens on a phone", async () => {
const toggled = vi.fn();
const content = (
<FormDropdownSubmenu icon="bx bx-chip" title="Advanced" onDropdownToggleClicked={toggled}>
@@ -441,13 +441,22 @@ describe("Dropdown", () => {
click(phoneToggle);
await vi.waitFor(() => expect(submenuRow()).toBeTruthy());
submenuRow()?.click();
- await vi.waitFor(() => expect(submenuRow()?.querySelector(":scope > .dropdown-menu.show")?.textContent)
- .toBe("Show log"));
+ const page = () => popup()?.querySelector<HTMLElement>(":scope > .tn-menu-page");
+ await vi.waitFor(() => expect(page()?.querySelector(".tn-menu-scroll")?.textContent).toBe("Show log"));
await new Promise((resolve) => setTimeout(resolve, 20));
expect(popup()).not.toBeNull();
- // A row in the unfolded submenu still closes the menu.
- submenuRow()?.querySelector<HTMLElement>(".dropdown-menu li.dropdown-item")?.click();
+ // Neither does its header, the way back included.
+ page()?.querySelector<HTMLElement>(".tn-master-detail-title")?.click();
+ page()?.querySelector<HTMLElement>(".tn-menu-page-header button")?.click();
+ await vi.waitFor(() => expect(page()).toBeNull());
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ expect(popup()).not.toBeNull();
+
+ // A row on the page still closes the menu.
+ submenuRow()?.click();
+ await vi.waitFor(() => expect(page()).not.toBeNull());
+ page()?.querySelector<HTMLElement>("li.dropdown-item")?.click();
await vi.waitFor(() => expect(popup()).toBeNull());
});
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsx
index 26d0623271..1028106003 100644
--- a/apps/client/src/widgets/react/FormList.tsx
+++ b/apps/client/src/widgets/react/FormList.tsx
@@ -5,14 +5,16 @@ import type { KeyboardActionNames } from "@triliumnext/commons";
import type { Tooltip } from "bootstrap";
import clsx from "clsx";
import { ComponentChildren, createPortal, type CSSProperties, RefObject } from "preact";
-import { useContext, useLayoutEffect, useMemo, useRef } from "preact/hooks";
+import { useCallback, useContext, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
+import { t } from "../../services/i18n";
import { getActionSync } from "../../services/keyboard_actions";
import { handleRightToLeftPlacement, isMobile, openInAppHelpFromUrl } from "../../services/utils";
import FormToggle from "./FormToggle";
import HelpTooltipButton from "./HelpTooltipButton";
import { useStaticTooltip, useSyncedRef, useUniqueName } from "./hooks";
import Icon, { SvgIcon } from "./Icon";
+import { MasterDetailHeader } from "./master_detail";
import { isRightToLeft, MenuContext, type MenuContextValue, MenuFilterContext, MenuLevelContext, type OpenSubmenu, pointerMoved, shouldDropStart, useMenu } from "./menu_context";
import { placeFloating } from "./Popup";
import { joinElements } from "./react_utils";
@@ -403,6 +405,7 @@ function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleCli
const open = openSubmenu?.id === id;
const isActive = menu.active?.id === id;
const filter = filterable ? { rowId: id, level, text: menu.filter?.rowId === id ? menu.filter.text : "" } : undefined;
+ const [ pageSlide, settlePage ] = usePageSlide(open);
/** Runs the row's own action for the keys, with the modifiers of the key that ran it. */
function select(e: MouseEvent | KeyboardEvent) {
@@ -438,25 +441,16 @@ function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleCli
onPointerMove={(e) => {
if (!isActive && pointerMoved(e)) onPointed(e);
}}
- // As any row: the press keeps focus where it was, and the release acts. An unfolded
- // row holds its submenu's rows, whose presses and clicks reach it too; those are theirs.
+ // As any row: the press keeps focus where it was, and the release acts.
onMouseDown={(e) => {
- if (e.button === 0 && !inUnfoldedRows(e)) e.preventDefault();
+ if (e.button === 0) e.preventDefault();
}}
onClick={(e) => {
- if (inUnfoldedRows(e)) return;
// The dropdown's `closeOnClickInside` would close the whole menu.
e.stopPropagation();
if (disabled) return;
- // Clicked 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 (isMobile()) {
- menu.openSubmenu(level, open ? undefined : id, e.currentTarget, true);
- menu.setActive(level, id);
- return;
- }
menu.openSubmenu(level, id, e.currentTarget, true);
- onDropdownToggleClicked?.(e);
+ if (!isMobile()) onDropdownToggleClicked?.(e);
}}
>
<span className="dropdown-toggle">
@@ -465,14 +459,12 @@ function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleCli
<span id={titleId(id)}>{title}</span>
</span>
{isMobile()
- // A phone has no room beside the menu, so an open submenu unfolds under its row.
- ? (
- <ul className={clsx("dropdown-menu", open && "show")} role="menu" aria-labelledby={titleId(id)}>
- <MenuLevelContext.Provider value={level + 1}>
- <MenuFilterContext.Provider value={filter}>{open && children}</MenuFilterContext.Provider>
- </MenuLevelContext.Provider>
- </ul>
- )
+ // A phone has no room beside the menu, so a submenu replaces it as a page of its own.
+ ? (open || pageSlide) && menu.layerHost && createPortal((
+ <SubmenuPage rowId={id} level={level + 1} title={title} slide={pageSlide} onSlideEnd={settlePage}>
+ <MenuFilterContext.Provider value={filter}>{children}</MenuFilterContext.Provider>
+ </SubmenuPage>
+ ), menu.layerHost)
: open && openSubmenu && menu.layerHost && createPortal((
<SubmenuLayer level={level + 1} submenu={openSubmenu} pinned={!!filter?.text}>
<MenuFilterContext.Provider value={filter}>{children}</MenuFilterContext.Provider>
@@ -563,9 +555,86 @@ function SubmenuLayer({ level, submenu, pinned, children }: {
);
}
-/** Whether an event on a submenu's row came from the rows its submenu unfolds inside it, on a phone. */
-function inUnfoldedRows(e: Event & { currentTarget: HTMLElement }) {
- return e.target instanceof Element && e.target.closest(".dropdown-menu") !== e.currentTarget.closest(".dropdown-menu");
+/**
+ * A submenu opened on a phone: a page that takes the menu's place, headed by the submenu's title and
+ * a way back. The level it covers stays mounted, as the row that owns this page stands in it.
+ */
+function SubmenuPage({ rowId, level, title, slide, onSlideEnd, children }: {
+ rowId: string,
+ level: number,
+ title: ComponentChildren,
+ slide: PageSlide | undefined,
+ onSlideEnd(): void,
+ children: ComponentChildren
+}) {
+ const menu = useMenu();
+ const pageRef = useRef<HTMLDivElement>(null);
+
+ // Without an animation to wait for, as with `motion-disabled`, the slide ends at once.
+ useLayoutEffect(() => {
+ const page = pageRef.current;
+ if (slide && page && !hasAnimation(page)) onSlideEnd();
+ }, [ slide, onSlideEnd ]);
+
+ function back() {
+ menu.openSubmenu(level - 1);
+ menu.setActive(level - 1, rowId);
+ }
+
+ return (
+ <MenuLevelContext.Provider value={level}>
+ <div
+ ref={pageRef} role="menu" aria-labelledby={titleId(rowId)}
+ className={clsx("tn-menu-page", slide && `tn-menu-page-${slide}`)}
+ onAnimationEnd={(e) => {
+ // Animations inside the page bubble up here too.
+ if (e.target === e.currentTarget) onSlideEnd();
+ }}
+ >
+ {/* As a row's press: the menu keeps focus, and the dropdown does not close on it. */}
+ <div
+ className="tn-menu-page-header"
+ onMouseDown={(e) => e.preventDefault()}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <MasterDetailHeader inPage onBack={back} backTitle={t("menu.back")} pageTitle={title} listTitle={title} />
+ </div>
+ <menu className="tn-menu-scroll" role="none">{children}</menu>
+ </div>
+ </MenuLevelContext.Provider>
+ );
+}
+
+/** How a phone's submenu page is moving: sliding in over its menu, or back out. */
+type PageSlide = "entering" | "leaving";
+
+/**
+ * The slide of a phone's submenu page that `open` shows or hides. A page that closes keeps being
+ * drawn until it has slid out, which the page reports with the returned callback.
+ */
+function usePageSlide(open: boolean) {
+ const slide = useRef<PageSlide | undefined>(undefined);
+ const wasOpen = useRef(open);
+ const [ , redraw ] = useState(0);
+
+ // Worked out while rendering, so the first frame of the page already carries its slide.
+ if (wasOpen.current !== open) {
+ wasOpen.current = open;
+ slide.current = open ? "entering" : "leaving";
+ }
+
+ const settle = useCallback(() => {
+ if (!slide.current) return;
+ slide.current = undefined;
+ redraw((pass) => pass + 1);
+ }, []);
+
+ return [ slide.current, settle ] as const;
+}
+
+function hasAnimation(element: HTMLElement) {
+ const name = getComputedStyle(element).animationName;
+ return !!name && name !== "none";
}
/** The id of a row's title, which names the submenu it opens. */
diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.css
index 2166d272fb..13dd17d6ea 100644
--- a/apps/client/src/widgets/react/Menu.css
+++ b/apps/client/src/widgets/react/Menu.css
@@ -51,6 +51,86 @@ body.desktop .dropdown-submenu > .dropdown-menu.tn-menu.tn-menu-immediate {
animation: none;
}
+/*
+ * On a phone, a submenu is a page that takes its menu's place (`SubmenuPage`), and the frame
+ * follows the height of the page on show. The level under a page keeps its rows and its scroll
+ * position, hidden out of the flow. The slides are master_detail.css's.
+ */
+.tn-menu-page {
+ --tn-popup-padding: var(--padding, var(--menu-padding-size));
+ display: flex;
+ flex-direction: column;
+ flex: 1 1 auto;
+ min-height: 0;
+ /* Spans the frame's padding as the top level's `.tn-menu-scroll` does (Popup.css), so every
+ level has the same box in the flow and out of it. */
+ margin: calc(0px - var(--tn-popup-padding));
+ border-radius: inherit;
+
+ > .tn-menu-scroll {
+ margin: 0;
+ }
+}
+
+.tn-menu-page-header {
+ padding: var(--tn-popup-padding) var(--tn-popup-padding) 0;
+}
+
+/* A sliding level stands a full width to the side, which the frame would scroll to. */
+.dropdown-menu.tn-menu:has(> .tn-menu-page) {
+ overflow-x: hidden;
+}
+
+.dropdown-menu.tn-menu > :is(.tn-menu-scroll, .tn-menu-page) {
+ &:has(+ .tn-menu-page:not(.tn-menu-page-leaving)) {
+ position: absolute;
+ inset: 0;
+ margin: 0;
+ visibility: hidden;
+ }
+
+ &:has(+ .tn-menu-page-entering) {
+ visibility: visible;
+ animation: tn-master-detail-out-start 0.35s ease-in-out forwards;
+ }
+
+ &:has(+ .tn-menu-page-leaving) {
+ animation: tn-master-detail-in-start 0.35s ease-in-out forwards;
+ }
+}
+
+.dropdown-menu.tn-menu > .tn-menu-page-entering {
+ position: relative;
+ z-index: 1;
+ animation: tn-master-detail-in-end 0.35s ease-in-out forwards;
+}
+
+.dropdown-menu.tn-menu > .tn-menu-page-leaving {
+ position: absolute;
+ inset: 0;
+ margin: 0;
+ z-index: 1;
+ animation: tn-master-detail-out-end 0.35s ease-in-out forwards;
+}
+
+body[dir="rtl"] .dropdown-menu.tn-menu {
+ > :is(.tn-menu-scroll, .tn-menu-page):has(+ .tn-menu-page-entering) {
+ animation-name: tn-master-detail-out-end;
+ }
+
+ > :is(.tn-menu-scroll, .tn-menu-page):has(+ .tn-menu-page-leaving) {
+ animation-name: tn-master-detail-in-end;
+ }
+
+ > .tn-menu-page-entering {
+ animation-name: tn-master-detail-in-start;
+ }
+
+ > .tn-menu-page-leaving {
+ animation-name: tn-master-detail-out-start;
+ }
+}
+
/* A menu in the flow of what holds it, as a list is, rather than beside an anchor. */
.dropdown-menu.tn-menu.tn-menu-inline {
position: static;
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index 01c04ebe90..f9f15b294e 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -6,6 +6,7 @@ import { useCallback, useContext, useLayoutEffect, useRef, useState } from "prea
import type { MenuCommandItem, MenuItem } from "../../menus/context_menu";
import { t } from "../../services/i18n";
+import { isMobile } from "../../services/utils";
import { FormDropdownDivider, FormDropdownSubmenu, FormListCustomItem, FormListHeader, FormListItem } from "./FormList";
import FormTextBox from "./FormTextBox";
import { type ActiveRow, isRightToLeft, MenuContext, type MenuContextValue, type MenuFilter, MenuFilterContext, type OpenSubmenu, pointerMoved, type RowEntry, shouldDropStart, useMenu } from "./menu_context";
@@ -238,7 +239,8 @@ export default function Menu<T>({ id, className, anchor, placement, bottomSheet,
function onKeyDown(e: KeyboardEvent) {
// From a filter input, the keys act on the rows of the submenu it filters.
const filterInput = e.target instanceof HTMLInputElement && e.target.matches(FILTER_INPUT) ? e.target : undefined;
- const level = filterInput ? Number(filterInput.dataset.level) : active?.level ?? 0;
+ // On a phone, the deepest open submenu is the page on show, even before a row in it is active.
+ const level = filterInput ? Number(filterInput.dataset.level) : isMobile() ? open.length : active?.level ?? 0;
const levelRows = navigableRows(level);
const activeHere = active?.level === level ? active : undefined;
const index = activeHere ? levelRows.indexOf(activeHere.id) : -1;