From 410f9d2ce2b192a2d84970ffff596357eb70f064 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 5 Dec 2026 22:21:40 -0500 Subject: [PATCH] feat: Keep expanded collection sticky at the top of the sidebar (#14907) * feat: Keep expanded collection sticky at the top of the sidebar * fix: Uncover rows under the sticky collection row, contain archived collection rows --- .../components/ArchivedCollectionLink.tsx | 17 ++++++++++------- .../Sidebar/components/CollectionRow.tsx | 15 ++++++++++++--- .../Sidebar/components/DocumentTree.tsx | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/components/Sidebar/components/ArchivedCollectionLink.tsx b/app/components/Sidebar/components/ArchivedCollectionLink.tsx index 4b21c91191..da35b977e1 100644 --- a/app/components/Sidebar/components/ArchivedCollectionLink.tsx +++ b/app/components/Sidebar/components/ArchivedCollectionLink.tsx @@ -26,13 +26,16 @@ export function ArchivedCollectionLink({ collection, depth = 0 }: Props) { setExpanded(true); }, []); + // The wrapper limits the sticky collection row to its own documents. return ( - +
+ +
); } diff --git a/app/components/Sidebar/components/CollectionRow.tsx b/app/components/Sidebar/components/CollectionRow.tsx index 7b924383ad..d9f624ead6 100644 --- a/app/components/Sidebar/components/CollectionRow.tsx +++ b/app/components/Sidebar/components/CollectionRow.tsx @@ -6,6 +6,8 @@ import { flushSync } from "react-dom"; import { useTranslation } from "react-i18next"; import { mergeRefs } from "react-merge-refs"; import type { match } from "react-router"; +import styled from "styled-components"; +import { s } from "@shared/styles"; import { isTouchDevice } from "@shared/utils/browser"; import { CollectionValidation, DocumentValidation } from "@shared/validations"; import type Collection from "~/models/Collection"; @@ -17,7 +19,6 @@ import Tooltip from "~/components/Tooltip"; import useBoolean from "~/hooks/useBoolean"; import { ActionContextProvider } from "~/hooks/useActionContext"; import DropToImport from "./DropToImport"; -import Relative from "./Relative"; import SidebarLink from "./SidebarLink"; import { StaticLink } from "./StaticLink"; import type { SidebarContextType } from "./SidebarContext"; @@ -257,11 +258,11 @@ function CollectionRow({ - + {sidebarLinkElement} - + {children( isAddingNewChild && onCreateChild ? ( parent.id !== "sidebar", }); + + // Uncovers a row that is under the sticky collection row. + element.scrollIntoView({ block: "nearest" }); } // Scroll when the active row appears, not when rows above it change. // oxlint-disable-next-line react-hooks/exhaustive-deps @@ -251,7 +256,7 @@ export const DocumentTree = observer(function DocumentTree({ return ( {gap > 0 &&
} -
+ -
+ ); }); @@ -280,6 +285,11 @@ export const DocumentTree = observer(function DocumentTree({ ); }); +// Leaves space for the sticky collection row when a row scrolls into view. +const Row = styled.div` + scroll-margin-top: ${isMobile() ? 48 : ROW_HEIGHT}px; +`; + /** * Moves the descendants of root rows at depth 0 one level deeper, so that the * rows match childDepthFor.