Make WordPress Core

Changeset 55124

Timestamp:
01/24/2023 12:56:13 PM (19 months ago)
Author:
audrasjb
Message:

Twenty Twenty-One: Refine primary-navigation.js behavior for anchor links.

This changeset fixes a bug where clicking on an anchor link in the content changes the state of the button that opens and closes the responsive menu. It adds a conditional to check if the clicked anchor link is inside the primary navigation menu (#site-navigation), in order to prevent content anchor links from changing the state of the button.

Known limitations: The state of the button is not reset when the browser is resized. If a menu anchor link is first clicked while on desktop width, and the browser width is reduced, the menu button will show the text "Close" even though the menu is not opened.

Props andreaboe, sabernhardt, poena, afercia, chaion07, cu121, mukesh27.
Fixes #53331.

File:
1 edited

Legend:

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

    r52213 r55124  
    173173         * @since Twenty Twenty-One 1.1
    174174         */
    175         document.addEventListener( 'click', function( event ) {
     175        document.addEventListener( 'click', function( event ) {
    176176            // If target onclick is <a> with # within the href attribute
    177             if ( event.target.hash && event.target.hash.includes( '#' ) ) {
     177            if ( event.target.hash ) {
    178178                wrapper.classList.remove( id + '-navigation-open', 'lock-scrolling' );
    179179                twentytwentyoneToggleAriaExpanded( mobileButton );
Note: See TracChangeset for help on using the changeset viewer.