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
fix(client): restore dropdown backdrop blur for note icon picker
Elian Doran35e11be93da1
diff --git a/apps/client/src/widgets/note_icon.tsx b/apps/client/src/widgets/note_icon.tsxindex c6ed7e618b..f70b1b07fc 100644--- a/apps/client/src/widgets/note_icon.tsx+++ b/apps/client/src/widgets/note_icon.tsx@@ -56,6 +56,10 @@ export default function NoteIcon() {dropdownRef={dropdownRef}dropdownContainerStyle={{ width: "620px" }}dropdownOptions={{ autoClose: "outside" }}+ // The inline title sets `container-type: inline-size`, which makes it a backdrop root and+ // flattens the menu's blur into a flat tint. Portal the menu out of that subtree; it stays+ // wrapped in a `.note-icon-widget` div so the picker's scoped CSS keeps applying.+ portalToBodybuttonClassName={`note-icon tn-focusable-button ${icon ?? "bx bx-empty"}`}hideToggleArrowdisabled={isDisabled}diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsxindex f8f8775d13..94f87430cd 100644--- a/apps/client/src/widgets/react/Dropdown.tsx+++ b/apps/client/src/widgets/react/Dropdown.tsx@@ -1,6 +1,6 @@import { Dropdown as BootstrapDropdown, Tooltip } from "bootstrap";import { ComponentChildren, HTMLAttributes } from "preact";-import { CSSProperties, HTMLProps } from "preact/compat";+import { createPortal, CSSProperties, HTMLProps } from "preact/compat";import { MutableRef, useCallback, useEffect, useRef, useState } from "preact/hooks";import { isMobile } from "../../services/utils";@@ -34,9 +34,18 @@ export interface DropdownProps extends Pick<HTMLProps<HTMLDivElement>, "id" | "ctitlePosition?: "top" | "right" | "bottom" | "left";titleOptions?: 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={className}>` so any CSS scoped under that+ * class keeps applying even though the menu no longer lives inside the toggle's wrapper.+ */+ portalToBody?: boolean;}-export default function Dropdown({ id, className, buttonClassName, isStatic, children, title, text, dropdownContainerStyle, dropdownContainerClassName, dropdownContainerRef: externalContainerRef, hideToggleArrow, iconAction, disabled, noSelectButtonStyle, noDropdownListStyle, forceShown, onShown: externalOnShown, onHidden: externalOnHidden, dropdownOptions, buttonProps, dropdownRef, titlePosition, titleOptions, mobileBackdrop }: DropdownProps) {+export default function Dropdown({ id, className, buttonClassName, isStatic, children, title, text, dropdownContainerStyle, dropdownContainerClassName, dropdownContainerRef: externalContainerRef, hideToggleArrow, iconAction, disabled, noSelectButtonStyle, noDropdownListStyle, forceShown, onShown: externalOnShown, onHidden: externalOnHidden, dropdownOptions, buttonProps, dropdownRef, titlePosition, titleOptions, mobileBackdrop, portalToBody }: DropdownProps) {const containerRef = useRef<HTMLDivElement | null>(null);const triggerRef = useRef<HTMLButtonElement | null>(null);const dropdownContainerRef = useRef<HTMLUListElement | null>(null);@@ -59,6 +68,15 @@ export default function Dropdown({ id, className, buttonClassName, isStatic, chiif (!triggerRef.current || !dropdownContainerRef.current) return;const dropdown = BootstrapDropdown.getOrCreateInstance(triggerRef.current, dropdownOptions);++ // When the menu is portaled to `document.body` it is no longer a sibling of the toggle, so+ // Bootstrap fails to locate it (it searches the toggle's wrapper). Wire it up by hand —+ // Bootstrap only ever positions/toggles whatever `_menu` points at, regardless of where it+ // lives in the DOM, and the popper reference stays the toggle button.+ if (portalToBody && dropdownContainerRef.current) {+ (dropdown as unknown as { _menu: HTMLElement })._menu = dropdownContainerRef.current;+ }+if (dropdownRef) {dropdownRef.current = dropdown;}@@ -119,6 +137,23 @@ export default function Dropdown({ id, className, buttonClassName, isStatic, chiconst ariaId = useUniqueName("button");+ const menu = (+ <ul+ class={`dropdown-menu tn-dropdown-menu ${isStatic ? "static" : ""} ${dropdownContainerClassName ?? ""} ${!noDropdownListStyle ? "tn-dropdown-list" : ""}`}+ style={dropdownContainerStyle}+ aria-labelledby={ariaId}+ ref={dropdownContainerRef}+ onClick={(e) => {+ // Prevent clicks directly inside the dropdown from closing.+ if (e.target === dropdownContainerRef.current) {+ e.stopPropagation();+ }+ }}+ >+ {shown && children}+ </ul>+ );+return (<div ref={containerRef} class={`dropdown ${className ?? ""}`} style={{ display: "flex" }} title={title}><button@@ -139,20 +174,11 @@ export default function Dropdown({ id, className, buttonClassName, isStatic, chi<span className="caret" /></button>- <ul- class={`dropdown-menu tn-dropdown-menu ${isStatic ? "static" : ""} ${dropdownContainerClassName ?? ""} ${!noDropdownListStyle ? "tn-dropdown-list" : ""}`}- style={dropdownContainerStyle}- aria-labelledby={ariaId}- ref={dropdownContainerRef}- onClick={(e) => {- // Prevent clicks directly inside the dropdown from closing.- if (e.target === dropdownContainerRef.current) {- e.stopPropagation();- }- }}- >- {shown && children}- </ul>+ {portalToBody+ // Keep the `className` scope on the portaled wrapper so CSS scoped under it (e.g.+ // `.note-icon-widget .icon-list`) still applies even though the menu now lives in body.+ ? createPortal(<div class={className ?? ""}>{menu}</div>, document.body)+ : menu}</div>);}