Make WordPress Core

Changeset 61099


Ignore:
Timestamp:
10/30/2025 10:30:18 PM (12 months ago)
Author:
joedolson
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/vendor/plupload/handlers.js

    r59960 r61099  
    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}
    … …  
    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 );
  • trunk/src/wp-admin/includes/media.php

    r61098 r61099  
    30293029 *
    30303030 * @since 2.6.0
    3031  *
    3032  * @global int $post_ID
    30333031 */
    30343032function 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        ?>
    … …  
    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
Note: See TracChangeset for help on using the changeset viewer.