Skip to content

Commit fe0427c

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60263 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 34ed22c commit fe0427c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/js/media/views/uploader/status.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ UploaderStatus = View.extend(/** @lends wp.media.view.UploaderStatus.prototype *
124124
this.views.add( '.upload-errors', statusError, { at: 0 } );
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

131134
dismiss: function() {
@@ -135,6 +138,7 @@ UploaderStatus = View.extend(/** @lends wp.media.view.UploaderStatus.prototype *
135138
_.invoke( errors, 'remove' );
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 ) {
140144
this.controller.modal.focusManager.focus();

src/wp-admin/async-upload.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@
112112

113113
$id = media_handle_upload( 'async-upload', $post_id );
114114
if ( 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
),
123125
sprintf(
@@ -127,14 +129,23 @@
127129
),
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
}
140151

0 commit comments

Comments
 (0)