Skip to content

Build your personal knowledge base with Trilium Notes

refactor(menu): drop the submenu nested in its row, outside a `Menu`

Elian Doranb7080bca1c69
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.css
index aba00b6d5f..a99bc33882 100644
--- a/apps/client/src/stylesheets/style.css
+++ b/apps/client/src/stylesheets/style.css
@@ -1737,48 +1737,15 @@ body.mobile .dropdown-submenu > .dropdown-menu {
white-space: nowrap;
}
-body.desktop li.dropdown-submenu:hover > ul.dropdown-menu {
- display: block;
-}
-
.dropdown-submenu {
position: relative;
}
-.dropdown-submenu > .dropdown-menu {
- top: 0;
- inset-inline-start: calc(100% - 2px); /* -2px, otherwise there's a small gap between menu and submenu where the hover can disappear */
- margin-top: -10px;
-}
-
-/* to make submenu scrollable https://github.com/zadam/trilium/issues/3136 */
-.dropdown-submenu > .dropdown-menu:not(:has(.dropdown-submenu)) {
- max-height: 600px;
- overflow: auto;
-}
-
-/* Flipped upward (added by ContextMenu.repositionSubmenu) when the submenu would overflow the bottom of the viewport. */
-.dropdown-submenu > .dropdown-menu.submenu-flip-up {
- top: auto;
- bottom: 0;
- margin-top: 0;
- margin-bottom: -10px;
-}
-
body.desktop .dropdown-submenu > .dropdown-menu {
min-width: max-content;
max-width: 300px;
}
-/* Opened on the other side (`submenu-flip-start` added by ContextMenu.repositionSubmenu) when the
- submenu would overflow the side it opens on. */
-.dropdown-submenu.dropstart > .dropdown-menu,
-.dropdown-submenu > .dropdown-menu.submenu-flip-start,
-body:not(.mobile) #launcher-pane.horizontal .dropdown-submenu > .dropdown-menu {
- inset-inline-start: auto;
- inset-inline-end: calc(100% - 2px);
-}
-
.right-dropdown-widget {
flex-shrink: 0;
}
diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsx
index 806713ceb4..5500a1cdf7 100644
--- a/apps/client/src/widgets/react/Dropdown.tsx
+++ b/apps/client/src/widgets/react/Dropdown.tsx
@@ -120,8 +120,7 @@ export function DropdownPanel({ scrollable, ...props }: DropdownPanelProps) {
popup={({ popupProps, className, bottomSheet, startAt, dismiss }) => (
<PanelPopup
{...popupProps}
- // Otherwise it grows with its content, as Bootstrap's dropdowns did: a
- // `FormDropdownSubmenu` nested in it would be clipped by one that scrolls.
+ // Otherwise it grows with its content, as Bootstrap's dropdowns did.
capHeight={!!scrollable}
placedByStylesheet={bottomSheet}
className={clsx("dropdown-menu show", className, bottomSheet && "mobile-bottom-menu")}
diff --git a/apps/client/src/widgets/react/FormList.spec.tsx b/apps/client/src/widgets/react/FormList.spec.tsx
index ed0c76fda4..cd8a50fa87 100644
--- a/apps/client/src/widgets/react/FormList.spec.tsx
+++ b/apps/client/src/widgets/react/FormList.spec.tsx
@@ -8,7 +8,7 @@ vi.mock("bootstrap", () => ({
Tooltip: class { static getInstance() { return null; } }
}));
-import FormList, { FormDropdownDivider, FormListCustomItem, FormListHeader, FormListItem } from "./FormList";
+import FormList, { FormDropdownDivider, FormDropdownSubmenu, FormListCustomItem, FormListHeader, FormListItem } from "./FormList";
describe("FormDropdownDivider", () => {
it("draws a separator among the rows, whose click closes no menu", () => {
@@ -138,6 +138,20 @@ describe("FormListCustomItem", () => {
});
});
+describe("FormDropdownSubmenu", () => {
+ it("heads its rows with its title outside any menu, where there is no layer to open", () => {
+ const host = document.createElement("div");
+ render(<menu><FormDropdownSubmenu icon="bx bx-chip" title="Advanced">
+ <FormListItem>Reload</FormListItem>
+ </FormDropdownSubmenu></menu>, host);
+ const rows = [ ...host.querySelectorAll("menu > li") ];
+
+ expect(rows.map((row) => row.textContent)).toEqual([ "Advanced", "Reload" ]);
+ expect(rows[0]?.querySelector("h6.dropdown-header")).not.toBeNull();
+ expect(host.querySelector(".dropdown-submenu")).toBeNull();
+ });
+});
+
describe("FormList keyboard activation", () => {
it.each([ "Enter", " " ])("activates the focused item on %j like a click", (key) => {
const { container, onSelect } = renderList();
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsx
index c376f87193..685d429a9c 100644
--- a/apps/client/src/widgets/react/FormList.tsx
+++ b/apps/client/src/widgets/react/FormList.tsx
@@ -5,7 +5,7 @@ import type { KeyboardActionNames } from "@triliumnext/commons";
import { Dropdown as BootstrapDropdown, Tooltip } from "bootstrap";
import clsx from "clsx";
import { ComponentChildren, RefObject } from "preact";
-import { createPortal, type CSSProperties, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/compat";
+import { createPortal, type CSSProperties, useContext, useEffect, useLayoutEffect, useMemo, useRef } from "preact/compat";
import { getActionSync } from "../../services/keyboard_actions";
import { handleRightToLeftPlacement, isMobile, openInAppHelpFromUrl } from "../../services/utils";
@@ -365,13 +365,14 @@ export interface FormDropdownSubmenuProps {
}
/**
- * A row that opens its children as a submenu. Inside a `Menu` the submenu is a layer of its own
- * beside the row, which a scrolling menu neither clips nor scrolls away; elsewhere, as in a
- * dropdown, it is a list nested in the row, shown on hover.
+ * A row that opens its children as a submenu, in a layer of its own beside the row, which a
+ * scrolling menu neither clips nor scrolls away. Outside a `Menu`, which only a script can render,
+ * its title heads its children in the list.
*/
export function FormDropdownSubmenu(props: FormDropdownSubmenuProps) {
const menu = useContext(MenuContext);
- return menu ? <MenuSubmenu {...props} menu={menu} /> : <NestedSubmenu {...props} />;
+ if (!menu) return <><FormListHeader text={props.title} />{props.children}</>;
+ return <MenuSubmenu {...props} menu={menu} />;
}
function MenuSubmenu({ menu, icon, title, children, onDropdownToggleClicked, columns, disabled, className }: FormDropdownSubmenuProps & { menu: MenuContextValue }) {
@@ -455,36 +456,6 @@ function MenuSubmenu({ menu, icon, title, children, onDropdownToggleClicked, col
);
}
-function NestedSubmenu({ icon, title, children, dropStart, onDropdownToggleClicked, disabled, className }: FormDropdownSubmenuProps) {
- const [ openOnMobile, setOpenOnMobile ] = useState(false);
-
- return (
- <li className={clsx("dropdown-item dropdown-submenu", { "submenu-open": openOnMobile, "dropstart": dropStart },
- disabled && "disabled", className)}>
- <span
- className="dropdown-toggle"
- onClick={(e) => {
- e.stopPropagation();
-
- if (isMobile()) {
- setOpenOnMobile(!openOnMobile);
- } else if (onDropdownToggleClicked) {
- onDropdownToggleClicked(e);
- }
- }}
- >
- <Icon icon={icon} />
- <span className="tn-menu-gap" />
- {title}
- </span>
-
- <ul className={`dropdown-menu ${openOnMobile ? "show" : ""}`}>
- {children}
- </ul>
- </li>
- );
-}
-
/**
* A submenu opened on the desktop, placed beside the row it opened from rather than nested in it,
* so a scrolling menu neither clips it nor scrolls it away.
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css
index 258df69460..e6ed05df72 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css
+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css
@@ -307,12 +307,6 @@
overflow: auto;
}
-/* Position legacy models submenu to open upward */
-.llm-chat-model-dropdown .dropdown-submenu .dropdown-menu {
- bottom: 0;
- top: auto;
-}
-
/*
* The model picker stays the theme's own combo box (`.select-button.dropdown-toggle.btn`
* — its fill, its 6px radius, its caret, its focus outline), so it reads as the same