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');
|
||||
if (!sidebar) return;
|
||||
|
||||
const link = e.target.closest('a[x-navigate]');
|
||||
const link = e.target.closest('a');
|
||||
if (link && sidebar.contains(link)) {
|
||||
// Save scroll position before navigation
|
||||
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
|
||||
function restoreSidebarScroll() {
|
||||
const sidebar = document.getElementById('kb-sidebar');
|
||||
if (!sidebar) return;
|
||||
if (!sidebar) {
|
||||
console.log('Sidebar not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const savedPos = sessionStorage.getItem('kb_sidebar_scroll');
|
||||
if (savedPos !== null) {
|
||||
sidebar.scrollTop = parseInt(savedPos, 10);
|
||||
console.log('Restored sidebar scroll position:', savedPos);
|
||||
sessionStorage.removeItem('kb_sidebar_scroll');
|
||||
console.log('Retrieved from sessionStorage:', savedPos);
|
||||
if (savedPos !== null && savedPos !== '0') {
|
||||
const pos = parseInt(savedPos, 10);
|
||||
sidebar.scrollTop = pos;
|
||||
console.log('Restored sidebar scroll position:', pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user