diff --git a/freesound/static/bw-frontend/src/components/collapsableBlock.js b/freesound/static/bw-frontend/src/components/collapsableBlock.js index f38e7f685..53eb906bd 100644 --- a/freesound/static/bw-frontend/src/components/collapsableBlock.js +++ b/freesound/static/bw-frontend/src/components/collapsableBlock.js @@ -16,9 +16,8 @@ const toggleCollapse = (toggleElement) => { collapsableContainer.classList.toggle(closeClass); const showText = toggleElement.dataset.showText; const hideText = toggleElement.dataset.hideText; - toggleElement.textContent = collapsableContainer.classList.contains(closeClass) - ? showText - : hideText; + toggleElement.ariaExpanded = collapsableContainer.classList.contains(closeClass) ? "false" : "true"; + toggleElement.textContent = collapsableContainer.classList.contains(closeClass) ? showText: hideText; } const handleCollapsable = (e) => { @@ -36,6 +35,9 @@ collapsableToggles.forEach(element => { return; // continue to next toggle element as this will not implement collapsable behaviour } } + + // Set aria expanded attribute with is true by default + element.ariaExpanded = "true"; if (element.dataset.hideOnLoad !== undefined){ toggleCollapse(element); diff --git a/freesound/static/bw-frontend/src/components/dropdown.js b/freesound/static/bw-frontend/src/components/dropdown.js index 04da69c50..ad2e6fee5 100644 --- a/freesound/static/bw-frontend/src/components/dropdown.js +++ b/freesound/static/bw-frontend/src/components/dropdown.js @@ -6,7 +6,7 @@ const closeOnClickAway = () => { const { toggle, dropdownOptions } = lastOpenedDropdown; if (toggle && dropdownOptions) { dropdownOptions.classList.remove('show'); - toggle.setAttribute('aria-expanded', 'false'); + toggle.ariaExpanded = 'false'; lastOpenedDropdown.toggle = undefined; lastOpenedDropdown.dropdownOptions = undefined; } @@ -29,7 +29,7 @@ const toggleExpandDropdown = toggle => { const dropdownOptions = dropdownContainer.getElementsByClassName('dropdown-menu')[0]; if (dropdownOptions && !isDropdownExpanded) { dropdownOptions.classList.add('show'); - toggle.setAttribute('aria-expanded', 'true'); + toggle.ariaExpanded = 'true'; lastOpenedDropdown.toggle = toggle; lastOpenedDropdown.dropdownOptions = dropdownOptions; setTimeout(() => { @@ -40,5 +40,13 @@ const toggleExpandDropdown = toggle => { }; dropdownToggles.forEach(toggle => { + toggle.ariaExpanded = 'false'; + toggle.ariaHasPopup = 'menu'; + const dropdownContainer = toggle.closest('.dropdown'); + const dropdownOptions = dropdownContainer.getElementsByClassName('dropdown-menu')[0]; + dropdownOptions.setAttribute('role', 'menu'); + dropdownOptions.getElementsByClassName('dropdown-item').forEach(item => { + item.setAttribute('role', 'menuitem'); + }); toggle.addEventListener('click', () => toggleExpandDropdown(toggle)); }); diff --git a/templates_bw/accounts/account.html b/templates_bw/accounts/account.html index baa3240b7..820e504d7 100644 --- a/templates_bw/accounts/account.html +++ b/templates_bw/accounts/account.html @@ -40,8 +40,8 @@