Make WordPress Core

Changeset 60263


Ignore:
Timestamp:
05/29/2025 07:51:28 PM (14 months ago)
Author:
joedolson
Message:

Media: Screen reader improvements for upload media errors.

Add a screen reader announcement when a media upload fails. Also add an announcement when dismissing upload errors, and improve the labeling context of the dismiss error button to explicitly identify which error will be dismissed.

Props joedolson, navi161, yogeshbhutkar, rishavdutta.
Fixes #63114.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/media/views/uploader/status.js

    r51123 r60263  
    125125                _.delay( function() {
    126126                        buttonClose.trigger( 'focus' );
    127                         wp.a11y.speak( error.get( 'message' ), 'assertive' );
    128127                }, 1000 );
     128
     129                _.delay( function() {
     130                        wp.a11y.speak( error.get( 'message' ) );
     131                }, 1500 );
    129132        },
    130133
     
    136139                }
    137140                wp.Uploader.errors.reset();
     141                wp.a11y.speak( wp.i18n.__( 'Error dismissed.' ) );
    138142                // Move focus to the modal after the dismiss button gets removed from the DOM.
    139143                if ( this.controller.modal ) {
  • trunk/src/wp-admin/async-upload.php

    r59986 r60263  
    113113$id = media_handle_upload( 'async-upload', $post_id );
    114114if ( is_wp_error( $id ) ) {
    115         $button_unique_id = uniqid( 'dismiss-' );
    116         $message          = sprintf(
     115        $button_unique_id     = uniqid( 'dismiss-' );
     116        $error_description_id = uniqid( 'error-description-' );
     117        $message              = sprintf(
    117118                '%s <strong>%s</strong><br />%s',
    118119                sprintf(
    119                         '<button type="button" id="%s" class="dismiss button-link">%s</button>',
     120                        '<button type="button" id="%1$s" class="dismiss button-link" aria-describedby="%2$s">%3$s</button>',
    120121                        esc_attr( $button_unique_id ),
     122                        esc_attr( $error_description_id ),
    121123                        __( 'Dismiss' )
    122124                ),
     
    128130                esc_html( $id->get_error_message() )
    129131        );
     132
    130133        wp_admin_notice(
    131134                $message,
    132135                array(
     136                        'id'                 => $error_description_id,
    133137                        'additional_classes' => array( 'error-div', 'error' ),
    134138                        'paragraph_wrap'     => false,
    135139                )
    136140        );
    137         echo "<script>jQuery( 'button#{$button_unique_id}' ).on( 'click', function() {jQuery(this).parents('div.media-item').slideUp(200, function(){jQuery(this).remove();})});</script>\n";
     141
     142        $speak_message = sprintf(
     143                /* translators: %s: Name of the file that failed to upload. */
     144                __( '%s has failed to upload.' ),
     145                esc_js( $_FILES['async-upload']['name'] )
     146        );
     147
     148        echo "<script>_.delay(function() {wp.a11y.speak('" . esc_js( $speak_message ) . "');}, 1500);jQuery( 'button#{$button_unique_id}' ).on( 'click', function() {jQuery(this).parents('div.media-item').slideUp(200, function(){jQuery(this).remove();wp.a11y.speak( wp.i18n.__( 'Error dismissed.' ) );jQuery( '#plupload-browse-button' ).trigger( 'focus' );})});</script>\n";
    138149        exit;
    139150}
Note: See TracChangeset for help on using the changeset viewer.