Skip to content

Commit

Permalink
add aria-controls
Browse files Browse the repository at this point in the history
  • Loading branch information
bschneidewind committed Feb 11, 2025
1 parent c95f05d commit 7384114
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/wp-content/themes/twentyfifteen/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
}
initMainNavigation( $( '.main-navigation' ) );

// Add unique ID to each .sub-menu and aria-controls to parent links
function addUniqueIDToSubMenus() {
var subMenus = document.querySelectorAll( '.main-navigation .sub-menu' );
subMenus.forEach( function( subMenu, index ) {
var parentLi = subMenu.closest( 'li.menu-item-has-children' );
subMenu.id = 'sub-menu-' + (index + 1);
if ( parentLi ) {
var parentLink = parentLi.querySelector( 'button' );
if ( parentLink ) {
parentLink.setAttribute( 'aria-controls', subMenu.id );
}
}
} );
}

addUniqueIDToSubMenus();

// Re-initialize the main navigation when it is updated, persisting any existing submenu expanded states.
$( document ).on( 'customize-preview-menu-refreshed', function( e, params ) {
if ( 'primary' === params.wpNavMenuArgs.theme_location ) {
Expand Down

0 comments on commit 7384114

Please sign in to comment.