Skip to content

Commit f428c3b

Browse files
[WEB-5542] chore: scrollIntoView implementation for sidebar active project (#8208)
1 parent a05cd88 commit f428c3b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

apps/web/core/components/workspace/sidebar/projects-list-item.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-
77
import { observer } from "mobx-react";
88
import { useParams, useRouter } from "next/navigation";
99
import { createRoot } from "react-dom/client";
10+
import scrollIntoView from "smooth-scroll-into-view-if-needed";
1011
import { LinkIcon, Settings, Share2, LogOut, MoreHorizontal } from "lucide-react";
1112
import { Disclosure, Transition } from "@headlessui/react";
1213
// plane imports
@@ -225,7 +226,29 @@ export const SidebarProjectsListItem = observer(function SidebarProjectsListItem
225226
useOutsideClickDetector(projectRef, () => projectRef?.current?.classList?.remove(HIGHLIGHT_CLASS));
226227

227228
useEffect(() => {
228-
if (URLProjectId === project?.id) setIsProjectListOpen(true);
229+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
230+
231+
if (URLProjectId === project?.id) {
232+
setIsProjectListOpen(true);
233+
// Scroll to active project
234+
if (projectRef.current) {
235+
timeoutId = setTimeout(() => {
236+
if (projectRef.current) {
237+
scrollIntoView(projectRef.current, {
238+
behavior: "smooth",
239+
block: "center",
240+
scrollMode: "if-needed",
241+
});
242+
}
243+
}, 200);
244+
}
245+
}
246+
247+
return () => {
248+
if (timeoutId) {
249+
clearTimeout(timeoutId);
250+
}
251+
};
229252
}, [URLProjectId, project?.id, setIsProjectListOpen]);
230253

231254
if (!project) return null;

0 commit comments

Comments
 (0)