Skip to content

Commit fe81c8f

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@51946 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 548829f commit fe81c8f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/js/_enqueues/admin/common.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,25 @@ $( function() {
16951695
}
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 ) {
17001719
if ( ! $adminmenu.data('wp-responsive') ) {

0 commit comments

Comments
 (0)