From 4a481aa6696ff6621a2b4dd40b3a3e513189fdb9 Mon Sep 17 00:00:00 2001
From: alexisben <alex@noesya.coop>
Date: Tue, 20 Dec 2022 15:18:55 +0100
Subject: [PATCH] fix toc

---
 assets/js/theme/design-system/toc.js | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/assets/js/theme/design-system/toc.js b/assets/js/theme/design-system/toc.js
index 50a9f797..233156be 100644
--- a/assets/js/theme/design-system/toc.js
+++ b/assets/js/theme/design-system/toc.js
@@ -21,11 +21,12 @@ class TableOfContents {
     this.state = {
       opened: false,
       currentId: null,
-      currentLink: 0
+      currentLink: 0,
+      isOffcanvas : this.isOffcanvas()
     }
     this.listen();
 
-    if (this.isOffcanvas) {
+    if (this.state.isOffcanvas) {
       this.element.setAttribute("aria-hidden", true);
     }
   }
@@ -124,10 +125,10 @@ class TableOfContents {
     }
   }
   updateScrollspy(scroll) {
-    const container = this.isOffcanvas() ? this.nav : this.content;
-    if (this.state.currentLink) {
+    const container = this.state.isOffcanvas ? this.nav : this.content;
+    if (this.state.currentLink && scroll > window.innerHeight) {
       let progress = (this.getAbsoluteOffsetTop(this.state.currentLink) - container.offsetHeight/2);
-      progress = this.isOffcanvas() ? progress : progress - scroll;
+      progress = this.state.isOffcanvas ? progress : progress - scroll;
       container.scrollTo({
         top: progress
       })
-- 
GitLab