Skip to content

Commit

Permalink
feat(sidemenu): activation de l'item décrit dans le hash de l'URL #19
Browse files Browse the repository at this point in the history
Co-authored-by: pprevautel <[email protected]>
  • Loading branch information
ocruze and pprev94 committed Jun 3, 2024
1 parent d57e83e commit b6b0e5f
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions _includes/components/sidemenu.njk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,32 @@
</nav>
<script>
(() => {
console.log("HASH : ", window.location.hash);
const links = document.querySelectorAll(".fr-sidemenu__link"));
const hash = window.location.hash
const link = document.querySelector(`.fr-sidemenu__link[href='${hash}']`);
if (link) {
link.ariaCurrent = "page"
let el = link.parentElement
do {
if (el?.classList?.contains("fr-collapse")) {
el.previousElementSibling.ariaExpanded = true
el.ariaCurrent = "true"
}
el = el.parentElement
} while (!el?.classList?.contains("fr-sidemenu__inner")); // on est arrivés an haut du sommaire, on a fini la boucle
}
const allLinks = document.querySelectorAll("a.fr-sidemenu__link")
const handleClick = (e) => {
allLinks.forEach(link => link.ariaCurrent = null)
e.currentTarget.ariaCurrent = "page"
}
allLinks.forEach(link => {
link.addEventListener("click", handleClick)
})
})();
</script>

0 comments on commit b6b0e5f

Please sign in to comment.