Skip to content

Commit

Permalink
Only register event listeners once
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Jul 29, 2024
1 parent 6da7e3f commit 4b6b3ca
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/dokka-presets/scripts/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ function ensureNavButtonInteractable() {
const navButtons = document.querySelectorAll('.navButton');

navButtons.forEach(function(navButton) {
if (navButton.hasAttribute('aria-expanded')) {
return;
}

// Make the navButton focusable, add accessibility information
navButton.setAttribute('tabindex', '0');
navButton.setAttribute('role', 'button');
Expand All @@ -95,7 +99,9 @@ function ensureNavButtonInteractable() {

// Update aria-expanded attribute on click
navButton.addEventListener('click', function() {
console.log("navButton aria-expanded: " + navButton.getAttribute('aria-expanded'))
const isExpanded = navButton.getAttribute('aria-expanded') === 'true';
console.log("navButton isExpanded: " + isExpanded)
navButton.setAttribute('aria-expanded', (!isExpanded).toString());
});
});
Expand Down

0 comments on commit 4b6b3ca

Please sign in to comment.