From f1857a10fe15439c14c0ce4014a695ea0079ed24 Mon Sep 17 00:00:00 2001 From: Kia King Ishii Date: Wed, 25 Nov 2020 00:45:56 +0900 Subject: [PATCH] fix: parent element not found error --- src/client/theme-default/composables/activeSidebarLink.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/theme-default/composables/activeSidebarLink.ts b/src/client/theme-default/composables/activeSidebarLink.ts index 9a7d8a49..de98c7a0 100644 --- a/src/client/theme-default/composables/activeSidebarLink.ts +++ b/src/client/theme-default/composables/activeSidebarLink.ts @@ -96,14 +96,16 @@ function isAnchorActive( nextAnchor: HTMLAnchorElement ): [boolean, string | null] { const scrollTop = window.scrollY - const anchorTop = getAnchorTop(anchor) - const nextAnchorTop = getAnchorTop(nextAnchor) if (index === 0 && scrollTop === 0) { return [true, null] } - if (scrollTop >= anchorTop && (!nextAnchor || scrollTop < nextAnchorTop)) { + if (scrollTop < getAnchorTop(anchor)) { + return [false, null] + } + + if (!nextAnchor || scrollTop < getAnchorTop(nextAnchor)) { return [true, decodeURIComponent(anchor.hash)] }