Skip to content

Build your personal knowledge base with Trilium Notes

fix(menu): blur a context submenu on its ::before, like the top level

Elian Doranda4a6d9c99eb
diff --git a/apps/client/src/menus/context_menu.spec.ts b/apps/client/src/menus/context_menu.spec.ts
index 8959485a5b..f9f68f6ab9 100644
--- a/apps/client/src/menus/context_menu.spec.ts
+++ b/apps/client/src/menus/context_menu.spec.ts
@@ -359,7 +359,7 @@ describe("contextMenu", () => {
/** The submenu layers standing open, each as the titles of its rows. */
function layers() {
return [ ...menuElement()?.querySelectorAll(":scope > div.dropdown-submenu > ul.dropdown-menu") ?? [] ]
- .map((layer) => [ ...layer.querySelectorAll(":scope > li") ].map((item) => item.textContent));
+ .map((layer) => [ ...layer.querySelectorAll(":scope > .tn-menu-scroll > li") ].map((item) => item.textContent));
}
const hover = (element: HTMLElement) => element.dispatchEvent(new PointerEvent("pointerenter"));
@@ -405,6 +405,9 @@ describe("contextMenu", () => {
hover(row("Templates"));
await vi.waitFor(() => expect(layers()).toEqual([ [ "Meeting" ] ]));
expect(scroller?.querySelector("div.dropdown-submenu")).toBeNull();
+ // A layer scrolls its rows the same way, so its own blur stays behind them too.
+ const layer = menuElement()?.querySelector("div.dropdown-submenu > ul");
+ expect([ ...layer?.children ?? [] ].map((child) => child.className)).toEqual([ "tn-menu-scroll" ]);
});
it("places a layer beside its row, flipped where it does not fit, and hides it while its row is scrolled away", async () => {
@@ -473,7 +476,7 @@ describe("contextMenu", () => {
});
hover(row("Insert child note"));
- await vi.waitFor(() => expect(menuElement()?.querySelector("div.dropdown-submenu > ul > .tn-menu-columns")).not.toBeNull());
+ await vi.waitFor(() => expect(menuElement()?.querySelector("div.dropdown-submenu > ul > .tn-menu-scroll > .tn-menu-columns")).not.toBeNull());
const columns = menuElement()?.querySelector<HTMLElement>(".tn-menu-columns");
expect(columns?.style.columnCount).toBe("2");
expect(columns?.textContent).toBe("TextCode");
@@ -510,7 +513,7 @@ describe("contextMenu", () => {
// A single column has no breaks to avoid, so nothing is grouped.
hover(row("Insert note after"));
await vi.waitFor(() => expect(menuElement()?.querySelector(".tn-menu-columns")).toBeNull());
- expect(layout(menuElement()?.querySelector("div.dropdown-submenu > ul"))).toEqual([
+ expect(layout(menuElement()?.querySelector("div.dropdown-submenu > ul > .tn-menu-scroll"))).toEqual([
"Text", "Code", "---", "Templates", "Meeting", "Weekly"
]);
});
diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.css
index 739ca07c86..fe3fdaaa4c 100644
--- a/apps/client/src/widgets/react/Menu.css
+++ b/apps/client/src/widgets/react/Menu.css
@@ -31,14 +31,23 @@
overflow-y: auto;
}
-/*
- * A submenu is placed by `placeMenu()`, not beside a parent it is nested in. The theme blurs it on
- * the element itself rather than a `::before`, so it can scroll as a whole.
- */
+/* A submenu is placed by `placeMenu()`, not beside a parent it is nested in. */
.dropdown-submenu > .dropdown-menu.tn-menu {
inset: 0 auto auto 0;
margin: 0;
- overflow-y: auto;
+}
+
+/*
+ * The theme blurs a nested submenu on the element itself, which over a transparent window (background
+ * effects) composites with the menu's translucent background into a see-through layer with no blur.
+ * A layer is not nested in another menu, so it takes the top level's blur on `::before` instead.
+ */
+body.desktop .dropdown-submenu > .dropdown-menu.tn-menu {
+ backdrop-filter: none;
+
+ &::before {
+ content: "";
+ }
}
/* The menu holds focus for its keys; the row they act on shows where they are instead. */
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index f0f0905cd0..593865d7ab 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -140,7 +140,6 @@ export default function Menu<T>({ id, className, x, y, orientation, bottomSheet,
setActive(closing - 1, parent.item);
};
const rtl = handleRightToLeftPlacement("right") !== "right";
-
/** Moves to the row beside the active one in a menu laid out in columns, if there is one. */
const moveAcross = (towards: "left" | "right") => {
const boxes = levelRows.map((item) => rows.get(item)?.getBoundingClientRect());
@@ -269,15 +268,18 @@ function SubmenuLayer<T>({ level, submenu, state }: { level: number, submenu: Op
return (
<div className="dropdown-submenu">
<ul ref={layerRef} className="dropdown-menu show tn-menu" role="menu">
- {columns
- // The columns go on an inner element of their full height, so a capped menu
- // scrolls them rather than growing more columns to the side.
- ? (
- <div className="tn-menu-columns" style={{ columnCount: columns }}>
- <MenuList level={level} items={items} state={state} columns />
- </div>
- )
- : <MenuList level={level} items={items} state={state} />}
+ {/* Like the top level, so the blur on the layer's `::before` stays behind its rows. */}
+ <div className="tn-menu-scroll">
+ {columns
+ // The columns go on an inner element of their full height, so a capped menu
+ // scrolls them rather than growing more columns to the side.
+ ? (
+ <div className="tn-menu-columns" style={{ columnCount: columns }}>
+ <MenuList level={level} items={items} state={state} columns />
+ </div>
+ )
+ : <MenuList level={level} items={items} state={state} />}
+ </div>
</ul>
</div>
);