Skip to content

Commit 00ae6b8

Browse files
committed
TwentyTwentyOne: Add aria-controls attributes to primary sub-menu.
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
1 parent 165d803 commit 00ae6b8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ function twentytwentyoneExpandSubMenu( el ) { // jshint ignore:line
120120
};
121121
}
122122

123+
// Add aria-controls attributes to primary sub-menu.
124+
var subMenus = document.querySelectorAll( '.primary-menu-container .sub-menu' );
125+
subMenus.forEach( function( subMenu, index ) {
126+
var parentLi = subMenu.closest( 'li.menu-item-has-children' );
127+
subMenu.id = 'sub-menu-' + ( index + 1 );
128+
if ( parentLi ) {
129+
var parentLink = parentLi.querySelector( 'button' );
130+
if ( parentLink ) {
131+
parentLink.setAttribute( 'aria-controls', subMenu.id );
132+
}
133+
}
134+
} );
135+
123136
/**
124137
* Trap keyboard navigation in the menu modal.
125138
* Adapted from Twenty Twenty.

0 commit comments

Comments
 (0)