Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/dev/s2-docs/src/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,18 @@ export function SideNavItem(props) {

export function SideNavLink(props) {
let linkRef = useRef<HTMLAnchorElement | null>(null);
let shouldAutoScrollOnMount = useRef(props.isSelected);
let selected = useContext(SideNavContext);
let {isExternal, ...linkProps} = props;

useEffect(() => {
let link = linkRef.current;
if (!link || !props.isSelected) {
if (!link || !props.isSelected || !shouldAutoScrollOnMount.current) {
return;
}

link.scrollIntoView({block: 'start', behavior: 'smooth'});
shouldAutoScrollOnMount.current = false;
link.scrollIntoView({block: 'start'});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that it scrolls even when you click on a link in the sidebar. For example scroll down and then click a link near the top, it will move when you click it. Maybe we should only do this on the initial page load?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand what you mean correctly, this should be fixed when using our shim here instead, as that implements the equivalent of scrollIntoViewIfNeeded.

}, [props.isSelected]);

return (
Expand Down
Loading