Fix sidebar scroll preservation by correcting link selector
- Change selector from 'a[x-navigate]' to 'a' (no x-navigate attribute) - Remove sessionStorage.removeItem to prevent clearing saved scroll position - Add '0' check to prevent restoring scroll position to top - Add debug logging for troubleshooting - Now works correctly in all browsers including Chrome
This commit is contained in:
@@ -264,7 +264,7 @@ class="fixed inset-y-0 left-0 top-16 w-64 bg-white border-r border-gray-200 over
|
|||||||
const sidebar = document.getElementById('kb-sidebar');
|
const sidebar = document.getElementById('kb-sidebar');
|
||||||
if (!sidebar) return;
|
if (!sidebar) return;
|
||||||
|
|
||||||
const link = e.target.closest('a[x-navigate]');
|
const link = e.target.closest('a');
|
||||||
if (link && sidebar.contains(link)) {
|
if (link && sidebar.contains(link)) {
|
||||||
// Save scroll position before navigation
|
// Save scroll position before navigation
|
||||||
const scrollPos = sidebar.scrollTop;
|
const scrollPos = sidebar.scrollTop;
|
||||||
@@ -276,13 +276,17 @@ class="fixed inset-y-0 left-0 top-16 w-64 bg-white border-r border-gray-200 over
|
|||||||
// Restore scroll position after page load
|
// Restore scroll position after page load
|
||||||
function restoreSidebarScroll() {
|
function restoreSidebarScroll() {
|
||||||
const sidebar = document.getElementById('kb-sidebar');
|
const sidebar = document.getElementById('kb-sidebar');
|
||||||
if (!sidebar) return;
|
if (!sidebar) {
|
||||||
|
console.log('Sidebar not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const savedPos = sessionStorage.getItem('kb_sidebar_scroll');
|
const savedPos = sessionStorage.getItem('kb_sidebar_scroll');
|
||||||
if (savedPos !== null) {
|
console.log('Retrieved from sessionStorage:', savedPos);
|
||||||
sidebar.scrollTop = parseInt(savedPos, 10);
|
if (savedPos !== null && savedPos !== '0') {
|
||||||
console.log('Restored sidebar scroll position:', savedPos);
|
const pos = parseInt(savedPos, 10);
|
||||||
sessionStorage.removeItem('kb_sidebar_scroll');
|
sidebar.scrollTop = pos;
|
||||||
|
console.log('Restored sidebar scroll position:', pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user