Skip to content

Commit e0eb90b

Browse files
committed
Media: A11y: Switch uploader toggle to button and set focus.
The control to switch between the browser uploader and the default uploader used a link with `target="_blank"`, but was driven by scripts. In a no-js context, this meant that the link could be used to open the browser uploader in a new tab. This is unnecessary, however, because the default uploader is not rendered when JS is not available. On switching uploaders, browser focus was lost. For more predictable keyboard and screen reader behavior, switch the media uploader toggle to a `button` element and set focus to the upload button in the new context. Props dilipbheda, sabernhardt, rollybueno, westonruter, joedolson. Fixes #63238. git-svn-id: https://develop.svn.wordpress.org/trunk@61099 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d5fed6b commit e0eb90b

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/js/_enqueues/vendor/plupload/handlers.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,12 @@ function switchUploader( s ) {
276276

277277
if ( typeof( uploader ) == 'object' )
278278
uploader.refresh();
279+
280+
jQuery( '#plupload-browse-button' ).trigger( 'focus' );
279281
} else {
280282
setUserSetting( 'uploader', '1' ); // 1 == html uploader.
281283
jQuery( '.media-upload-form' ).addClass( 'html-uploader' );
284+
jQuery( '#async-upload' ).trigger( 'focus' );
282285
}
283286
}
284287

@@ -420,11 +423,11 @@ jQuery( document ).ready( function( $ ) {
420423
target.parents( '.media-item' ).fadeOut( 200, function() {
421424
$( this ).remove();
422425
} );
423-
} else if ( target.is( '.upload-flash-bypass a' ) || target.is( 'a.uploader-html' ) ) { // Switch uploader to html4.
426+
} else if ( target.is( '.upload-flash-bypass button' ) || target.is( 'a.uploader-html' ) ) { // Switch uploader to html4.
424427
$( '#media-items, p.submit, span.big-file-warning' ).css( 'display', 'none' );
425428
switchUploader( 0 );
426429
e.preventDefault();
427-
} else if ( target.is( '.upload-html-bypass a' ) ) { // Switch uploader to multi-file.
430+
} else if ( target.is( '.upload-html-bypass button' ) ) { // Switch uploader to multi-file.
428431
$( '#media-items, p.submit, span.big-file-warning' ).css( 'display', '' );
429432
switchUploader( 1 );
430433
e.preventDefault();

src/wp-admin/includes/media.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,27 +3028,15 @@ function wp_media_insert_url_form( $default_view = 'image' ) {
30283028
* Displays the multi-file uploader message.
30293029
*
30303030
* @since 2.6.0
3031-
*
3032-
* @global int $post_ID
30333031
*/
30343032
function media_upload_flash_bypass() {
3035-
$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
3036-
3037-
$post = get_post();
3038-
if ( $post ) {
3039-
$browser_uploader .= '&post_id=' . (int) $post->ID;
3040-
} elseif ( ! empty( $GLOBALS['post_ID'] ) ) {
3041-
$browser_uploader .= '&post_id=' . (int) $GLOBALS['post_ID'];
3042-
}
3043-
30443033
?>
30453034
<p class="upload-flash-bypass">
30463035
<?php
30473036
printf(
3048-
/* translators: 1: URL to browser uploader, 2: Additional link attributes. */
3049-
__( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" %2$s>browser uploader</a> instead.' ),
3050-
$browser_uploader,
3051-
'target="_blank"'
3037+
/* translators: %s: HTML attributes for button. */
3038+
__( 'You are using the multi-file uploader. Problems? Try the <button %s>browser uploader</button> instead.' ),
3039+
'type="button" class="button-link"'
30523040
);
30533041
?>
30543042
</p>
@@ -3063,7 +3051,13 @@ function media_upload_flash_bypass() {
30633051
function media_upload_html_bypass() {
30643052
?>
30653053
<p class="upload-html-bypass hide-if-no-js">
3066-
<?php _e( 'You are using the browser&#8217;s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.' ); ?>
3054+
<?php
3055+
printf(
3056+
/* translators: %s: HTML attributes for button. */
3057+
__( 'You are using the browser&#8217;s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <button %s>Switch to the multi-file uploader</button>.' ),
3058+
'type="button" class="button-link"'
3059+
);
3060+
?>
30673061
</p>
30683062
<?php
30693063
}

0 commit comments

Comments
 (0)