From 7128b148c2c58649e20b2a22afeb87f7f18120b4 Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:37:54 +0300 Subject: [PATCH] Change rect top (#270) Change rect top --- src/components/TableOfContents/TableOfContents.tsx | 9 ++------- tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/components/TableOfContents/TableOfContents.tsx b/src/components/TableOfContents/TableOfContents.tsx index 7f018eb6..1efcdd4e 100644 --- a/src/components/TableOfContents/TableOfContents.tsx +++ b/src/components/TableOfContents/TableOfContents.tsx @@ -16,12 +16,7 @@ interface Props { const isInViewport = (el: Element): boolean => { const rect = el.getBoundingClientRect() - return ( - rect.top >= 0 && - rect.left >= 0 && - rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && - rect.right <= (window.innerWidth || document.documentElement.clientWidth) - ) + return rect.top <= DEFAULT_HEADER_OFFSET } const scrollToHeader = (element) => { window.scrollTo({ @@ -57,7 +52,7 @@ export const TableOfContents = (props: Props) => { const debouncedUpdateHeadings = debounce(updateHeadings, 500) const updateActiveHeader = throttle(() => { - const newActiveIndex = headings().findIndex((heading) => isInViewport(heading)) + const newActiveIndex = headings().findLastIndex((heading) => isInViewport(heading)) setActiveHeaderIndex(newActiveIndex) }, 50) diff --git a/tsconfig.json b/tsconfig.json index dac5c23c..bfe45861 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,6 @@ "resolveJsonModule": true, "skipLibCheck": true, "isolatedModules": true, - "lib": ["ES2021", "dom"] + "lib": ["es2023", "dom"] } }