Skip to content

Commit

Permalink
TwentyTwentyOne: Add aria-controls attributes to primary sub-menu.
Browse files Browse the repository at this point in the history
On the Twenty Twenty-One theme, this changeset adds `aria-controls` attribute to sub-menu buttons and an `id` to the sub-menu wrapper for additional context on what is being expanded.

Props bschneidewind, audrasjb, anandraj346.
Fixes #62973.


git-svn-id: https://develop.svn.wordpress.org/trunk@59856 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
audrasjb committed Feb 22, 2025
1 parent 165d803 commit 00ae6b8
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line
};
}

// Add aria-controls attributes to primary sub-menu.
var subMenus = document.querySelectorAll( '.primary-menu-container .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 );
}
}
} );

/**
* Trap keyboard navigation in the menu modal.
* Adapted from Twenty Twenty.
Expand Down

0 comments on commit 00ae6b8

Please sign in to comment.