diff --git a/src-web/components/Sidebar.tsx b/src-web/components/Sidebar.tsx index 346b701e..c22a3d8c 100644 --- a/src-web/components/Sidebar.tsx +++ b/src-web/components/Sidebar.tsx @@ -610,7 +610,6 @@ function SidebarItem({ children, }: SidebarItemProps) { const ref = useRef(null); - useScrollIntoView(ref.current, selected); const [, connectDrop] = useDrop( { @@ -670,6 +669,8 @@ function SidebarItem({ const isActive = activeRequest?.id === itemId; const createDropdownItems = useCreateDropdownItems({ folderId: itemId }); + useScrollIntoView(ref.current, isActive); + const handleSubmitNameEdit = useCallback( (el: HTMLInputElement) => { if (itemModel === 'http_request') { diff --git a/src-web/hooks/useScrollIntoView.ts b/src-web/hooks/useScrollIntoView.ts index 204bb410..0881c660 100644 --- a/src-web/hooks/useScrollIntoView.ts +++ b/src-web/hooks/useScrollIntoView.ts @@ -1,9 +1,9 @@ import { useEffect } from 'react'; -export function useScrollIntoView(node: T | null, active: boolean) { +export function useScrollIntoView(node: T | null, enabled: boolean) { useEffect(() => { - if (active) { - node?.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + if (enabled) { + node?.scrollIntoView({ block: 'nearest' }); } - }, [active, node]); + }, [enabled, node]); }