docs: fix error during navigation (#3509)

This commit is contained in:
Shahed Nasser
2023-03-17 10:59:20 +02:00
committed by GitHub
parent d0d46a504a
commit 812c8c6abd
+8 -17
View File
@@ -47,26 +47,17 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
navElementBoundingRect = navElement.getBoundingClientRect(); navElementBoundingRect = navElement.getBoundingClientRect();
//logic to scroll to current active item //logic to scroll to current active item
const activeItem = document.querySelector('.sidebar-desktop [aria-current=page]'), const activeItem = document.querySelector('.sidebar-desktop [aria-current=page]')
activeItemBoundingReact = activeItem?.getBoundingClientRect(),
if (!activeItem) {
return
}
const activeItemBoundingReact = activeItem.getBoundingClientRect(),
//the extra 160 is due to the sticky elements in the sidebar //the extra 160 is due to the sticky elements in the sidebar
isActiveItemVisible = activeItemBoundingReact.top >= 0 && activeItemBoundingReact.bottom + 160 <= navElementBoundingRect.height isActiveItemVisible = activeItemBoundingReact.top >= 0 && activeItemBoundingReact.bottom + 160 <= navElementBoundingRect.height
// alert(isActiveItemVisible);
if (activeItem && !isActiveItemVisible) { if (!isActiveItemVisible) {
//check if it has a parent list item element
// let parentListItem = activeItem.parentElement
//search only to reach the main sidebar element
// while (parentListItem && !parentListItem.classList.contains('sidebar-desktop')) {
// if (parentListItem.classList.contains('menu__list-item')) {
// break;
// }
// parentListItem = parentListItem.parentElement
// }
const elementToScrollTo = activeItem, const elementToScrollTo = activeItem,
elementBounding = elementToScrollTo.getBoundingClientRect() elementBounding = elementToScrollTo.getBoundingClientRect()
//scroll to element //scroll to element