diff --git a/src/js/_enqueues/lib/image-edit.js b/src/js/_enqueues/lib/image-edit.js index 253152b07b..3afbcdc812 100644 --- a/src/js/_enqueues/lib/image-edit.js +++ b/src/js/_enqueues/lib/image-edit.js @@ -244,6 +244,37 @@ return false; }, + /** + * Observes whether the popup should remain open based on focus position. + * + * @since 6.4.0 + * + * @memberof imageEdit + * + * @param {HTMLElement} el The activated control element. + * + * @return {boolean} Always returns false. + */ + monitorPopup : function(el) { + var $el = $( el ); + var $parent = document.querySelector( '.imgedit-rotate-menu-container' ); + var $toggle = document.querySelector( '.imgedit-rotate-menu-container .imgedit-rotate' ); + + setTimeout( function() { + var $focused = document.activeElement; + var $contains = $parent.contains( $focused ); + + // If $focused is defined and not inside the menu container, close the popup. + if ( $focused && ! $contains ) { + if ( 'true' === $toggle.getAttribute( 'aria-expanded' ) ) { + imageEdit.togglePopup( $toggle ); + } + } + }, 100 ); + + return false; + }, + /** * Navigate popup menu by arrow keys. * diff --git a/src/wp-admin/includes/image-edit.php b/src/wp-admin/includes/image-edit.php index 8281221eb2..5c0d3d7f39 100644 --- a/src/wp-admin/includes/image-edit.php +++ b/src/wp-admin/includes/image-edit.php @@ -63,7 +63,7 @@ function wp_image_editor( $post_id, $msg = false ) {