From 0500623052173d0c236d6e073e8cbbf16faa9db9 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Fri, 17 Mar 2023 10:45:50 +0200 Subject: [PATCH] docs: fix error top undefined --- .../src/theme/DocSidebar/Desktop/index.js | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/www/docs/src/theme/DocSidebar/Desktop/index.js b/www/docs/src/theme/DocSidebar/Desktop/index.js index b2e0c8aceecc9..7b2ae4a3f3cfb 100644 --- a/www/docs/src/theme/DocSidebar/Desktop/index.js +++ b/www/docs/src/theme/DocSidebar/Desktop/index.js @@ -47,26 +47,17 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) { navElementBoundingRect = navElement.getBoundingClientRect(); //logic to scroll to current active item - const activeItem = document.querySelector('.sidebar-desktop [aria-current=page]'), - activeItemBoundingReact = activeItem?.getBoundingClientRect(), + const activeItem = document.querySelector('.sidebar-desktop [aria-current=page]') + + if (!activeItem) { + return + } + + const activeItemBoundingReact = activeItem.getBoundingClientRect(), //the extra 160 is due to the sticky elements in the sidebar isActiveItemVisible = activeItemBoundingReact.top >= 0 && activeItemBoundingReact.bottom + 160 <= navElementBoundingRect.height - - // alert(isActiveItemVisible); - if (activeItem && !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 - // } - + if (!isActiveItemVisible) { const elementToScrollTo = activeItem, elementBounding = elementToScrollTo.getBoundingClientRect() //scroll to element