Files
copilotkit__copilotkit/docs/components/layout/scroll-reset.tsx
2026-02-13 11:01:44 +01:00

23 lines
678 B
TypeScript

"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
/**
* Resets scroll position of the parent scroll container when navigating to a new page.
* Fixes issue where scroll position persists when using collapsed TOC navigation.
*/
export function ScrollReset() {
const pathname = usePathname();
useEffect(() => {
// Find the scroll container (docs-content-wrapper)
const scrollContainer = document.querySelector(".docs-content-wrapper");
if (scrollContainer) {
scrollContainer.scrollTop = 0;
}
}, [pathname]); // Run whenever pathname changes
return null; // This component doesn't render anything
}