diff --git a/docs/dokka-presets/templates/base.ftl b/docs/dokka-presets/templates/base.ftl index be60753e373..c57f7fd0bd7 100644 --- a/docs/dokka-presets/templates/base.ftl +++ b/docs/dokka-presets/templates/base.ftl @@ -86,6 +86,15 @@ navButton.setAttribute('role', 'button'); navButton.setAttribute('aria-expanded', 'false'); + // Grab the grandparent element's page ID, use it for aria-label and aria-controls + const sectionName = navButton.parentElement.parentElement.getAttribute('pageid') + // Remove the page ID suffix auto-generated by Dokka + const cleanedSectionName = sectionName.substring(0, sectionName.indexOf("////PointingToDeclaration")) + navButton.setAttribute('aria-label', cleanedSectionName); + + const sectionID = navButton.parentElement.parentElement.id + navButton.setAttribute('aria-controls', sectionID); + // Add event listener for Enter and Space keys navButton.addEventListener('keydown', function(event) { if (event.key === 'Enter' || event.key === ' ') {