Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1cff436
Add password visibility switch to setup-config
Dec 4, 2022
610991c
Fix position differences between browsers
Dec 4, 2022
532d957
Remove aria show/hide label
Dec 4, 2022
8b9a548
Add padding so password visibility button does not overlap for rtl/lt…
Dec 4, 2022
a285e1e
Change the button width back to 40px to be consistent
Dec 4, 2022
108ce82
Change .wp-pwd back to inline-block to stay consistent
Dec 4, 2022
c727c38
Remove leftover `display: initial` from forms.css
Dec 5, 2022
5910151
Rename setup-config.js to password-toggle.js
Dec 5, 2022
ab58f95
Update password-toggle.js @output to new file name
bgoewert Dec 6, 2022
b676c71
Update #pwd-toggle to .pwd-toggle
Jan 5, 2023
5c4ab19
Update `password-toggle.js` to toggle any and all `.pwd-toggle` fields
Jan 5, 2023
a0fd4b6
Change default aria-label from "Hide" to "Show"
Jan 6, 2023
b3905ba
Reword file description for password-toggle.js
Jan 6, 2023
1240f8e
Fix spacing inside parenthesis so it's consistent
Jan 6, 2023
106d80c
Change `toggle` to `toggleElements` to imply potentially several `.pw…
Jan 6, 2023
10270a8
Change `.wp-pwd` from inline to block
Jan 6, 2023
605a8d6
Fix password-toggle.js so it correctly toggles the input that the but…
Jan 6, 2023
cf8bae6
Add `hide-if-no-js` to `setup-config.php` toggle as it is unusable w/…
Jan 6, 2023
70de2bd
Update forms.css and install.css for appropriate input padding
Jan 6, 2023
6a33173
Remove `data-pw` from setup-config.php
Jan 6, 2023
31210f9
Change `aria-label` on toggle including translation support
Jan 6, 2023
8b3997c
Change install.css selector for `padding-right` so as to not affect i…
Jan 6, 2023
304428c
Change `margin-top` to not affect top margin on profile page
Jan 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ module.exports = function(grunt) {
[ WORKING_DIR + 'wp-admin/js/plugin-install.js' ]: [ './src/js/_enqueues/admin/plugin-install.js' ],
[ WORKING_DIR + 'wp-admin/js/post.js' ]: [ './src/js/_enqueues/admin/post.js' ],
[ WORKING_DIR + 'wp-admin/js/postbox.js' ]: [ './src/js/_enqueues/admin/postbox.js' ],
[ WORKING_DIR + 'wp-admin/js/password-toggle.js' ]: [ './src/js/_enqueues/admin/password-toggle.js' ],
[ WORKING_DIR + 'wp-admin/js/revisions.js' ]: [ './src/js/_enqueues/wp/revisions.js' ],
[ WORKING_DIR + 'wp-admin/js/set-post-thumbnail.js' ]: [ './src/js/_enqueues/admin/set-post-thumbnail.js' ],
[ WORKING_DIR + 'wp-admin/js/svg-painter.js' ]: [ './src/js/_enqueues/wp/svg-painter.js' ],
Expand Down
38 changes: 38 additions & 0 deletions src/js/_enqueues/admin/password-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Adds functionality for password visibility buttons to toggle between text and password input types.
*
* @since 6.2.0
* @output wp-admin/js/password-toggle.js
*/

( function () {
var toggleElements, status, input, icon, label;

toggleElements = document.querySelectorAll( '.pwd-toggle' );

toggleElements.forEach( function (toggle) {
toggle.classList.remove( 'hide-if-no-js' );
toggle.addEventListener( 'click', togglePassword );
} );

function togglePassword() {
status = this.getAttribute( 'data-toggle' );
input = this.parentElement.children.namedItem( 'pwd' );
icon = this.getElementsByClassName( 'dashicons' )[ 0 ];
label = this.getElementsByClassName( 'text' )[ 0 ];

if ( 0 === parseInt( status, 10 ) ) {
this.setAttribute( 'data-toggle', 1 );
this.setAttribute( 'aria-label', this.getAttribute( 'data-hide-label' ) );
input.setAttribute( 'type', 'text' );
icon.classList.remove( 'dashicons-visibility' );
icon.classList.add( 'dashicons-hidden' );
} else {
this.setAttribute( 'data-toggle', 0 );
this.setAttribute( 'aria-label', this.getAttribute( 'data-show-label' ) );
input.setAttribute( 'type', 'password' );
icon.classList.remove( 'dashicons-hidden' );
icon.classList.add( 'dashicons-visibility' );
}
}
} )();
40 changes: 40 additions & 0 deletions src/wp-admin/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,46 @@ fieldset label,

.wp-pwd {
margin-top: 1em;
position: relative;
}

.wp-pwd button.pwd-toggle {
background: transparent;
border: 1px solid transparent;
box-shadow: none;
font-size: 14px;
line-height: 2;
width: 2rem;
min-width: 40px;
margin: 0;
padding: 0;
position: absolute;
right: 0;
top: 0;
}

.wp-pwd button.pwd-toggle:hover {
background: transparent;
border-color: transparent;
}

.wp-pwd button.pwd-toggle:focus {
background: transparent;
border-color: #3582c4;
border-radius: 4px;
box-shadow: 0 0 0 1px #3582c4;
/* Only visible in Windows High Contrast mode */
outline: 2px solid transparent;
}

.wp-pwd button.pwd-toggle:active {
background: transparent;
box-shadow: none;
transform: none;
}

.wp-pwd button.pwd-toggle .dashicons {
line-height: 1.375;
}

#misc-publishing-actions label {
Expand Down
8 changes: 8 additions & 0 deletions src/wp-admin/css/install.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ textarea {
padding: 3px 5px;
}

.wp-pwd {
margin-top: 0;
}

.wp-pwd input#pwd {
padding-right: 2.5rem;
}

input,
submit {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
Expand Down
10 changes: 9 additions & 1 deletion src/wp-admin/setup-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,14 @@ function setup_config_display_header( $body_classes = array() ) {
</tr>
<tr>
<th scope="row"><label for="pwd"><?php _e( 'Password' ); ?></label></th>
<td><input name="pwd" id="pwd" type="text" aria-describedby="pwd-desc" size="25" placeholder="<?php echo htmlspecialchars( _x( 'password', 'example password' ), ENT_QUOTES ); ?>" autocomplete="off" /></td>
<td>
<div class="wp-pwd">
<input name="pwd" id="pwd" type="password" class="regular-text" data-reveal="1" aria-describedby="pwd-desc" size="25" placeholder="<?php echo htmlspecialchars( _x( 'password', 'example password' ), ENT_QUOTES ); ?>" autocomplete="off" />
<button type="button" class="button pwd-toggle hide-if-no-js" data-toggle="0" data-start-masked="1" aria-label="<?php esc_attr_e( 'Show password' ); ?>" data-show-label="<?php esc_attr_e( 'Show password' ); ?>" data-hide-label="<?php esc_attr_e( 'Hide password' ); ?>" >
<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
</button>
</div>
</td>
<td id="pwd-desc"><?php _e( 'Your database password.' ); ?></td>
</tr>
<tr>
Expand All @@ -250,6 +257,7 @@ function setup_config_display_header( $body_classes = array() ) {
<p class="step"><input name="submit" type="submit" value="<?php echo htmlspecialchars( __( 'Submit' ), ENT_QUOTES ); ?>" class="button button-large" /></p>
</form>
<?php
wp_print_scripts( 'password-toggle' );
break;

case 2:
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,8 @@ function wp_default_scripts( $scripts ) {
)
);

$scripts->add( 'password-toggle', "/wp-admin/js/password-toggle$suffix.js", array(), false, 1 );

$scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 );

$scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
Expand Down