File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
docs_headless/src/components Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -14,10 +14,21 @@ const { sidebar } = Astro.locals.starlightRoute;
1414 "a[aria-current='page']"
1515 );
1616 if (currentItem) {
17- sidebarContainer.scrollTo({
18- top: currentItem.offsetTop - sidebarContainer.offsetTop,
19- behavior: 'smooth',
20- });
17+ // Check if the current item is already visible in the sidebar viewport
18+ const containerRect = sidebarContainer.getBoundingClientRect();
19+ const itemRect = currentItem.getBoundingClientRect();
20+
21+ const isItemVisible =
22+ itemRect.top >= containerRect.top &&
23+ itemRect.bottom <= containerRect.bottom;
24+
25+ // Only scroll if the item is not already visible
26+ if (!isItemVisible) {
27+ sidebarContainer.scrollTo({
28+ top: currentItem.offsetTop - sidebarContainer.offsetTop,
29+ behavior: 'auto',
30+ });
31+ }
2132 }
2233 });
2334</script >
You can’t perform that action at this time.
0 commit comments