Skip to content

Commit ca01d2f

Browse files
itzmekhokanafercia
authored andcommitted
Media: Fix ARIA labelling and list semantics in the media views.
The media modal labelled itself with a fixed `media-frame-title` ID that was set on the frame's heading container. In the Media Library grid that ID is claimed by the manage frame's empty heading, so the Edit attachment dialog had no accessible name, and any page that opened more than one media frame ended up with duplicate IDs. Generate the ID on the modal instance, set it directly on the frame's H1 heading, and reference it from the dialog element. Also set `role="group"` on the attachments list. Its `li` children carry `role="checkbox"`, and ARIA in HTML only allows that if the role of the list itself is changed as well. Fixes #66025.
1 parent 81e3c7f commit ca01d2f

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎src/js/media/views/attachments.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Attachments = View.extend(/** @lends wp.media.view.Attachments.prototype */{
88
className: 'attachments',
99

1010
attributes: {
11+
role: 'group',
1112
tabIndex: -1
1213
},
1314

‎src/js/media/views/media-frame.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ MediaFrame = Frame.extend(/** @lends wp.media.view.MediaFrame.prototype */{
164164
* @this wp.media.controller.Region
165165
*/
166166
createTitle: function( title ) {
167+
// A modal's dialog element points `aria-labelledby` at its frame heading.
167168
title.view = new wp.media.View({
168169
controller: this,
169-
tagName: 'h1'
170+
tagName: 'h1',
171+
attributes: this.modal ? { id: this.modal.titleId } : {}
170172
});
171173
},
172174
/**

‎src/js/media/views/modal.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,24 @@ Modal = wp.media.View.extend(/** @lends wp.media.view.Modal.prototype */{
3232
hasCloseButton: true
3333
});
3434

35+
this.titleId = _.uniqueId( 'media-frame-title-' );
36+
3537
this.focusManager = new wp.media.view.FocusManager({
3638
el: this.el
3739
});
3840
},
3941
/**
4042
* Prepares the data for the modal template.
4143
*
44+
* @since 7.2.0 Added the `titleId` property.
45+
*
4246
* @return {Object} The prepared data.
4347
*/
4448
prepare: function() {
4549
return {
4650
title: this.options.title,
47-
hasCloseButton: this.options.hasCloseButton
51+
hasCloseButton: this.options.hasCloseButton,
52+
titleId: this.titleId
4853
};
4954
},
5055

‎src/wp-includes/media-template.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function wp_print_media_templates() {
178178

179179
<?php // Template for the media frame: used both in the media grid and in the media modal. ?>
180180
<script type="text/html" id="tmpl-media-frame">
181-
<div class="media-frame-title" id="media-frame-title"></div>
181+
<div class="media-frame-title"></div>
182182
<h2 class="media-frame-menu-heading"><?php _ex( 'Actions', 'media modal menu actions' ); ?></h2>
183183
<button type="button" class="button button-link media-frame-menu-toggle" aria-expanded="false">
184184
<?php _ex( 'Menu', 'media modal menu' ); ?>
@@ -201,7 +201,7 @@ function wp_print_media_templates() {
201201

202202
<?php // Template for the media modal. ?>
203203
<script type="text/html" id="tmpl-media-modal">
204-
<div id="wp-media-modal" tabindex="0" class="<?php echo $class; ?>" role="dialog" aria-labelledby="media-frame-title">
204+
<div id="wp-media-modal" tabindex="0" class="<?php echo $class; ?>" role="dialog" aria-labelledby="{{ data.titleId }}">
205205
<# if ( data.hasCloseButton ) { #>
206206
<button type="button" class="media-modal-close"><span class="media-modal-icon" aria-hidden="true"></span><span class="screen-reader-text">
207207
<?php

0 commit comments

Comments
 (0)