Media: Change upload button to a file input for better e2e targeting.

Changes the media library upload button to `input type="file"` for better end to end testing capabilities.

Props  justinahinon, joedolson, sabernhardt, audrasjb.
Fixes #54168.


Built from https://develop.svn.wordpress.org/trunk@52059


git-svn-id: http://core.svn.wordpress.org/trunk@51651 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
antpb 2021-11-08 22:49:00 +00:00
parent d00b86ff06
commit 975f56e42b
9 changed files with 26 additions and 12 deletions

View File

@ -2246,7 +2246,7 @@ function media_upload_form( $errors = null ) {
<div class="drag-drop-inside"> <div class="drag-drop-inside">
<p class="drag-drop-info"><?php _e( 'Drop files to upload' ); ?></p> <p class="drag-drop-info"><?php _e( 'Drop files to upload' ); ?></p>
<p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p> <p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p>
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p> <p class="drag-drop-buttons"><label for="plupload-browse-button" id="plupload-browse-label" class="button button-hero"><?php esc_html_e( 'Select Files' ); ?></label><input id="plupload-browse-button" type="file" class="screen-reader-text" aria-labelledby="plupload-browse-label post-upload-info" /></p>
</div> </div>
</div> </div>
<?php <?php
@ -2288,7 +2288,7 @@ function media_upload_form( $errors = null ) {
?> ?>
</div> </div>
<p class="max-upload-size"> <p class="max-upload-size" id="post-upload-info">
<?php <?php
/* translators: %s: Maximum allowed file size. */ /* translators: %s: Maximum allowed file size. */
printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) );

View File

@ -134,6 +134,9 @@ TABLE OF CONTENTS:
color: #0a4b78; color: #0a4b78;
} }
/* Support focus state on label designed as button in media uploader. */
.drag-drop-inside p.drag-drop-buttons:focus-within label.button,
.uploader-inline-content div.browser-container:focus-within label.button,
.wp-core-ui .button.focus, .wp-core-ui .button.focus,
.wp-core-ui .button:focus, .wp-core-ui .button:focus,
.wp-core-ui .button-secondary:focus { .wp-core-ui .button-secondary:focus {

File diff suppressed because one or more lines are too long

View File

@ -133,6 +133,9 @@ TABLE OF CONTENTS:
color: #0a4b78; color: #0a4b78;
} }
/* Support focus state on label designed as button in media uploader. */
.drag-drop-inside p.drag-drop-buttons:focus-within label.button,
.uploader-inline-content div.browser-container:focus-within label.button,
.wp-core-ui .button.focus, .wp-core-ui .button.focus,
.wp-core-ui .button:focus, .wp-core-ui .button:focus,
.wp-core-ui .button-secondary:focus { .wp-core-ui .button-secondary:focus {

File diff suppressed because one or more lines are too long

View File

@ -2858,16 +2858,21 @@ UploaderInline = View.extend(/** @lends wp.media.view.UploaderInline.prototype *
$placeholder; $placeholder;
if ( this.controller.uploader ) { if ( this.controller.uploader ) {
$placeholder = this.$('.browser'); $placeholder = this.$('.browser-container');
// Check if we've already replaced the placeholder. // Check if we've already replaced the placeholder.
if ( $placeholder[0] === $browser[0] ) { if ( $placeholder[0] === $browser[0] ) {
return; return;
} }
$browser.detach().text( $placeholder.text() ); var browserLabel = $placeholder.find( 'label' );
$browser[0].className = $placeholder[0].className; var browserInput = $placeholder.find( 'input' );
$browser[0].setAttribute( 'aria-labelledby', $browser[0].id + ' ' + $placeholder[0].getAttribute('aria-labelledby') );
browserLabel.attr( 'for', $browser[0].id );
browserInput.attr( 'id', $browser[0].id );
$browser.removeAttr( 'id' );
$browser.append( browserLabel ).append( browserInput );
$placeholder.replaceWith( $browser.show() ); $placeholder.replaceWith( $browser.show() );
} }
@ -6334,7 +6339,7 @@ UploaderWindow = wp.media.View.extend(/** @lends wp.media.view.UploaderWindow.pr
initialize: function() { initialize: function() {
var uploader; var uploader;
this.$browser = $( '<button type="button" class="browser" />' ).hide().appendTo( 'body' ); this.$browser = $( '<div class="browser-container">' ).hide().appendTo( 'body' );
uploader = this.options.uploader = _.defaults( this.options.uploader || {}, { uploader = this.options.uploader = _.defaults( this.options.uploader || {}, {
dropzone: this.$el, dropzone: this.$el,

File diff suppressed because one or more lines are too long

View File

@ -252,7 +252,10 @@ function wp_print_media_templates() {
<div class="upload-ui"> <div class="upload-ui">
<h2 class="upload-instructions drop-instructions"><?php _e( 'Drop files to upload' ); ?></h2> <h2 class="upload-instructions drop-instructions"><?php _e( 'Drop files to upload' ); ?></h2>
<p class="upload-instructions drop-instructions"><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p> <p class="upload-instructions drop-instructions"><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p>
<button type="button" class="browser button button-hero" aria-labelledby="post-upload-info"><?php _e( 'Select Files' ); ?></button> <div class="browser-container">
<label class="button button-hero"><?php esc_html_e( 'Select Files' ); ?></label>
<input type="file" class="browser screen-reader-text" aria-describedby="post-upload-info">
</div>
</div> </div>
<div class="upload-inline-status"></div> <div class="upload-inline-status"></div>

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-52058'; $wp_version = '5.9-alpha-52059';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.