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.
Built from https://develop.svn.wordpress.org/trunk@51946


git-svn-id: http://core.svn.wordpress.org/trunk@51535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2021-10-28 17:28:56 +00:00
parent acabcf82ff
commit d71ae9a7e3
3 changed files with 21 additions and 2 deletions

View File

@ -1695,6 +1695,25 @@ $( function() {
} }
} ); } );
// Close sidebar when focus moves outside of toggle and sidebar.
$( '#wp-admin-bar-menu-toggle, #adminmenumain' ).on( 'focusout', function() {
var focusIsInToggle, focusIsInSidebar;
if ( ! $wpwrap.hasClass( 'wp-responsive-open' ) ) {
return;
}
// A brief delay is required to allow focus to switch to another element.
setTimeout( function() {
focusIsInToggle = $.contains( $( '#wp-admin-bar-menu-toggle' )[0], $( ':focus' )[0] );
focusIsInSidebar = $.contains( $( '#adminmenumain' )[0], $( ':focus' )[0] );
if ( ! focusIsInToggle && ! focusIsInSidebar ) {
$( '#wp-admin-bar-menu-toggle' ).trigger( 'click.wp-responsive' );
}
}, 10 );
} );
// Add menu events. // Add menu events.
$adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) { $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
if ( ! $adminmenu.data('wp-responsive') ) { if ( ! $adminmenu.data('wp-responsive') ) {

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-51945'; $wp_version = '5.9-alpha-51946';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.