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
refactor(dropdown): drop `portalToBody`, as every popup is portaled
Elian Doran0e727787bd1e
diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 8208fc0510..73318035b2 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -462,7 +462,7 @@ button kbd {display: contents;}-/* A portaled menu (the Dropdown's `portalToBody`) stacks in the root context, so it has to clear a+/* A dropdown's popup, portaled to the body, stacks in the root context, so it has to clear amodal (1055) and a stacked quick-edit popup (1100), and stay under the prompts (2000) it cansummon. */body > .tn-dropdown-portal > .dropdown-menu {diff --git a/apps/client/src/widgets/EmbeddedNotePane.tsx b/apps/client/src/widgets/EmbeddedNotePane.tsxindex 2c779d31a1..86c17aaf93 100644--- a/apps/client/src/widgets/EmbeddedNotePane.tsx+++ b/apps/client/src/widgets/EmbeddedNotePane.tsx@@ -228,9 +228,6 @@ export function OpenNoteActions({ note }: { note: FNote }) {title={t("embedded_note.more-ways-to-open")}iconActionhideToggleArrow- // The panel clips what overflows it, so a menu nested in the row would be cut off at- // its edge; and a panel's backdrop filter would flatten the menu's own.- portalToBodydisabled={!notePath}>{OTHER_WAYS_TO_OPEN.map(({ command, icon, title }) => (@@ -341,7 +338,6 @@ export function NoteColorAction({ note, title }: { note: FNote; title: string })iconActionhideToggleArrownoDropdownListStyle- portalToBody><NoteColorPicker note={note} /></DropdownPanel>diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.css b/apps/client/src/widgets/attribute_widgets/attribute_detail.cssindex 352742fe06..77fc60a23d 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.css+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.css@@ -20,7 +20,7 @@contain: none;}-/* The type menu is portaled to `document.body` (see the Dropdown's `portalToBody`): the popup is a+/* The type menu is portaled to `document.body`, as every dropdown's is: the popup is ascroll container (`overflow: auto` above), so an inline menu could only open by scrolling the formunder itself. In body it competes with the popup in the root stacking context, where the globaldropdown z-index (999) loses to the popup's 1060 — raise it above the popup, staying below thediff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsxindex 728e38ea21..88f76517e1 100644--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx@@ -255,7 +255,7 @@ export function AttributeDetail({ opts, currentNoteId, onDismiss, onCancel, ...f// Modals count as belonging to the popup: creating a note straight from the target// note field opens the note type chooser, and dismissing on its clicks would tear// the popup down before the created note could be filled in. The type menu belongs- // to it too: it is portaled to the body (see the dropdown's `portalToBody`), so a+ // to it too: it is portaled to the body, as every dropdown is, so a// press on one of its items lands outside the popup element.|| e.target.closest(`${AUTOCOMPLETE_DROPDOWN_SELECTOR}, .algolia-autocomplete, #context-menu-container, .modal, .modal-backdrop, .attr-input-label-type`)) {return;@@ -597,9 +597,6 @@ export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId,<OptionsRow name="attr-label-type" label={t("attribute_detail.label_type")}><FormDropdownListclassName="attr-input-label-type"- // The popup is a scroll container, so an inline menu could only grow by- // scrolling the form under itself — and the type list only gets longer.- portalToBodyvalues={DEFINITION_TYPES}keyProperty="value"titleProperty="title"diff --git a/apps/client/src/widgets/collections/SortDropdown.tsx b/apps/client/src/widgets/collections/SortDropdown.tsxindex 063f86f0c3..b3aff5ff31 100644--- a/apps/client/src/widgets/collections/SortDropdown.tsx+++ b/apps/client/src/widgets/collections/SortDropdown.tsx@@ -27,9 +27,6 @@ export default function SortDropdown({{sortMenuTitle({ orderBy, attributes, noneTitle, defaultTitle })}</>}mobileBottomSheet- // The card the dropdown stands in is a backdrop root, which would otherwise flatten the- // menu's blur into a tint.- portalToBody>{orders.map(renderEntry)}<FormDropdownDivider />diff --git a/apps/client/src/widgets/collections/board/card_template_pill.tsx b/apps/client/src/widgets/collections/board/card_template_pill.tsxindex 6e20beab46..ae07a7f84b 100644--- a/apps/client/src/widgets/collections/board/card_template_pill.tsx+++ b/apps/client/src/widgets/collections/board/card_template_pill.tsx@@ -54,7 +54,6 @@ export default function CardTemplatePill({ offered, current, onSelect, onMore, otext={<span className="card-template-name">{current?.title ?? ""}</span>}title={t("board_view.card-template")}noSelectButtonStyle- portalToBodyonShown={() => {setIsShown(true);onOpened?.();diff --git a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.cssindex 056a62d422..69d46b8ea6 100644--- a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css+++ b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.css@@ -1,4 +1,4 @@-/* Carried by the in-place wrapper and by the portaled one alike (see portalToBody in Dropdown.tsx),+/* Carried by the toggle's wrapper and by the popup's portal alike (see `portalClassName` in Dropdown.tsx),so the button is styled here and the menu there under the one class. */.calendar-recurrence-dropdown {flex: 1;diff --git a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsxindex dd4429c871..ecade638c0 100644--- a/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx+++ b/apps/client/src/widgets/collections/calendar/RecurrenceEditor.tsx@@ -63,7 +63,6 @@ export default function RecurrenceEditor({ note }: { note: FNote }) {className="calendar-recurrence-dropdown"text={modelTitle(model)}noDropdownListStyle- portalToBodydropdownOptions={{ autoClose: "outside" }}><EventFieldList>diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsxindex 2598cf0614..3d8793945d 100644--- a/apps/client/src/widgets/react/Dropdown.tsx+++ b/apps/client/src/widgets/react/Dropdown.tsx@@ -43,35 +43,14 @@ export interface DropdownProps extends Pick<HTMLProps<HTMLDivElement>, "id" | "ctitleOptions?: Partial<Tooltip.Options>;mobileBackdrop?: boolean;/**- * Render the dropdown menu into `document.body` instead of nesting it next to the toggle.- *- * Use this when an ancestor establishes a containment/backdrop root (e.g. `container-type`,- * `transform`, `filter`) which would otherwise flatten the menu's `backdrop-filter` blur into a- * flat tint. The menu is wrapped in a `<div class="tn-dropdown-portal {className}">` so any CSS- * scoped under that class keeps applying even though the menu no longer lives inside the- * toggle's wrapper, and so the menu outranks whatever stacking context it was lifted out of.- */- portalToBody?: boolean;- /**- * On a phone, show the menu as a sheet rising from the bottom of the screen over a dimmed page,- * the way the app's other mobile menus appear. No effect on a desktop layout.- *- * Prefer this to setting the pieces by hand. A menu left to place itself on mobile lands as a- * narrow box adrift in the middle of the page — Popper computes an offset that the app's own- * `body.mobile .dropdown-menu { position: fixed }` then measures from somewhere else — and one- * opened inside a dialog needs {@link portalToBody} besides, since a transformed `.modal-dialog`- * is both the box a fixed menu is placed against and a stacking context the backdrop, painting- * above the whole modal, would otherwise dim the menu through.+ * On a phone, shows the popup as a sheet rising from the bottom of the screen over a dimmed+ * page, the way the app's other mobile menus appear. No effect on a desktop layout.*/mobileBottomSheet?: boolean;/**- * Dim the page behind the menu on any screen, for a menu that is a task of its own rather than+ * Dims the page behind the popup on any screen, for one that is a task of its own rather than* a list of actions: the icon picker, which holds a search field and a grid of a thousand- * icons.- *- * Drawn inside the same portal as the menu, immediately before it, so what covers what is a- * matter of document order and one z-index rather than of two scales meeting. Needs- * {@link portalToBody} for that, and does nothing without it.+ * icons. Drawn in the popup's portal, immediately before it.*/backdrop?: boolean;}diff --git a/apps/client/src/widgets/react/HelpDropdown.tsx b/apps/client/src/widgets/react/HelpDropdown.tsxindex 16be85715c..6ae325bcea 100644--- a/apps/client/src/widgets/react/HelpDropdown.tsx+++ b/apps/client/src/widgets/react/HelpDropdown.tsx@@ -42,10 +42,6 @@ export default function HelpDropdown({ children, helpPage, openInPopup, classNamhideToggleArrownoSelectButtonStylenoDropdownListStyle- // Hosts like the ribbon establish their own stacking context (`.ribbon-container` sits at- // z-index 998), which would clamp the popup below the body-level widgets it overlaps —- // e.g. the attribute detail at 1000. Rendering into the body lets its z-index actually apply.- portalToBody>{children}diff --git a/apps/client/src/widgets/react/IconPicker.spec.tsx b/apps/client/src/widgets/react/IconPicker.spec.tsxindex 6d8a23f938..4ee9603eb9 100644--- a/apps/client/src/widgets/react/IconPicker.spec.tsx+++ b/apps/client/src/widgets/react/IconPicker.spec.tsx@@ -39,7 +39,7 @@ describe("IconPickerButton", () => {const desktop = renderButton(false);// The button stands where it was put; what it opens is a menu, which is neither built nor- // handed to the page until it is opened (see `portalToBody`).+ // handed to the page until it is opened.expect(desktop.querySelector(".note-icon-widget button.note-icon")).toBeTruthy();expect(document.body.querySelector(".modal.icon-switcher")).toBeNull();expect(document.body.querySelector(".dropdown-menu")).toBeNull();diff --git a/apps/client/src/widgets/react/IconPicker.tsx b/apps/client/src/widgets/react/IconPicker.tsxindex 4d1f655564..f0461f2019 100644--- a/apps/client/src/widgets/react/IconPicker.tsx+++ b/apps/client/src/widgets/react/IconPicker.tsx@@ -192,10 +192,6 @@ function IconPickerDropdownButton({]})}}- // The menu is wider than some of the places a button stands in, and the inline title- // establishes a backdrop root that would flatten its blur into a tint; hand the menu to- // the page rather than leaving it to be clipped or dulled.- portalToBodybackdrop={backdrop}hideToggleArrowonShown={() => {diff --git a/apps/client/src/widgets/sidebar/HighlightsList.tsx b/apps/client/src/widgets/sidebar/HighlightsList.tsxindex a7a79aa74b..63be3a5f8a 100644--- a/apps/client/src/widgets/sidebar/HighlightsList.tsx+++ b/apps/client/src/widgets/sidebar/HighlightsList.tsx@@ -116,9 +116,6 @@ function HighlightsListMenu({ currentValue, onChange }: {iconActionhideToggleArrownoSelectButtonStyle- // The card establishes a stacking context of its own and clips its overflow, so the menu- // is rendered into the body to stand clear of it — as the card's help popup is.- portalToBody>{HIGHLIGHT_FORMATS.map(({ val, titleKey, icon }) => (<FormListToggleableItemdiff --git a/apps/client/src/widgets/sidebar/SidebarChat.tsx b/apps/client/src/widgets/sidebar/SidebarChat.tsxindex 5a64ddc7bb..659904b395 100644--- a/apps/client/src/widgets/sidebar/SidebarChat.tsx+++ b/apps/client/src/widgets/sidebar/SidebarChat.tsx@@ -317,9 +317,6 @@ export default function SidebarChat() {hideToggleArrowdropdownContainerClassName="tn-dropdown-menu-scrollable"dropdownOptions={{ popperConfig: { strategy: "fixed" } }}- // In peek mode #right-pane has a backdrop-filter, which becomes the containing- // block for the fixed-positioned menu and offsets it — portal to body to escape it.- portalToBodydropdownRef={historyDropdownRef}onShown={loadRecentChats}>@@ -370,9 +367,6 @@ export default function SidebarChat() {iconActionhideToggleArrowdropdownOptions={{ popperConfig: { strategy: "fixed" } }}- // See the history dropdown above: portal to body so peek mode's backdrop-filter- // containing block doesn't offset the fixed menu.- portalToBody><FormListItemicon="bx bx-save"diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsxindex 6da175fdfd..065524d753 100644--- a/apps/client/src/widgets/type_widgets/Attachment.tsx+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx@@ -431,10 +431,6 @@ function AttachmentActions({ attachment, copyAttachmentReferenceToClipboard, onSiconActiondropdownContainerClassName="mobile-bottom-menu"mobileBackdrop- // The card clips its overflow, to keep a picture inside its rounded corners, and a menu- // opening from the header is taller than the header has room for — so it is rendered- // into the body to stand clear of the card, as the highlights card's menu is.- portalToBody><FormListItemicon="bx bx-file-find"diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.cssindex bed67138ac..258df69460 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css@@ -296,7 +296,7 @@}/* Scoped to the dropdown wrapper (not `.llm-chat-model-selector`) so these menu styles- survive `portalToBody`, which reparents the menu to <body> under this same class. */+ reach the menu, which is portaled to <body> under this same class. */.llm-chat-model-dropdown small {margin-left: 0.5em;color: var(--muted-text-color);diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsxindex b7242f7a6a..d9367fd243 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx@@ -436,11 +436,6 @@ export default function ChatInputBar({titlePosition="top"buttonClassName="llm-chat-model-select"className="llm-chat-model-dropdown"- // In the sidebar the menu lives inside `.sidebar-chat-container`'s- // `overflow: hidden`, which clips the leftward-opening legacy submenu.- // Portal it to the body (with a fixed popper) so it can extend past the- // sidebar edge, matching the sidebar's other dropdowns.- portalToBody={inSidebar}dropdownOptions={inSidebar ? { popperConfig: { strategy: "fixed" } } : undefined}>{chat.modelGroups.map(group => (diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.spec.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.spec.tsxindex 5cadab1d86..be568187a0 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.spec.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.spec.tsx@@ -10,11 +10,11 @@ vi.mock("../../../services/i18n.js", () => ({// Renders the toggle's face, its tooltip and class, and the menu, without Bootstrap;// the placement options go on data attributes.vi.mock("../../react/Dropdown.js", () => ({- default: ({ text, title, buttonClassName, children, portalToBody, dropdownOptions }: {+ default: ({ text, title, buttonClassName, children, dropdownOptions }: {text: ComponentChildren; title?: string; buttonClassName?: string; children: ComponentChildren;- portalToBody?: boolean; dropdownOptions?: { popperConfig?: { strategy?: string } };+ dropdownOptions?: { popperConfig?: { strategy?: string } };}) => (- <div className="dropdown-stub" data-portal={String(!!portalToBody)} data-strategy={dropdownOptions?.popperConfig?.strategy ?? "none"}>+ <div className="dropdown-stub" data-strategy={dropdownOptions?.popperConfig?.strategy ?? "none"}><button className={buttonClassName} title={title}>{text}</button><div className="menu">{children}</div></div>@@ -56,15 +56,15 @@ describe("effectiveReasoningEffort", () => {});describe("ReasoningEffortDropdown placement", () => {- it("portals the menu with a fixed position in the sidebar", () => {+ it("fixes the menu's position in the sidebar", () => {const stub = renderDropdown(FLASH, undefined, vi.fn(), true).host.querySelector(".dropdown-stub");- expect([ stub?.getAttribute("data-portal"), stub?.getAttribute("data-strategy") ]).toEqual([ "true", "fixed" ]);+ expect(stub?.getAttribute("data-strategy")).toBe("fixed");});- it("keeps the menu in place elsewhere, and lists nothing for a model without levels", () => {+ it("leaves the position alone elsewhere, and lists nothing for a model without levels", () => {const { host: plain } = renderDropdown({ id: "m", name: "M" }, undefined);const stub = plain.querySelector(".dropdown-stub");- expect([ stub?.getAttribute("data-portal"), stub?.getAttribute("data-strategy") ]).toEqual([ "false", "none" ]);+ expect(stub?.getAttribute("data-strategy")).toBe("none");expect(plain.querySelectorAll(".menu .dropdown-item")).toHaveLength(0);});});diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.tsxindex 382b0ddc4b..5d6dfbcb6d 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ReasoningEffortDropdown.tsx@@ -34,8 +34,6 @@ export default function ReasoningEffortDropdown({ model, value, onChange, disablbuttonClassName="llm-chat-model-select"className="llm-chat-reasoning-effort"disabled={disabled}- // Same reason as the model selector: the sidebar clips an unportaled menu.- portalToBody={inSidebar}dropdownOptions={inSidebar ? { popperConfig: { strategy: "fixed" } } : undefined}>{(model.reasoningEfforts ?? []).map(level => (diff --git a/apps/client/src/widgets/type_widgets/options/active_content.tsx b/apps/client/src/widgets/type_widgets/options/active_content.tsxindex 0d3d98be09..efccd685b3 100644--- a/apps/client/src/widgets/type_widgets/options/active_content.tsx+++ b/apps/client/src/widgets/type_widgets/options/active_content.tsx@@ -49,9 +49,6 @@ function ContentItemMenu({ note, categories }: { note: FNote, categories: ContenclassName="active-content-item-menu"buttonClassName="note-book-item-menu bx bx-dots-vertical-rounded"hideToggleArrow noSelectButtonStyle iconAction- // Out of the row and into the body: nested, the open menu would still count as hovering- // the row, leaving it highlighted while the cursor is over the menu.- portalToBody// Asked for as a sheet rather than dressed as one: the prop brings the cover over the// rest of the screen with it, which the class alone does not.mobileBottomSheetdiff --git a/apps/client/src/widgets/type_widgets/options/appearance.tsx b/apps/client/src/widgets/type_widgets/options/appearance.tsxindex 4a777e9e5c..79f1f43d6f 100644--- a/apps/client/src/widgets/type_widgets/options/appearance.tsx+++ b/apps/client/src/widgets/type_widgets/options/appearance.tsx@@ -134,9 +134,6 @@ function UserInterface() {{currentFamilyLabel}</>}mobileBottomSheet- // The card is a container, and so a backdrop root: left inside it the menu- // loses its blur and reads as a flat tint.- portalToBody>{THEME_FAMILIES.map(family => (<FormListItemdiff --git a/apps/client/src/widgets/type_widgets/options/components/LocaleSelector.tsx b/apps/client/src/widgets/type_widgets/options/components/LocaleSelector.tsxindex 9ee67a5689..79270457c3 100644--- a/apps/client/src/widgets/type_widgets/options/components/LocaleSelector.tsx+++ b/apps/client/src/widgets/type_widgets/options/components/LocaleSelector.tsx@@ -15,11 +15,6 @@ export function LocaleSelector({ id, locales, currentValue, onChange, defaultLoc}) {const currentValueWithDefault = currentValue ?? defaultLocale?.id ?? "";const { activeLocale, processedLocales } = useProcessedLocales(locales, defaultLocale, currentValueWithDefault);- // Deliberately not `portalToBody`, unlike the shorter menus on the other options pages. The card- // around it is a container and so a backdrop root, which leaves this menu a flat tint rather than- // frosted. That is the lesser cost: the list runs to every locale Trilium speaks and nothing caps- // a menu's height, so carried out to the body it would stand in a page that does not scroll, and- // every locale past the fold would be out of reach.return (<Dropdown id={id} text={activeLocale?.name} mobileBottomSheet>{processedLocales.map((locale, index) => (diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsxindex 18f6cd5de5..a4c464adce 100644--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx@@ -139,9 +139,6 @@ export default function ShortcutSettings() {title={t("shortcuts.filter")}dropdownRef={filterDropdownRef}mobileBottomSheet- // The row is a container, and so a backdrop root: left inside it the- // menu loses its blur and reads as a flat tint.- portalToBody><FilterContentactiveFilter={activeFilter}diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsxindex 841154005c..9d3ea91777 100644--- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx+++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx@@ -476,9 +476,6 @@ function HeadingStyleSelector({ currentValue, onChange }: { currentValue: stringreturn (<Dropdowntext={t(currentStyle.labelKey)} mobileBottomSheet- // The options card is a container, and so a backdrop root: left inside it the menu- // loses its blur and reads as a flat tint.- portalToBody>{HEADING_STYLES.map(({ value, labelKey }) => (<FormListItem