Skip to content

Instantly share code, notes, and snippets.

@gbissland
Created June 28, 2024 20:24
Show Gist options
  • Save gbissland/94bbb26c679098ac1ef86694ae23722d to your computer and use it in GitHub Desktop.
Save gbissland/94bbb26c679098ac1ef86694ae23722d to your computer and use it in GitHub Desktop.
Fixes accessibility in BB for empty menu and site links by adding role="button"
// Select all elements with class 'fl-button' that do not have an href attribute starting with '#'
// These are considered real links, not buttons.
const notButtons = document.querySelectorAll('a.fl-button:not([href^="#"])');
// Remove the 'role' attribute from all selected real link elements.
for (let i = 0; i < notButtons.length; i++) {
notButtons[i].removeAttribute('role');
}
// Select all elements with an href attribute starting with '#', including menu items with such links.
// These are considered buttons or menu items acting as buttons.
const buttonsAndMenuItems = document.querySelectorAll('a[href^="#"], li.menu-item a[href^="#"]');
// Add the 'role' attribute with value 'button' to all selected button and menu item elements.
for (let i = 0; i < buttonsAndMenuItems.length; i++) {
buttonsAndMenuItems[i].setAttribute('role', 'button');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment