Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
b00361f
Change icon to text and fix pw mgr icon support
Jan 8, 2023
b11bc95
Merge branch 'trunk'
Jan 8, 2023
82be788
Remove unneeded `margin: 0` from `.pwd-toggle`. Margin is already set…
Jan 8, 2023
ca73852
Fix password strength result and button height
Jan 8, 2023
f1c7a78
Remove unnecessary `.pwd-toggle` styles from forms.css
Jan 14, 2023
65c0011
Re-add icon to button for consistency
Jan 14, 2023
5c77e9f
Increase input size slightly to allow for pwd-toggle. Also fixes orph…
Jan 14, 2023
bb2f668
Merge branch 'trunk'
Jan 21, 2023
359b3c6
Revert `.pwd-toggle` to default button width/padding
Jan 21, 2023
bef447e
Fix input width on narrow screens and update `calc()` based on revers…
Jan 21, 2023
a48daba
Merge branch 'trunk'
Jan 21, 2023
c7d4314
Reorder `password-toggle.js` in gruntfile so it is listed alphabetica…
Jan 31, 2023
f2fb3ff
Update `script-loader.php` to group `password-toggle` near `password-…
Feb 1, 2023
e71bd9f
Remove `display: flex` from forms.css that was causing the `wp-login.…
Feb 1, 2023
86e33e0
Add fixed width to toggle button
Feb 1, 2023
6c1b2fd
Add `.password-input-wrapper` with `display: inline-block` to forms.css.
Feb 1, 2023
570df33
Merge branch 'trunk'
Feb 1, 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 @@ -276,6 +276,7 @@ module.exports = function(grunt) {
[ WORKING_DIR + 'wp-admin/js/media.js' ]: [ './src/js/_enqueues/admin/media.js' ],
[ WORKING_DIR + 'wp-admin/js/nav-menu.js' ]: [ './src/js/_enqueues/lib/nav-menu.js' ],
[ WORKING_DIR + 'wp-admin/js/password-strength-meter.js' ]: [ './src/js/_enqueues/wp/password-strength-meter.js' ],
[ WORKING_DIR + 'wp-admin/js/password-toggle.js' ]: [ './src/js/_enqueues/admin/password-toggle.js' ],
[ 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' ],
Expand Down
40 changes: 40 additions & 0 deletions src/js/_enqueues/admin/password-toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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, __ = wp.i18n.__;

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', __( 'Hide password' ) );
input.setAttribute( 'type', 'text' );
label.innerHTML = __( 'Hide' );
icon.classList.remove( 'dashicons-visibility' );
icon.classList.add( 'dashicons-hidden' );
} else {
this.setAttribute( 'data-toggle', 0 );
this.setAttribute( 'aria-label', __( 'Show password' ) );
input.setAttribute( 'type', 'password' );
label.innerHTML = __( 'Show' );
icon.classList.remove( 'dashicons-hidden' );
icon.classList.add( 'dashicons-visibility' );
}
}
} )();
15 changes: 15 additions & 0 deletions src/wp-admin/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,17 @@ fieldset label,

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

.wp-pwd button {
height: min-content;
width: 4.875rem;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed width buttons can be trouble in other languages.

Spanish overflows a little:
setup-config in Spanish

Malayalam overflows a lot:
setup-config in Malayalam

}

.wp-pwd button.pwd-toggle .dashicons {
position: relative;
top: 0.25rem
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

}

#misc-publishing-actions label {
Expand Down Expand Up @@ -593,6 +604,10 @@ fieldset label,
opacity: 1;
}

.password-input-wrapper {
display: inline-block;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be inline-block at smaller sizes. It seems fine on setup-config.php, but it changes both the Installation and Profile screens.

Installation:
installation screen at 500 pixels wide

Profile:
profile screen at 500 pixels wide

}

.password-input-wrapper input {
font-family: Consolas, Monaco, monospace;
}
Expand Down
14 changes: 12 additions & 2 deletions src/wp-admin/css/install.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ textarea {
font-size: 14px;
text-align: left;
padding: 10px 20px 10px 0;
width: 140px;
width: 115px;
vertical-align: top;
}

Expand All @@ -151,6 +151,10 @@ textarea {
padding: 3px 5px;
}

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

input,
submit {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
Expand All @@ -161,7 +165,7 @@ submit {
.form-table input[type=url],
.form-table input[type=password],
#pass-strength-result {
width: 218px;
width: 230px;
}

.form-table th p {
Expand Down Expand Up @@ -242,6 +246,12 @@ body.rtl,
}
}

@media screen and (min-width: 783px) {
.wp-pwd input#pwd {
width: calc(230px - 5.125rem);
}
}

@media screen and (max-width: 782px) {

.form-table {
Expand Down
6 changes: 4 additions & 2 deletions src/wp-admin/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ function display_setup_form( $error = null ) {
<td>
<div class="wp-pwd">
<?php $initial_password = isset( $_POST['admin_password'] ) ? stripslashes( $_POST['admin_password'] ) : wp_generate_password( 18 ); ?>
<input type="password" name="admin_password" id="pass1" class="regular-text" autocomplete="new-password" spellcheck="false" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
<span class="password-input-wrapper">
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A div could be set to inline-block, if appropriate, to avoid putting the password-strength div inside a span.

<input type="password" name="admin_password" id="pass1" class="regular-text" autocomplete="new-password" spellcheck="false" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
<div id="pass-strength-result" aria-live="polite"></div>
</span>
<button type="button" class="button wp-hide-pw hide-if-no-js" data-start-masked="<?php echo (int) isset( $_POST['admin_password'] ); ?>" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
<span class="dashicons dashicons-hidden"></span>
<span class="text"><?php _e( 'Hide' ); ?></span>
</button>
<div id="pass-strength-result" aria-live="polite"></div>
</div>
<p><span class="description important hide-if-no-js">
<strong><?php _e( 'Important:' ); ?></strong>
Expand Down
11 changes: 10 additions & 1 deletion src/wp-admin/setup-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,15 @@ 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" spellcheck="false" /></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" spellcheck="false" />
<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' ); ?>">
<span class="dashicons dashicons-visibility"></span>
<span class="text"><?php _e( 'Show' ); ?></span>
</button>
</div>
</td>
<td id="pwd-desc"><?php _e( 'Your database password.' ); ?></td>
</tr>
<tr>
Expand All @@ -250,6 +258,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: 1 addition & 1 deletion src/wp-admin/user-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,12 @@
<?php $initial_password = wp_generate_password( 24 ); ?>
<span class="password-input-wrapper">
<input type="password" name="pass1" id="pass1" class="regular-text" autocomplete="new-password" spellcheck="false" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
</span>
<button type="button" class="button wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
<span class="dashicons dashicons-hidden" aria-hidden="true"></span>
<span class="text"><?php _e( 'Hide' ); ?></span>
</button>
<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
</div>
</td>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@ function wp_default_scripts( $scripts ) {
);
$scripts->set_translations( 'password-strength-meter' );

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

$scripts->add( 'application-passwords', "/wp-admin/js/application-passwords$suffix.js", array( 'jquery', 'wp-util', 'wp-api-request', 'wp-date', 'wp-i18n', 'wp-hooks' ), false, 1 );
$scripts->set_translations( 'application-passwords' );

Expand Down