Make WordPress Core

Changeset 51946


Ignore:
Timestamp:
10/28/2021 05:27:04 PM (3 years ago)
Author:
joedolson
Message:

Administration: Hide mobile menu on focusout.

Closes the admin menu on mobile devices when keyboard focus moves outside of the menu or menu toggle elements. Improves the usability of the menu on mobile by allowing closure anywhere outside the menu rather than only on the toggle.

Props kaneva, costdev, sabernhardt
Fixes #53587.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/common.js

    r50547 r51946  
    16961696            } );
    16971697
     1698            // Close sidebar when focus moves outside of toggle and sidebar.
     1699            $( '#wp-admin-bar-menu-toggle, #adminmenumain' ).on( 'focusout', function() {
     1700                var focusIsInToggle, focusIsInSidebar;
     1701
     1702                if ( ! $wpwrap.hasClass( 'wp-responsive-open' ) ) {
     1703                    return;
     1704                }
     1705
     1706                // A brief delay is required to allow focus to switch to another element.
     1707                setTimeout( function() {
     1708                    focusIsInToggle  = $.contains( $( '#wp-admin-bar-menu-toggle' )[0], $( ':focus' )[0] );
     1709                    focusIsInSidebar = $.contains( $( '#adminmenumain' )[0], $( ':focus' )[0] );
     1710
     1711                    if ( ! focusIsInToggle && ! focusIsInSidebar ) {
     1712                        $( '#wp-admin-bar-menu-toggle' ).trigger( 'click.wp-responsive' );
     1713                    }
     1714                }, 10 );
     1715            } );
     1716
    16981717            // Add menu events.
    16991718            $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
Note: See TracChangeset for help on using the changeset viewer.