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
client/right pane: add a backdrop when open as an overlay
Adorian Doran3931d359843a
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.css b/apps/client/src/widgets/sidebar/RightPanelContainer.cssindex 5fc3be3bc7..4daf13d913 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.css+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.css@@ -29,6 +29,31 @@ body.experimental-feature-new-layout #right-pane.overlay {to { transform: translateX(0); opacity: 1; }}+/* Backdrop behind the overlay: marks the content area as a click-to-dismiss zone and reliably+ captures outside clicks (including over the PDF iframe, which swallows the parent's pointer+ events). Sidebar popups (dropdowns, tooltips) render above it via their own z-index, so they+ aren't dismissed. Sits left of the handle gutter so the handle stays interactive. */+body.experimental-feature-new-layout .right-pane-overlay-backdrop {+ /* Always in the DOM (see RightPanelContainer.tsx); shown only while the overlay is active. */+ display: none;+ position: absolute;+ inset-block: 0;+ inset-inline-start: 0;+ inset-inline-end: var(--right-pane-handle-gutter);+ z-index: 14;+ background: rgba(0, 0, 0, 0.05);+}++body.experimental-feature-new-layout .right-pane-overlay-backdrop.active {+ display: block;+ animation: right-pane-backdrop-in 150ms ease;+}++@keyframes right-pane-backdrop-in {+ from { opacity: 0; }+ to { opacity: 1; }+}+/* Pin/close controls, shown only in overlay mode. */body.experimental-feature-new-layout #right-pane .right-pane-overlay-actions {position: absolute;diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.spec.ts b/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsindex 59c0995db3..8f59556e85 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.spec.ts+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.spec.ts@@ -11,38 +11,33 @@ describe("isWithinOverlay", () => {document.body.innerHTML = html;}- it("treats the pane, the handle, and allowlisted popups as inside", () => {+ it("keeps the overlay open for the pane, the handle, and allowlisted popups", () => {mount(`<div id="right-pane"><span class="toc-item">x</span></div><button class="right-pane-toggle-handle"></button><ul class="dropdown-menu"><li class="dropdown-item">y</li></ul><div class="tooltip">t</div>- <div id="center-pane"><p class="editor">z</p></div>`);- const inside = [".toc-item", ".right-pane-toggle-handle", ".dropdown-item", ".tooltip"];- for (const selector of inside) {+ for (const selector of [".toc-item", ".right-pane-toggle-handle", ".dropdown-item", ".tooltip"]) {expect(isWithinOverlay(document.querySelector(selector)), selector).toBe(true);}});- it("treats content outside the pane/popups as outside, and ignores non-elements", () => {- mount(`<div id="center-pane"><p class="editor">z</p></div>`);+ it("dismisses for the backdrop, surrounding chrome, and non-elements", () => {+ mount(`+ <div class="right-pane-overlay-backdrop active"></div>+ <div id="center-pane"><p class="editor">z</p></div>+ <div class="tab-row-container"><span class="tab">t</span></div>+ <div id="left-pane"><span class="tree-item">n</span></div>+ `);- expect(isWithinOverlay(document.querySelector(".editor"))).toBe(false);+ // The backdrop is deliberately outside the allowlist, so clicking the covered content dismisses.+ for (const selector of [".right-pane-overlay-backdrop", ".editor", ".tab", ".tree-item"]) {+ expect(isWithinOverlay(document.querySelector(selector)), selector).toBe(false);+ }expect(isWithinOverlay(document.body)).toBe(false);expect(isWithinOverlay(null)).toBe(false);expect(isWithinOverlay(document)).toBe(false);});-- it("classifies a focused iframe by its location (the PDF-viewer dismiss path)", () => {- mount(`- <div id="center-pane"><iframe class="pdf-viewer"></iframe></div>- <div id="right-pane"><iframe class="sidebar-frame"></iframe></div>- `);-- // Clicking the PDF viewer (center-pane iframe) should dismiss; a sidebar iframe should not.- expect(isWithinOverlay(document.querySelector(".pdf-viewer"))).toBe(false);- expect(isWithinOverlay(document.querySelector(".sidebar-frame"))).toBe(true);- });});diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsxindex d16f76281d..5803d6863d 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx@@ -80,6 +80,12 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare{/* Absolutely positioned in a reserved gutter on the viewport's right edge, so itstays put regardless of the panel's open/collapsed state (see RightPanelContainer.css). */}<RightPaneToggleHandle rightPaneVisible={visible} onToggle={toggleOverlay} />+ {/* Visual dismiss cue and a physical layer over the content area (so presses over the+ PDF iframe reach the document listener in useOverlayDismiss). Always rendered, toggled+ via CSS, so the fragment's child list stays structurally stable: Split.js injects a+ gutter among these siblings, and mounting/unmounting a Preact-managed sibling around+ it corrupts reconciliation (insertBefore error). */}+ <div class={mode === "overlay" ? "right-pane-overlay-backdrop active" : "right-pane-overlay-backdrop"} /><div id="right-pane" class={mode === "overlay" ? "overlay" : undefined} style={overlayStyle}>{mode === "overlay" && (<div class="right-pane-overlay-actions">@@ -197,57 +203,39 @@ function useSplit(visible: boolean) {}, [ visible ]);}-// Elements that should NOT dismiss the overlay when clicked/focused: the pane itself, the toggle-// handle, and popups that sidebar content renders into portals outside #right-pane (dropdowns,-// context menus, tooltips, modals). Tune this list as sidebar widgets add new popup roots.-const OVERLAY_KEEP_OPEN_SELECTOR = "#right-pane, .right-pane-toggle-handle, .dropdown-menu, .tooltip, .modal, .popover, .context-menu";+// Clicks within these keep the overlay open: the pane, the toggle handle, and popups that sidebar+// content renders into portals outside #right-pane (dropdowns, tooltips, modals). The backdrop is+// intentionally NOT listed, so clicking the (covered) content area dismisses like other outside clicks.+const OVERLAY_KEEP_OPEN_SELECTOR = "#right-pane, .right-pane-toggle-handle, .dropdown-menu, .tooltip, .modal, .popover";/** Whether an event target lies within the overlay or an allowlisted popup (i.e. should keep it open). */export function isWithinOverlay(target: EventTarget | null): boolean {return target instanceof Element && target.closest(OVERLAY_KEEP_OPEN_SELECTOR) !== null;}-/** While `active`, closes the overlay on an outside pointer press, focus move, or Escape. */+/**+ * While `active`, closes the overlay on an outside press or Escape. Presses over the content area+ * (including the PDF iframe) land on the backdrop element and so reach this listener; presses on+ * chrome the backdrop doesn't cover (tree, toolbar, tabs) are caught directly. Capture phase so a+ * child's `stopPropagation` can't keep a stale overlay open.+ */function useOverlayDismiss(active: boolean, onDismiss: () => void) {useEffect(() => {if (!active) return;-- let blurTimer: ReturnType<typeof setTimeout> | undefined;-const onPointerDown = (e: PointerEvent) => {if (!isWithinOverlay(e.target)) onDismiss();};- const onFocusIn = (e: FocusEvent) => {- // Focus parked on <body> (e.g. after the handle blurs itself on open) isn't a real move-away.- if (e.target === document.body || isWithinOverlay(e.target)) return;- onDismiss();- };- const onWindowBlur = () => {- // Clicks inside an iframe (e.g. the PDF viewer) don't reach the parent's pointerdown,- // but they blur the window and move focus onto the <iframe> element. Read activeElement- // on the next tick (some browsers update it after the blur fires).- blurTimer = setTimeout(() => {- const active = document.activeElement;- if (active instanceof HTMLIFrameElement && !isWithinOverlay(active)) onDismiss();- });- };const onKeyDown = (e: KeyboardEvent) => {if (e.key === "Escape") {onDismiss();document.querySelector<HTMLElement>(".right-pane-toggle-handle")?.focus();}};-document.addEventListener("pointerdown", onPointerDown, true);- document.addEventListener("focusin", onFocusIn);document.addEventListener("keydown", onKeyDown);- window.addEventListener("blur", onWindowBlur);return () => {document.removeEventListener("pointerdown", onPointerDown, true);- document.removeEventListener("focusin", onFocusIn);document.removeEventListener("keydown", onKeyDown);- window.removeEventListener("blur", onWindowBlur);- if (blurTimer) clearTimeout(blurTimer);};}, [ active, onDismiss ]);}