From 16049638b9fb4b981f9f0389c6951ba25927f360 Mon Sep 17 00:00:00 2001 From: Ozgur Sar Date: Thu, 12 Nov 2026 18:46:37 +0300 Subject: [PATCH 1/2] Media: Match the DOM order of the media modal header to its visual order. Place the media modal close button and the Edit Attachment header buttons after the frame title, so that the DOM order matches the visual order for screen readers and other assistive technologies. See #66270. --- src/js/media/views/modal.js | 3 +++ src/wp-includes/media-template.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/media/views/modal.js b/src/js/media/views/modal.js index 629329ed88789..307f772854096 100644 --- a/src/js/media/views/modal.js +++ b/src/js/media/views/modal.js @@ -110,6 +110,9 @@ Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{ this.attach(); } + // Match the DOM order to the visual order: place the close button after the frame title. + this.$( '.media-frame-title' ).first().after( this.$( '.media-modal' ).children( '.media-modal-close' ) ); + // Disable page scrolling. $( 'body' ).addClass( 'modal-open' ); diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index a624b81e3187f..7b1879942994e 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -362,12 +362,12 @@ function wp_print_media_templates() { From 5d96855679dbd0eb051d635ad2b67925ac92e912 Mon Sep 17 00:00:00 2001 From: Aminul Islam Alvi Date: Sat, 21 Nov 2026 21:22:26 +0600 Subject: [PATCH 2/2] Media: Keep initial focus off the close button in the Gallery widget modal. After the close button is moved after the frame title, it becomes the first focusable element inside the media frame, so the Gallery widget would set initial focus on it instead of the first menu item. Exclude the close button from the selector to keep the previous behavior. See #66270. --- src/js/_enqueues/wp/widgets/media-gallery.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/wp/widgets/media-gallery.js b/src/js/_enqueues/wp/widgets/media-gallery.js index fe9f93cb381db..0417c2527735d 100644 --- a/src/js/_enqueues/wp/widgets/media-gallery.js +++ b/src/js/_enqueues/wp/widgets/media-gallery.js @@ -312,8 +312,9 @@ /* * Make sure focus is set inside of modal so that hitting Esc will close * the modal and not inadvertently cause the widget to collapse in the customizer. + * Skip the modal close button, which is placed after the frame title. */ - mediaFrame.$el.find( ':focusable:first' ).focus(); + mediaFrame.$el.find( ':focusable:not(.media-modal-close):first' ).focus(); }, /**