Skip to content

Commit f8dd575

Browse files
authored
[TASK] Scroll active menu items into view (#977)
1 parent 356e34a commit f8dd575

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

packages/typo3-docs-theme/assets/js/scrolling.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,19 @@ document.addEventListener("DOMContentLoaded", function () {
3535
});
3636
});
3737

38+
function scrollActiveMenuItemIntoView() {
39+
const menuContainer = document.querySelector(".page-main-navigation nav");
40+
const activeItem = menuContainer?.querySelector(".main_menu .active");
41+
42+
if (activeItem && typeof activeItem.scrollIntoView === "function") {
43+
activeItem.scrollIntoView({
44+
behavior: "auto", // or "smooth" if you prefer
45+
block: "center", // or "nearest" if you want minimal scrolling
46+
inline: "nearest"
47+
});
48+
}
49+
}
50+
51+
scrollActiveMenuItemIntoView();
3852
window.addEventListener("resize", adjustScrollMargin);
3953
});

0 commit comments

Comments
 (0)