diff --git a/src/components/folder-selection-view.tsx b/src/components/folder-selection-view.tsx index 49712284..5752239a 100644 --- a/src/components/folder-selection-view.tsx +++ b/src/components/folder-selection-view.tsx @@ -28,9 +28,18 @@ const FolderSelectionView: Component = (props) => { }) function scrollToIndex(index: number) { - const element = recentListRef?.querySelector(`[data-folder-index="${index}"]`) - if (element) { - element.scrollIntoView({ block: "nearest", behavior: "auto" }) + const container = recentListRef + if (!container) return + const element = container.querySelector(`[data-folder-index="${index}"]`) as HTMLElement | null + if (!element) return + + const containerRect = container.getBoundingClientRect() + const elementRect = element.getBoundingClientRect() + + if (elementRect.top < containerRect.top) { + container.scrollTop -= containerRect.top - elementRect.top + } else if (elementRect.bottom > containerRect.bottom) { + container.scrollTop += elementRect.bottom - containerRect.bottom } } @@ -182,59 +191,55 @@ const FolderSelectionView: Component = (props) => { } > -
-
-

Recent Folders

-

- {folders().length} {folders().length === 1 ? "folder" : "folders"} available -

-
-
(recentListRef = el)} - > - - {(folder, index) => ( -
- -
+
+
+

Recent Folders

+

+ {folders().length} {folders().length === 1 ? "folder" : "folders"} available +

+
+
(recentListRef = el)}> + + {(folder, index) => ( +
+