Skip to content

Commit

Permalink
Close side nav drawer when anchors are clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
bartaz committed Jun 9, 2022
1 parent 07e6217 commit 0f95768
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions templates/static/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@
}

setupSideNavigations('.p-side-navigation, [class*="p-side-navigation--"]');
})();

// Add table of contents to side navigation on documentation pages
(function () {
// Add table of contents to side navigation on documentation pages
const sideNav = document.querySelector('.p-side-navigation, [class*="p-side-navigation--"]');

// Generate id from H2s content when it does not exist
document.querySelectorAll('main h2:not([id])').forEach(function (heading) {
var id = heading.textContent
Expand All @@ -135,6 +135,9 @@
var thisAnchor = anchor.cloneNode();
thisAnchor.setAttribute('href', '#' + heading.id);
thisAnchor.textContent = heading.textContent;
thisAnchor.addEventListener('click', () => {
toggleDrawer(sideNav, false);
});
thisItem.appendChild(thisAnchor);
list.appendChild(thisItem);
});
Expand Down

0 comments on commit 0f95768

Please sign in to comment.