Make WordPress Core

Changeset 63612


Ignore:
Timestamp:
09/14/2026 09:12:31 AM (2 months ago)
Author:
afercia
Message:

Media: Fix accessibility violations reported by Axe-core.

  • Fixes the labelling of the media modal dialog.
  • Fixes the semantics of the attachments browser list: given each attachment has a role=checkbox, the list itself must have a role=group.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13368

Props khokansardar, arkaprabhachowdhury, afercia.
Fixes #66025.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/media/views/attachments.js

    r63598 r63612  
    99
    1010        attributes: {
     11                role:     'group',
    1112                tabIndex: -1
    1213        },
  • trunk/src/js/media/views/media-frame.js

    r63598 r63612  
    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        },
  • trunk/src/js/media/views/modal.js

    r63598 r63612  
    3333                });
    3434
     35                this.titleId = _.uniqueId( 'media-frame-title-' );
     36
    3537                this.focusManager = new wp.media.view.FocusManager({
    3638                        el: this.el
    … …  
    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         */
    … …  
    4549                return {
    4650                        title:          this.options.title,
    47                         hasCloseButton: this.options.hasCloseButton
     51                        hasCloseButton: this.options.hasCloseButton,
     52                        titleId:        this.titleId
    4853                };
    4954        },
  • trunk/src/wp-includes/media-template.php

    r62819 r63612  
    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">
    … …  
    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">
Note: See TracChangeset for help on using the changeset viewer.