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.



git-svn-id: https://develop.svn.wordpress.org/trunk@52059 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Anthony Burchell 2021-11-08 22:47:09 +00:00
parent 99514de6bb
commit 56ff78042c
5 changed files with 19 additions and 8 deletions

View File

@ -106,16 +106,21 @@ UploaderInline = View.extend(/** @lends wp.media.view.UploaderInline.prototype *
$placeholder;
if ( this.controller.uploader ) {
$placeholder = this.$('.browser');
$placeholder = this.$('.browser-container');
// Check if we've already replaced the placeholder.
if ( $placeholder[0] === $browser[0] ) {
return;
}
$browser.detach().text( $placeholder.text() );
$browser[0].className = $placeholder[0].className;
$browser[0].setAttribute( 'aria-labelledby', $browser[0].id + ' ' + $placeholder[0].getAttribute('aria-labelledby') );
var browserLabel = $placeholder.find( 'label' );
var browserInput = $placeholder.find( 'input' );
browserLabel.attr( 'for', $browser[0].id );
browserInput.attr( 'id', $browser[0].id );
$browser.removeAttr( 'id' );
$browser.append( browserLabel ).append( browserInput );
$placeholder.replaceWith( $browser.show() );
}

View File

@ -27,7 +27,7 @@ UploaderWindow = wp.media.View.extend(/** @lends wp.media.view.UploaderWindow.pr
initialize: function() {
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 || {}, {
dropzone: this.$el,

View File

@ -2246,7 +2246,7 @@ function media_upload_form( $errors = null ) {
<div class="drag-drop-inside">
<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 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>
<?php
@ -2288,7 +2288,7 @@ function media_upload_form( $errors = null ) {
?>
</div>
<p class="max-upload-size">
<p class="max-upload-size" id="post-upload-info">
<?php
/* translators: %s: Maximum allowed file size. */
printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) );

View File

@ -133,6 +133,9 @@ TABLE OF CONTENTS:
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-secondary:focus {

View File

@ -252,7 +252,10 @@ function wp_print_media_templates() {
<div class="upload-ui">
<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>
<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 class="upload-inline-status"></div>