Skip to content

Build your personal knowledge base with Trilium Notes

client/right pane: allow resizing when opened as an overlay

Adorian Doran2a5897803d0a
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.css b/apps/client/src/widgets/sidebar/RightPanelContainer.css
index 4daf13d913..797d8fec67 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.css
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.css
@@ -10,48 +10,63 @@ body.experimental-feature-new-layout #vertical-main-container {
padding-inline-end: var(--right-pane-handle-gutter);
}
-/* Overlay mode: float the pane above the content (no Split, so the content never reflows).
- Width is applied inline from the saved rightPaneWidth (see RightPanelContainer.tsx). */
-body.experimental-feature-new-layout #right-pane.overlay {
+/* Persistent host wrapping the spacer + #right-pane (see RightPanelContainer.tsx), so #right-pane
+ never reparents between modes. A flex row: docked it fills with the pane (spacer hidden); overlay
+ it lays out [spacer | gutter | pane]. */
+body.experimental-feature-new-layout #right-pane-host {
+ display: flex;
+ flex-direction: row;
+}
+
+/* Docked: #right-pane fills the host (which Split sizes against #center-pane). */
+body.experimental-feature-new-layout #right-pane-host:not(.overlay) > #right-pane {
+ flex: 1 1 0;
+ min-width: 0;
+}
+
+/* When closing the overlay, the host goes in-flow a frame before Split.destroy (run in an effect)
+ removes its resize gutter. Keep any gutter inside a non-overlay host out of the flow so that
+ lingering 5px gutter can't briefly widen the host and reflow the content. */
+body.experimental-feature-new-layout #right-pane-host:not(.overlay) > .gutter {
+ display: none;
+}
+
+/* Overlay: float the host above the content as an absolute layer, so the content never reflows. */
+body.experimental-feature-new-layout #right-pane-host.overlay {
position: absolute;
inset-block: 0;
+ inset-inline-start: 0;
inset-inline-end: var(--right-pane-handle-gutter);
- /* Floor matching the docked Split minSize, so a small saved width can't make the overlay too thin. */
- min-width: 180px;
z-index: 15;
- border-inline-start: 1px solid var(--main-border-color);
- box-shadow: -4px 0 12px rgba(0, 0, 0, 0.18);
animation: right-pane-overlay-in 150ms ease;
}
@keyframes right-pane-overlay-in {
- from { transform: translateX(8px); opacity: 0; }
- to { transform: translateX(0); opacity: 1; }
+ from { opacity: 0; }
+ to { 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);
+/* Overlay: Split sizes the spacer and the pane via inline widths, so flex must not override them. */
+body.experimental-feature-new-layout #right-pane-host.overlay > .right-pane-overlay-spacer,
+body.experimental-feature-new-layout #right-pane-host.overlay > #right-pane {
+ flex: 0 0 auto;
}
-body.experimental-feature-new-layout .right-pane-overlay-backdrop.active {
- display: block;
- animation: right-pane-backdrop-in 150ms ease;
+body.experimental-feature-new-layout #right-pane-host.overlay > #right-pane {
+ border-inline-start: 1px solid var(--main-border-color);
+ box-shadow: -4px 0 12px rgba(0, 0, 0, 0.18);
}
-@keyframes right-pane-backdrop-in {
- from { opacity: 0; }
- to { opacity: 1; }
+/* The spacer is the left Split target and, in overlay mode, the faint click-to-dismiss backdrop
+ over the content (it also shields the PDF iframe during a resize drag). Hidden when docked. */
+body.experimental-feature-new-layout .right-pane-overlay-spacer {
+ display: none;
+}
+
+body.experimental-feature-new-layout #right-pane-host.overlay > .right-pane-overlay-spacer {
+ display: block;
+ min-width: 0;
+ background: rgba(0, 0, 0, 0.05);
}
/* Pin/close controls, shown only in overlay mode. */
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx
index 0658142208..154668a974 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.spec.tsx
@@ -43,27 +43,28 @@ describe("isWithinOverlay", () => {
document.body.innerHTML = "";
});
- it("keeps the overlay open for the pane, the handle, and allowlisted popups", () => {
+ it("keeps the overlay open for the pane, the handle, the resize gutter, and allowlisted popups", () => {
document.body.innerHTML = `
<div id="right-pane"><span class="toc-item">x</span></div>
<button class="right-pane-toggle-handle"></button>
+ <div class="gutter gutter-horizontal"></div>
<ul class="dropdown-menu"><li class="dropdown-item">y</li></ul>
<div class="tooltip">t</div>
`;
- for (const selector of [".toc-item", ".right-pane-toggle-handle", ".dropdown-item", ".tooltip"]) {
+ for (const selector of [".toc-item", ".right-pane-toggle-handle", ".gutter", ".dropdown-item", ".tooltip"]) {
expect(isWithinOverlay(document.querySelector(selector)), selector).toBe(true);
}
});
- it("dismisses for the backdrop, surrounding chrome, and non-elements", () => {
+ it("dismisses for the spacer/backdrop, surrounding chrome, and non-elements", () => {
document.body.innerHTML = `
- <div class="right-pane-overlay-backdrop active"></div>
+ <div class="right-pane-overlay-spacer"></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>
`;
- // 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"]) {
+ // The spacer/backdrop is deliberately outside the allowlist, so clicking the covered content dismisses.
+ for (const selector of [".right-pane-overlay-spacer", ".editor", ".tab", ".tree-item"]) {
expect(isWithinOverlay(document.querySelector(selector)), selector).toBe(false);
}
expect(isWithinOverlay(document.body)).toBe(false);
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index 7450a843ec..317e23599e 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -45,7 +45,7 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
const [ mode, setMode ] = useState<RightPaneMode>(() => options.is("rightPaneVisible") ? "docked" : "closed");
const visible = mode !== "closed";
const items = useItems(visible, widgetsByParent);
- useSplit(mode === "docked");
+ useSplit(mode);
// Apply a transition, persisting only when the docked/closed distinction changes
// (overlay is ephemeral, so it never writes the option).
@@ -69,45 +69,43 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
useOverlayDismiss(mode === "overlay", close);
- // The overlay reuses the docked width but can't be sized by Split (the content pane isn't flexed),
- // so it's applied as an inline width here — a genuinely computed value that can't live in CSS.
- const overlayStyle = mode === "overlay"
- ? { width: `${Math.max(MIN_WIDTH_PERCENT, options.getInt("rightPaneWidth") ?? MIN_WIDTH_PERCENT)}%` }
- : undefined;
-
return (
<>
{/* Absolutely positioned in a reserved gutter on the viewport's right edge, so it
stays 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">
- <ActionButton icon="bx bx-pin" text={t("right_pane.dock")} onClick={dock} />
- <ActionButton icon="bx bx-x" text={t("right_pane.close")} onClick={close} />
- </div>
- )}
- {visible && (
- items.length > 0 ? (
- items
- ) : (
- <NoItems
- icon="bx bx-sidebar"
- text={t("right_pane.empty_message")}
- >
- <Button
- text={t("right_pane.empty_button")}
- triggerCommand="toggleRightPane"
- />
- </NoItems>
- )
- )}
+ {/* Persistent host so #right-pane never reparents between modes (which would remount the
+ sidebar widgets). Docked: an in-flow flex child Split resizes against #center-pane.
+ Overlay: an absolute layer over the content where Split resizes the spacer vs the pane. */}
+ <div id="right-pane-host" class={mode === "overlay" ? "overlay" : undefined}>
+ {/* The spacer is both the left Split target and the dismiss backdrop in overlay mode:
+ it covers the content (a click dismisses) and shields the PDF iframe so Split's
+ drag tracking isn't interrupted. Always rendered + CSS-toggled to keep the host's
+ child list structurally stable for Split's gutter injection. */}
+ <div class="right-pane-overlay-spacer" />
+ <div id="right-pane">
+ {mode === "overlay" && (
+ <div class="right-pane-overlay-actions">
+ <ActionButton icon="bx bx-pin" text={t("right_pane.dock")} onClick={dock} />
+ <ActionButton icon="bx bx-x" text={t("right_pane.close")} onClick={close} />
+ </div>
+ )}
+ {visible && (
+ items.length > 0 ? (
+ items
+ ) : (
+ <NoItems
+ icon="bx bx-sidebar"
+ text={t("right_pane.empty_message")}
+ >
+ <Button
+ text={t("right_pane.empty_button")}
+ triggerCommand="toggleRightPane"
+ />
+ </NoItems>
+ )
+ )}
+ </div>
</div>
</>
);
@@ -185,22 +183,34 @@ function useItems(rightPaneVisible: boolean, widgetsByParent: WidgetsByParent) {
.map(e => e.el);
}
-function useSplit(visible: boolean) {
- // Split between right pane and the content pane.
+function useSplit(mode: RightPaneMode) {
useEffect(() => {
- if (!visible) return;
+ if (mode === "closed") return;
// We are intentionally omitting useTriliumOption to avoid re-render due to size change.
const rightPaneWidth = Math.max(MIN_WIDTH_PERCENT, options.getInt("rightPaneWidth") ?? MIN_WIDTH_PERCENT);
- const splitInstance = Split(["#center-pane", "#right-pane"], {
- sizes: [100 - rightPaneWidth, rightPaneWidth],
- gutterSize: DEFAULT_GUTTER_SIZE,
- minSize: [300, 180],
- rtl: glob.isRtl,
- onDragEnd: (sizes) => options.save("rightPaneWidth", Math.round(sizes[1]))
- });
+ const saveWidth = (sizes: number[]) => options.save("rightPaneWidth", Math.round(sizes[1]));
+
+ // Docked: resize the host (and thus the content) against #center-pane.
+ // Overlay: resize the pane against the spacer inside the absolute host — the content (#center-pane)
+ // is untouched, so it never reflows.
+ const splitInstance = mode === "docked"
+ ? Split(["#center-pane", "#right-pane-host"], {
+ sizes: [100 - rightPaneWidth, rightPaneWidth],
+ gutterSize: DEFAULT_GUTTER_SIZE,
+ minSize: [300, 180],
+ rtl: glob.isRtl,
+ onDragEnd: saveWidth
+ })
+ : Split([".right-pane-overlay-spacer", "#right-pane"], {
+ sizes: [100 - rightPaneWidth, rightPaneWidth],
+ gutterSize: DEFAULT_GUTTER_SIZE,
+ minSize: [0, 180],
+ rtl: glob.isRtl,
+ onDragEnd: saveWidth
+ });
return () => splitInstance.destroy();
- }, [ visible ]);
+ }, [ mode ]);
}
type RightPaneAction = "toggleOverlay" | "toggleDocked" | "dock" | "close";
@@ -223,10 +233,10 @@ export function persistedRightPaneVisible(prev: RightPaneMode, next: RightPaneMo
return (prev === "docked") !== (next === "docked") ? next === "docked" : null;
}
-// 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";
+// Clicks within these keep the overlay open: the pane, the toggle handle, the resize gutter, and
+// popups that sidebar content renders into portals outside #right-pane (dropdowns, tooltips, modals).
+// The spacer/backdrop is intentionally NOT listed, so clicking the covered content area dismisses.
+const OVERLAY_KEEP_OPEN_SELECTOR = "#right-pane, .right-pane-toggle-handle, .gutter, .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 {