Make WordPress Core

Opened 6 weeks ago

Last modified 2 days ago

#66270 new defect (bug)

Fix DOM and visual order mismatch in the various media dialogs

Reported by: afercia Owned by:
Priority: normal Milestone: 7.3
Component: Media Version:
Severity: normal Keywords: has-screenshots has-patch needs-testing
Cc: Focuses: accessibility

Description

In the various media dialog, the buttons in the top toolbar come first in the DOM order but they are visually placed after the main dialog heading on the left.

This introduces a mismatch between the DOM order and visual order that is an accessibility barrier for screen reader users. Note that this has nothing to do with Tab keyboard navigation. Rather, it's about navigating content with arrows keys or other screen readers navigation mechanisms (e.g. 'read all').

Worth also noting that any other software will get the order mismatch, including AI agents.

For example in the Media Library 'Edit attachments' modal dialog, the edit-media-header element, which contains the 3 buttons Previous, Next, and Close, comes before the media-frame-title element, which contains the H1 heading. As such, when navigating content following the DOM source there is a mismatch between the DOM and the visual order.

Same in the media dialog, where the media-modal-close button is before the H1 heading in the DOM.

It's also worth noting that now that initial focus is set on the modal dialog element, there is no need for the buttons to be the first thing within the dialog.

Attachments (6)

01 order.png​ (396.5 KB ) - added by afercia 6 weeks ago.
Screenshot to better illustrate the order issue
media-modal-dom-order.png​ (49.4 KB ) - added by iamchitti 6 weeks ago.
before-pr15949-1.png​ (588.3 KB ) - added by ozgursar 6 days ago.
Before PR15949 (media edit modal)
before-pr15949-2.png​ (878.8 KB ) - added by ozgursar 6 days ago.
Before PR15949 (add media modal)
after-pr15949-1.png​ (604.7 KB ) - added by ozgursar 6 days ago.
After PR15949 (media edit modal)
after-pr15949-2.png​ (803.6 KB ) - added by ozgursar 6 days ago.
After PR15949 (add media modal)

Change History (14)

@afercia
6 weeks ago

Screenshot to better illustrate the order issue

#1 @iamchitti
6 weeks ago

I can reproduce this on trunk. Both templates live in src/wp-includes/media-template.php:

  • tmpl-edit-attachment-frame: the prev/next/close buttons come before the title. Same as in 01 order.png.
  • tmpl-media-modal: the close button comes before .media-modal-content, so it's read before the H1.


The buttons are absolutely positioned, so I think just moving the markup around should fix it without any visual change. I'll open a PR for this.

@afercia, one question: in the media modal, the H1 is rendered by the frame view, but the close button is part of the modal template. The simplest fix puts the close button at the very end of the dialog. Would that be fine, or would you rather have it right after the heading? The second option needs some JS changes.

#2 @afercia
6 weeks ago

@iamchitti thanks for looking into this.

Unfortunately we can't just move the Close button at the very end, as that would still produce an order mismatch.

This ticket was mentioned in ​PR #14196 on ​WordPress/wordpress-develop by ​@iamchitti.


5 weeks ago
#3

  • Keywords has-patch added

Moves the Close and navigation buttons after the dialog heading in the DOM, so screen readers read them in the same order they appear on screen.

Back-compat: a plugin that overrides tmpl-media-frame would no longer get a Close button in the modal.

Screenshots

Numbers show DOM order.

Before After
Media modal https://github.com/user-attachments/assets/7cffdb2c-b953-4be1-a356-2161df58af59 https://github.com/user-attachments/assets/62d8abea-5f81-4deb-afd7-e14b1aa65d2d
Attachment details https://github.com/user-attachments/assets/3e97f6f9-8c41-4cdc-a399-1a90180f4990 https://github.com/user-attachments/assets/0f27b733-77e1-4fbb-9a00-2426c7594db7

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigation, implementation.

This ticket was mentioned in ​Slack in #core-test by huzaifaalmesbah. ​View the logs.


7 days ago

This ticket was mentioned in ​PR #15949 on ​WordPress/wordpress-develop by ​@ozgursar.


6 days ago
#5

In the media modals, the header buttons come before the heading in the DOM but are displayed after it. This creates a mismatch between DOM order and visual order for screen reader users navigating content (arrow keys, "read all").

  • Edit Attachment modal: .media-frame-title now comes before .edit-media-header (Previous, Next, Close) in tmpl-edit-attachment-frame.
  • Media modal: when the modal opens, its close button is moved directly after .media-frame-title. Modals without a frame title keep the current markup, so custom wp.media.view.Modal usages are unaffected.

All of these buttons are absolutely positioned, so the visual layout is unchanged.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Code analysis, implementation and PR description; reviewed by me.

---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with ​Claude Code

@ozgursar
6 days ago

Before PR15949 (media edit modal)

@ozgursar
6 days ago

Before PR15949 (add media modal)

@ozgursar
6 days ago

After PR15949 (media edit modal)

@ozgursar
6 days ago

After PR15949 (add media modal)

#6 @ozgursar
6 days ago

  • Keywords needs-testing added

Test Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/15949

Environment

  • WordPress: 7.2-beta5-65392-src
  • Subdirectory: No
  • PHP: 8.4.23
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.4.23)
  • Browser: Chrome 156.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.5
  • MU Plugins:
    • Fix Docker Loopback Requests 1.0.0
  • Plugins:
    • Test Reports 1.3.1

Steps taken

  1. Open an image present in the Media Library
  2. Observe the source code and confirm that div.media-frame-title appears after div.edit-media-header which causes the order mismatch in DOM
  3. To test the add media modal, try to add a featured image to a post and view the same mismatch in the DOM
  4. Apply the patch
  5. Repeat steps 2 and 3 and observe that div.media-frame-title appears before div.edit-media-header, which fixes the DOM order mismatch issue
  6. ✅ Patch is solving the problem

Expected result

  • Title should appear before the buttons in the DOM

Screenshots/Screencast with results

Before
https://core.trac.wordpress.org/raw-attachment/ticket/66270/before-pr15949-1.png

https://core.trac.wordpress.org/raw-attachment/ticket/66270/before-pr15949-2.png

After
https://core.trac.wordpress.org/raw-attachment/ticket/66270/after-pr15949-1.png

https://core.trac.wordpress.org/raw-attachment/ticket/66270/after-pr15949-2.png

#7 @369work
6 days ago

Test Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/15949

Environment (WordPress Contributor Toolkit 2.0.0; before and after applying the PR on the same site)

  • WordPress: 7.2-beta5-20261113.210748 (7.2-beta5-20261113.214123 after applying the PR)
  • Subdirectory: No
  • PHP: 8.4.25
  • Server: PHP.wasm
  • Database: WP_MySQL_On_SQLite (Server: 8.0.38-mysql-on-sqlite-3.0.2 / Client: 3.51.0)
  • Browser: Chrome 157.0.0.0
  • OS: Windows 10/11
  • Theme: Ipsum 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.3.1
  • WP_DEBUG: true
  • SCRIPT_DEBUG: true
  • Screen reader: NVDA 2026.3.1jp (2026.3.1.6813)

Steps taken

  1. Add four images to the Media Library (grid view)
  2. A: In the Media Library, click an image to open the "Attachment details" dialog
  3. B: In the post editor (block editor), click "Set featured image" to open the "Featured image" dialog
  4. C: Close the dialog from B with Esc, then open it again
  5. For each dialog, record:
    • The order NVDA reads the dialog in when it opens, captured with the NVDA Speech Viewer
    • The DOM order of the headings and buttons inside the dialog, and their positions on screen (getBoundingClientRect()), from the DevTools console (with NVDA turned off)
  6. Apply PR 15949 in the Toolkit, hard-reload (Ctrl+F5), and repeat steps 2–5

Results

What NVDA read when each dialog opened:

Before After
A: Attachment details Previous → Next → Close → Attachment details Attachment details → Previous → Next → Close
B: Featured image Close → Featured image Featured image → Close
C: B opened again Close → Featured image Featured image → Close
  • Before the patch, the buttons were read before the heading in both dialogs (reproduced).
  • After the patch, the heading was read first, followed by the buttons. The DOM order in DevTools matched what NVDA read (below).

DOM order from the DevTools console (the first four headings and buttons inside each dialog):

A: Attachment details
  Before: button.left "Previous" → button.right "Next" → button.media-modal-close "Close" → h1 "Attachment details"
  After:  h1 "Attachment details" → button.left "Previous" → button.right "Next" → button.media-modal-close "Close"

B: Featured image (same for C)
  Before: button.media-modal-close "Close" → h1 "Featured image" → button.media-menu-item "Upload files" → button.media-menu-item "Media Library"
  After:  h1 "Featured image" → button.media-modal-close "Close" → button.media-menu-item "Upload files" → button.media-menu-item "Media Library"
  • In C, the close button stayed after the heading when the dialog was opened a second time.
  • The positions of the heading and the buttons on screen (x, y, width, height) were the same before and after the patch, so nothing changed visually.
  • Right after a dialog opened, focus was on the dialog element (div.media-modal), both before and after the patch.
  • ✅ In the two dialogs I tested, the patch makes the DOM order match the visual order.

Notes

  • I only tested the two dialogs above. I did not test other media dialogs, such as creating a gallery or "Add Media" in the classic editor.
  • I compared what NVDA read when each dialog opened. I could not capture what NVDA read when moving through the dialog with the arrow keys or Tab, so I did not test that.
  • I did not test other screen readers or other browsers.

---
AI assistance: Yes
Tool(s): Claude Code
Used for: I did the testing together with Claude Code, which suggested the steps and wrote the console script. I carried out every step and checked the results myself. Claude Code translated this report into English, and I reviewed its contents.

#8 @sabernhardt
2 days ago

  • Milestone 7.2 → 7.3

Moving to the next cycle because RC1 is within 24 hours.

Note: See TracTickets for help on using tickets.