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): thin, persistent, non-shifting launcher scrollbar
Elian Doran8c65ecc468a9
diff --git a/apps/client/src/stylesheets/theme-next/shell.css b/apps/client/src/stylesheets/theme-next/shell.cssindex f24c79311a..eb8eef78ed 100644--- a/apps/client/src/stylesheets/theme-next/shell.css+++ b/apps/client/src/stylesheets/theme-next/shell.css@@ -177,8 +177,27 @@ body.layout-horizontal > .horizontal {align-items: center;}-body[dir=ltr] #launcher-container {- scrollbar-gutter: stable both-edges;+/* Thin launcher-rail scrollbar; the padding below (set from the JS-measured+ * `--launcher-scrollbar-size`) offsets its width so it never shifts the centred buttons. */+#launcher-container {+ --scrollbar-thickness: 4px;+ --scrollbar-thumb-thickness: 4px;+ --scrollbar-thumb-hover-thickness: 4px;+ scrollbar-width: thin;+}++/* Style the base pseudo (forms.css styles only :vertical) so WebKit shows a persistent bar+ * instead of an auto-hiding overlay. */+#launcher-container::-webkit-scrollbar {+ width: var(--scrollbar-thickness);+ height: var(--scrollbar-thickness);+}++@supports (-webkit-box-reflect: below) {+ /* Let ::-webkit-scrollbar win over scrollbar-width on WebKit (mirrors forms.css's :root reset). */+ #launcher-container {+ scrollbar-width: unset;+ }}#launcher-pane.vertical {@@ -205,6 +224,7 @@ body[dir=ltr] #launcher-container {height: 100%;overflow-x: hidden;overflow-y: auto;+ padding-inline-start: var(--launcher-scrollbar-size, 0px);}#launcher-pane.horizontal {@@ -230,6 +250,7 @@ body[dir=ltr] #launcher-container {height: 100%;overflow-x: auto;overflow-y: hidden;+ padding-block-start: var(--launcher-scrollbar-size, 0px);}@media (max-width: 991px) {diff --git a/apps/client/src/widgets/launch_bar/LauncherContainer.tsx b/apps/client/src/widgets/launch_bar/LauncherContainer.tsxindex a334d741b5..44da926714 100644--- a/apps/client/src/widgets/launch_bar/LauncherContainer.tsx+++ b/apps/client/src/widgets/launch_bar/LauncherContainer.tsx@@ -1,4 +1,4 @@-import { useCallback, useLayoutEffect, useState } from "preact/hooks";+import { useCallback, useLayoutEffect, useRef, useState } from "preact/hooks";import FNote from "../../entities/fnote";import { isExperimentalFeatureEnabled } from "../../services/experimental_features";@@ -20,9 +20,11 @@ import SyncStatus from "./SyncStatus";export default function LauncherContainer({ isHorizontalLayout }: { isHorizontalLayout: boolean }) {const childNotes = useLauncherChildNotes();+ const containerRef = useLauncherScrollbarCompensation(isHorizontalLayout, childNotes);return (<div+ ref={containerRef}id="launcher-container"style={{display: "flex",@@ -143,3 +145,41 @@ export function useLauncherChildNotes() {return childNotes;}++// Measures the scrollbar's actual consumed size (which varies by browser and the OS "show scroll+// bars" setting) and publishes it as `--launcher-scrollbar-size`; shell.css reserves that much on+// the opposite edge so the bar never shifts the centred buttons. Recomputed on resize and whenever+// the set of launchers changes; scroll position doesn't affect the measurement.+// Recomputed on resize and whenever the set of launchers changes (which is what makes the rail+// start or stop overflowing); scroll position doesn't affect the measurement.+function useLauncherScrollbarCompensation(isHorizontalLayout: boolean, childNotes: FNote[] | undefined) {+ const ref = useRef<HTMLDivElement>(null);++ const update = useCallback(() => {+ const el = ref.current;+ if (!el) return;++ // `offsetSize - clientSize` is the space taken by the scrollbar (the container has no+ // border); 0 when the bar overlays or the rail doesn't overflow. Unaffected by the padding+ // we set, so this can't feed back on itself.+ const scrollbarSize = isHorizontalLayout+ ? el.offsetHeight - el.clientHeight+ : el.offsetWidth - el.clientWidth;+ const value = `${scrollbarSize}px`;+ if (el.style.getPropertyValue("--launcher-scrollbar-size") !== value) {+ el.style.setProperty("--launcher-scrollbar-size", value);+ }+ }, [ isHorizontalLayout ]);++ useLayoutEffect(() => {+ const el = ref.current;+ if (!el) return;++ update();+ const observer = new ResizeObserver(update);+ observer.observe(el);+ return () => observer.disconnect();+ }, [ update, childNotes ]);++ return ref;+}