Skip to content

Commit a6ba35d

Browse files
committed
Scroll active navigation item into view on full load
1 parent 2be9d12 commit a6ba35d

File tree

1 file changed

+7
-3
lines changed
  • site/themes/arangodb-docs-theme/static/js

1 file changed

+7
-3
lines changed

site/themes/arangodb-docs-theme/static/js/theme.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function getSelectedVersion() {
138138
*/
139139
}
140140

141-
function updateActiveNavItem(pathname) {
141+
function updateActiveNavItem(pathname, scrollIntoView) {
142142
// Remove all existing active states
143143
document.querySelectorAll(".link-nav-active").forEach(el => el.classList.remove("link-nav-active"));
144144

@@ -151,6 +151,10 @@ function updateActiveNavItem(pathname) {
151151
activeItem.classList.add("link-nav-active");
152152
// Expand all parent sections
153153
document.querySelectorAll(".nav-section:has(.link-nav-active) > .nav-section-header > .expand-nav > input").forEach(el => el.checked = true);
154+
155+
if (scrollIntoView) {
156+
activeItem.scrollIntoView({ behavior: "auto", block: "center" });
157+
}
154158
}
155159
}
156160

@@ -201,7 +205,7 @@ async function loadNav() {
201205
mainNavPlaceholder.appendChild(mainNavContent);
202206

203207
// Set initial active state
204-
updateActiveNavItem(window.location.pathname);
208+
updateActiveNavItem(window.location.pathname, true);
205209
} catch (error) {
206210
console.error("Error loading navigation:", error);
207211
mainNavPlaceholder.textContent = "Failed to load navigation";
@@ -226,7 +230,7 @@ function initArticle(url) {
226230
goToTop();
227231
styleImages();
228232
linkToVersionedContent();
229-
updateActiveNavItem(window.location.pathname);
233+
updateActiveNavItem(window.location.pathname, false);
230234
}
231235

232236

0 commit comments

Comments
 (0)