From 4b6b3ca481249a6d69868d2c9d3c664714461045 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 29 Jul 2024 12:54:06 -0400 Subject: [PATCH] Only register event listeners once --- docs/dokka-presets/scripts/accessibility.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/dokka-presets/scripts/accessibility.js b/docs/dokka-presets/scripts/accessibility.js index 17e17b1614f..3b84d659424 100644 --- a/docs/dokka-presets/scripts/accessibility.js +++ b/docs/dokka-presets/scripts/accessibility.js @@ -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'); @@ -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()); }); });