Skip to content

Commit 8e6a68f

Browse files
committed
Don't scroll sidebar to the top
When we click on a left sidebar link, it used to open the right page but scroll the sidbar back to the top. Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent cf0aede commit 8e6a68f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

docs/js/app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,27 @@ document.addEventListener('keydown', (e) => {
202202
if (e.key === 'Escape') closeSearch();
203203
});
204204

205+
// ---------- Sidebar scroll persistence ----------
206+
function restoreSidebarScroll() {
207+
const sidebar = document.getElementById('sidebar');
208+
if (!sidebar) return;
209+
210+
const saved = sessionStorage.getItem('sidebar-scroll');
211+
if (saved !== null) {
212+
sidebar.scrollTop = parseInt(saved, 10);
213+
}
214+
215+
// Before navigating away, save the current scroll position
216+
sidebar.querySelectorAll('a').forEach(link => {
217+
link.addEventListener('click', () => {
218+
sessionStorage.setItem('sidebar-scroll', sidebar.scrollTop);
219+
});
220+
});
221+
}
222+
205223
// ---------- Init ----------
206224
initTheme();
225+
restoreSidebarScroll();
207226
buildSearchIndex();
208227
buildTOC();
209228
addCopyButtons();

0 commit comments

Comments
 (0)