Make WordPress Core

Changeset 59856


Ignore:
Timestamp:
02/22/2025 12:28:36 AM (8 weeks ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentyone/assets/js/primary-navigation.js

    r55124 r59856  
    120120            };
    121121        }
     122
     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        } );
    122135
    123136        /**
Note: See TracChangeset for help on using the changeset viewer.