Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(menu): set a split row's arrow apart with a divider
Elian Doran7e4cf4771430
diff --git a/apps/client/src/menus/context_menu.spec.ts b/apps/client/src/menus/context_menu.spec.tsindex 5ba3f2f87c..74ea64a46c 100644--- a/apps/client/src/menus/context_menu.spec.ts+++ b/apps/client/src/menus/context_menu.spec.ts@@ -652,8 +652,11 @@ describe("contextMenu", () => {expect(picked).toEqual([ "Templates", "Meeting", "Weekly" ]);expect(contextMenu.isShown).toBe(false);- // A row with a command of its own runs it and closes the menu, like any other.+ // A row with a command of its own is split, unlike a row that only opens its submenu,+ // and runs the command and closes the menu like any other.const again = await openMenu((title) => picked.push(title));+ expect(row("Templates").classList.contains("tn-menu-split")).toBe(false);+ expect(row("Insert child note").classList.contains("tn-menu-split")).toBe(true);press(row("Insert child note"));expect(picked.at(-1)).toBe("Insert child note");expect(again.isShown).toBe(false);diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsxindex 312a98981c..cd40b5e110 100644--- a/apps/client/src/widgets/react/FormList.tsx+++ b/apps/client/src/widgets/react/FormList.tsx@@ -388,6 +388,12 @@ export interface FormDropdownSubmenuProps {children: ComponentChildren;/** Called when the row is clicked, or run from the keyboard, on the desktop. */onDropdownToggleClicked?: (e: MouseEvent) => void;+ /**+ * Whether the row runs an action of its own besides opening the submenu. A split row draws a+ * divider before its arrow, and a click on the arrow only opens the submenu. Defaults to+ * whether {@link onDropdownToggleClicked} is set.+ */+ split?: boolean;disabled?: boolean;className?: string;/** Inside a menu, whether typing while the submenu is open filters it. See `MenuCommandItem.filterable`. */@@ -405,7 +411,7 @@ export function FormDropdownSubmenu(props: FormDropdownSubmenuProps) {return <MenuSubmenu {...props} menu={menu} />;}-function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleClicked, disabled, className, filterable }: FormDropdownSubmenuProps & { menu: MenuContextValue }) {+function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleClicked, split = !!onDropdownToggleClicked, disabled, className, filterable }: FormDropdownSubmenuProps & { menu: MenuContextValue }) {const level = useContext(MenuLevelContext);const id = useUniqueName("menu-row");const openSubmenu = menu.open[level];@@ -434,7 +440,7 @@ function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleClimenu.registerRow(id, element ? { level, element, custom: false, disabled: !!disabled, hasSubmenu: true, filterable, select } : undefined);}}className={clsx("dropdown-item dropdown-submenu", open && "submenu-open", isActive && "tn-menu-active",- disabled && "disabled", className)}+ split && !isMobile() && "tn-menu-split", disabled && "disabled", className)}role="menuitem"aria-disabled={disabled || undefined}aria-haspopup="menu"@@ -466,6 +472,17 @@ function MenuSubmenu({ menu, icon, iconSvg, title, children, onDropdownToggleCli<span className="tn-menu-gap" /><span id={titleId(id)}>{title}</span></span>+ {split && !isMobile() && (+ <span+ className="tn-menu-split-toggle"+ aria-hidden="true"+ onClick={(e) => {+ e.stopPropagation();+ const row = e.currentTarget.parentElement;+ if (!disabled && row) menu.openSubmenu(level, id, row, true);+ }}+ />+ )}{isMobile()// A phone has no room beside the menu, so a submenu replaces it as a page of its own.? (open || pageSlide.from !== undefined) && menu.layerHost && createPortal((diff --git a/apps/client/src/widgets/react/Menu.css b/apps/client/src/widgets/react/Menu.cssindex e74ddc505b..62a104b6cf 100644--- a/apps/client/src/widgets/react/Menu.css+++ b/apps/client/src/widgets/react/Menu.css@@ -138,6 +138,37 @@ body[dir="rtl"] .dropdown-menu.tn-menu {min-width: unset;}+body.desktop .dropdown-item.dropdown-submenu.tn-menu-split {+ /* The box of the arrow `.dropdown-toggle::after` draws in theme-next/base.css. */+ --tn-menu-split-toggle-width: calc(1.2em + 8px);+ --menu-item-end-padding: calc(var(--tn-menu-split-toggle-width) + 10px);++ .tn-menu-split-toggle {+ position: absolute;+ inset-block: 0;+ inset-inline-end: 0;+ width: var(--tn-menu-split-toggle-width);+ border-start-end-radius: inherit;+ border-end-end-radius: inherit;++ &::before {+ content: "";+ position: absolute;+ inset-block: 5px;+ inset-inline-start: 0;+ border-inline-start: 1px solid var(--menu-item-delimiter-color);+ }++ &:hover {+ background-color: color-mix(in srgb, currentColor 8%, transparent);+ }+ }++ &.disabled .tn-menu-split-toggle:hover {+ background-color: transparent;+ }+}+/* The menu holds focus for its keys; the row they act on shows where they are instead. */.dropdown-menu.tn-menu:focus {outline: none;diff --git a/apps/client/src/widgets/react/Menu.spec.tsx b/apps/client/src/widgets/react/Menu.spec.tsxindex ce5f206d39..54ce8d3c62 100644--- a/apps/client/src/widgets/react/Menu.spec.tsx+++ b/apps/client/src/widgets/react/Menu.spec.tsx@@ -175,6 +175,35 @@ describe("Menu with declared rows", () => {expect(activeTitle(unwanted)).toBeUndefined();});+ it("splits a submenu row that runs an action of its own: the row runs it, its arrow only opens", async () => {+ const toggled = vi.fn();+ render((+ <Menu anchor={{ x: 10, y: 10 }} onClose={vi.fn()}>+ <FormDropdownSubmenu title="Duplicate" icon="bx bx-outline" onDropdownToggleClicked={toggled}>+ <FormListItem>This note only</FormListItem>+ </FormDropdownSubmenu>+ <FormDropdownSubmenu title="Advanced" icon="bx bx-chip">+ <FormListItem>Reload</FormListItem>+ </FormDropdownSubmenu>+ </Menu>+ ), host);+ const menu = document.querySelector<HTMLElement>(".tn-popup.tn-menu");+ if (!menu) throw new Error("expected the menu to render");++ expect(rowTitled("Advanced").querySelector(".tn-menu-split-toggle")).toBeNull();+ const duplicateRow = rowTitled("Duplicate");+ expect(duplicateRow.classList.contains("tn-menu-split")).toBe(true);+ const arrow = duplicateRow.querySelector<HTMLElement>(".tn-menu-split-toggle");+ if (!arrow) throw new Error("expected the split row to draw its arrow as a target");++ press(arrow);+ await vi.waitFor(() => expect(layers(menu)).toEqual([ [ "This note only" ] ]));+ expect(toggled).not.toHaveBeenCalled();++ press(duplicateRow);+ expect(toggled).toHaveBeenCalledOnce();+ });+it("neither opens nor runs a disabled submenu row", async () => {const toggled = vi.fn();render((diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsxindex baccb2bd2a..f1641d0a0c 100644--- a/apps/client/src/widgets/react/Menu.tsx+++ b/apps/client/src/widgets/react/Menu.tsx@@ -524,7 +524,8 @@ function MenuItemRow<T>({ row, onSelect }: { row: MenuItem<T>, onSelect: MenuProreturn (<FormDropdownSubmenuicon={uiIcon ?? "bx bx-empty"} title={label} disabled={enabled === false}- className={className} onDropdownToggleClicked={select} filterable={row.filterable}+ className={className} onDropdownToggleClicked={select} split={!!(row.command || row.handler)}+ filterable={row.filterable}><MenuItems items={items} onSelect={onSelect} /></FormDropdownSubmenu>diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.htmlindex 5f12e43b89..278a103fd7 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.html@@ -128,7 +128,8 @@<ul><li>Creates a copy of the note and its descendants, placed right after theoriginal.</li>- <li>When the note has child notes, hovering the item opens a submenu:+ <li>When the note has child notes, the item also has an arrow, set apart by+ a divider. Hovering the item or clicking the arrow opens a submenu:<ul><li><em>Note and its children</em> does the same as clicking <em>Duplicate</em>.</li><li><em>This note only</em> copies the note with its content and attributes,diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.md b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.mdindex e92f23363e..083e6b0a77 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/UI Elements/Note Tree/Note tree contextual menu.md@@ -53,7 +53,7 @@ The contextual menu can operate:* Will display a modal to specify where to [clone](../../Notes/Cloning%20Notes.md) the desired notes.* **Duplicate*** Creates a copy of the note and its descendants, placed right after the original.- * When the note has child notes, hovering the item opens a submenu:+ * When the note has child notes, the item also has an arrow, set apart by a divider. Hovering the item or clicking the arrow opens a submenu:* _Note and its children_ does the same as clicking _Duplicate_.* _This note only_ copies the note with its content and attributes, but without any of its child notes. Links and relations to the original children keep pointing at them.* This process is different from <a class="reference-link" href="../../Notes/Cloning%20Notes.md">Cloning Notes</a> since the duplicated note can be edited independently from the original.