Skip to content

Commit b83dc88

Browse files
Fix sidebar auto-scroll to correctly target scrollable container
- Use closest() to find the actual scrollable UL container - Calculate position relative to the scrollable container, not the sidebar - Use getBoundingClientRect() for accurate positioning - Position active link near the top with 20px padding for visibility - Fixes issue where scroll didn't work correctly for Develop/Operate/Integrate - Fixes Commands section scrolling too far This improves the previous implementation by targeting the correct overflow-y-auto UL element that actually scrolls, rather than trying to scroll the sidebar nav element itself.
1 parent c55453e commit b83dc88

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

layouts/partials/docs-nav.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,27 @@
204204
const sidebar = document.getElementById('sidebar');
205205
const footer = document.querySelector('footer');
206206

207+
// Scroll sidebar to show active page on load
208+
const activeLink = sidebar.querySelector('a.active');
209+
if (activeLink) {
210+
// Find the scrollable UL container that contains the active link
211+
const scrollContainer = activeLink.closest('ul.overflow-y-auto');
212+
213+
if (scrollContainer) {
214+
// Get the position of the active link relative to its scrollable container
215+
const linkRect = activeLink.getBoundingClientRect();
216+
const containerRect = scrollContainer.getBoundingClientRect();
217+
218+
// Calculate how far the link is from the top of the container
219+
const relativeTop = linkRect.top - containerRect.top + scrollContainer.scrollTop;
220+
221+
// Scroll so the active link appears near the top (with some padding)
222+
const scrollPosition = relativeTop - 20; // 20px padding from top
223+
224+
scrollContainer.scrollTop = Math.max(0, scrollPosition);
225+
}
226+
}
227+
207228
window.addEventListener('scroll', function() {
208229
const scrolledHeight = window.scrollY + window.innerHeight;
209230
if (scrolledHeight >= footer.offsetTop) {

0 commit comments

Comments
 (0)