Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8819b84
Add caps lock warning on login screen
Apr 23, 2025
f830460
Fix javaScript coding standards
Apr 23, 2025
1904fad
Added caps warning for Add/Edit Users password field
nikunj8866 May 8, 2025
245a022
Changed warning color and bypass warning in macOS
nikunj8866 May 14, 2025
9144551
Changed notification color to yellow, Added screen readers capabiliti…
nikunj8866 Jun 9, 2025
4627c8f
Optimize JS code to remove identical code
nikunj8866 Jun 9, 2025
d0f71eb
Remove mac chrome from the skip
nikunj8866 Jul 4, 2025
1930260
update js doc comment
nikunj8866 Jul 4, 2025
eb15fdf
fix browser detection issue for macOS and disable checking capslock f…
nikunj8866 Sep 9, 2025
6fe7673
update comment text
nikunj8866 Sep 9, 2025
21e4ed9
Merge branch 'trunk' into pr/8726
joedolson Sep 19, 2025
0543ef5
hide warning when capslock off and fix popup design
nikunj8866 Sep 22, 2025
42d5822
Merge branch 'trunk' into pr/8726
joedolson Oct 17, 2025
325b0ef
Incorporate suggestions from @westonruter
joedolson Oct 19, 2025
a136b18
Caps lock warning improvements
joedolson Oct 19, 2025
cee70c6
Adjust profile page styles to merge better with existing styling.
joedolson Oct 19, 2025
3a1f38e
Fix Safari test so it doesn't return true on Chrome
joedolson Oct 19, 2025
8c2362f
Missing var declarations
joedolson Oct 19, 2025
113498e
Change function description to be declarative.
joedolson Oct 19, 2025
af58caf
Update padding on mobile to match password strength
joedolson Oct 19, 2025
bee36ea
Only fire blur within the same document.
joedolson Oct 19, 2025
5f51e28
Update src/js/_enqueues/admin/user-profile.js
joedolson Oct 20, 2025
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
75 changes: 74 additions & 1 deletion src/js/_enqueues/admin/user-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
$form,
originalFormContent,
$passwordWrapper,
successTimeout;
successTimeout,
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false,
ua = navigator.userAgent.toLowerCase(),
isSafari = ua.indexOf( 'safari' ) !== -1 && ua.indexOf( 'chrome' ) === -1,
isFirefox = ua.indexOf( 'firefox' ) !== -1;

function generatePassword() {
if ( typeof zxcvbn !== 'function' ) {
Expand Down Expand Up @@ -80,6 +84,8 @@
$pass1.removeClass( 'short bad good strong' );
showOrHideWeakPasswordCheckbox();
} );

bindCapsLockWarning( $pass1 );
}

function resetToggle( show ) {
Expand Down Expand Up @@ -213,6 +219,8 @@
} else {
// Password field for the login form.
$pass1 = $( '#user_pass' );

bindCapsLockWarning( $pass1 );
}

/*
Expand Down Expand Up @@ -332,6 +340,71 @@
}
}

/**
* Binds Caps Lock detection to a given password input field.
*
* @param {jQuery} $input The password input field.
*/
function bindCapsLockWarning( $input ) {
var $capsWarning = $( '#caps-warning' ),
capsLockOn = false;

Comment thread
joedolson marked this conversation as resolved.
$input.on( 'keydown', function( e ) {
var ev = e.originalEvent || e;
Comment thread
joedolson marked this conversation as resolved.
Outdated
Comment thread
joedolson marked this conversation as resolved.
Outdated

// Skip CapsLock key itself.
if ( ev.key === 'CapsLock' ) {
return;
}

// Skip if key is not a printable character.
// Key length > 1 usually means non-printable (e.g., "Enter", "Tab").
if ( ev.ctrlKey || ev.metaKey || ev.altKey || ! ev.key || ev.key.length !== 1 ) {
return;
}

var state = isCapsLockOn( ev );

// Only react when the state changes.
if ( state !== capsLockOn ) {
capsLockOn = state;

if ( capsLockOn ) {
$capsWarning.show();
wp.a11y.speak( __( 'Caps lock is on.' ) );
} else {
$capsWarning.hide();
}
}
Comment thread
nikunj8866 marked this conversation as resolved.
} );

$input.on( 'blur', function() {
capsLockOn = false;
$capsWarning.hide();
} );
}

/**
* Determines if Caps Lock is currently enabled.
*
* On macOS Safari and Firefox, the native warning is preferred,
* so this function returns false to suppress custom warnings.
*
* @param {KeyboardEvent} e The keydown event object.
*
* @return {boolean} True if Caps Lock is on, false otherwise.
*/
function isCapsLockOn( e ) {
Comment thread
joedolson marked this conversation as resolved.
Outdated
// Skip warning on macOS Safari + Firefox (they show native indicators).
if ( isMac && ( isSafari || isFirefox ) ) {
return false;
}
Comment thread
joedolson marked this conversation as resolved.
Outdated

if ( typeof e.getModifierState === 'function' ) {
return e.getModifierState( 'CapsLock' );
}
Comment thread
joedolson marked this conversation as resolved.
Outdated
Comment thread
joedolson marked this conversation as resolved.
Outdated
}

function showOrHideWeakPasswordCheckbox() {
var passStrengthResult = $('#pass-strength-result');

Expand Down
55 changes: 55 additions & 0 deletions src/wp-admin/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,61 @@ fieldset label,
display: inline-block;
}

/* Caps lock warning */
.wp-pwd .caps-warning {
display: none;
position: absolute;
background: #FFFDD6;
border: 1px solid #ddd;
border-radius: 3px;
color: #1E1E20;
font-size: 13px;
padding: 6px 10px;
top: calc(100% - 25px);
left: 24px;
white-space: nowrap;
z-index: 10;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

Comment thread
nikunj8866 marked this conversation as resolved.
.wp-pwd .caps-warning::before {
content: '';
position: absolute;
bottom: 100%;
left: 15px;
margin-left: -8px;
border-width: 8px;
border-style: solid;
border-color: transparent transparent #ddd transparent;
}

.wp-pwd .caps-warning::after {
content: '';
position: absolute;
bottom: 100%;
left: 15px;
margin-left: -7px;
border-width: 7px;
border-style: solid;
border-color: transparent transparent #FFFDD6 transparent;
}

.wp-pwd .caps-icon {
display: inline-flex;
justify-content: center;
background-color: #FFF972;
width: 20px;
height: 20px;
border-radius: 3px;
margin-right: 5px;
vertical-align: middle;
}

.wp-pwd .caps-warning-text {
vertical-align: middle;
}
/* Caps lock warning */

p.search-box {
display: flex;
flex-wrap: wrap;
Expand Down
9 changes: 9 additions & 0 deletions src/wp-admin/user-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,15 @@
<span class="dashicons dashicons-no" aria-hidden="true"></span>
<span class="text"><?php _e( 'Cancel' ); ?></span>
</button>
<div id="caps-warning" class="caps-warning">
<span class="caps-icon">
<svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg" fill="#2c3338" stroke="#2c3338" stroke-width="0.5">
<path d="M12 5L19 15H16V19H8V15H5L12 5Z"/>
<rect x="8" y="21" width="8" height="1.5" rx="0.75"/>
</svg>
</span>
<span class="caps-warning-text"><?php _e( 'Caps lock is on.' ); ?></span>
</div>
</div>
</td>
</tr>
Expand Down
9 changes: 9 additions & 0 deletions src/wp-admin/user-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,15 @@
<span class="dashicons dashicons-hidden" aria-hidden="true"></span>
<span class="text"><?php _e( 'Hide' ); ?></span>
</button>
<div id="caps-warning" class="caps-warning">
<span class="caps-icon">
<svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg" fill="#2c3338" stroke="#2c3338" stroke-width="0.5">
<path d="M12 5L19 15H16V19H8V15H5L12 5Z"/>
<rect x="8" y="21" width="8" height="1.5" rx="0.75"/>
</svg>
</span>
<span class="caps-warning-text"><?php _e( 'Caps lock is on.' ); ?></span>
</div>
</div>
</td>
</tr>
Expand Down
9 changes: 9 additions & 0 deletions src/wp-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,15 @@ function wp_login_viewport_meta() {
<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Show password' ); ?>">
<span class="dashicons dashicons-visibility" aria-hidden="true"></span>
</button>
<div id="caps-warning" class="caps-warning">
<span class="caps-icon">
<svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg" fill="#2c3338" stroke="#2c3338" stroke-width="0.5">
<path d="M12 5L19 15H16V19H8V15H5L12 5Z"/>
<rect x="8" y="21" width="8" height="1.5" rx="0.75"/>
</svg>
</span>
<span class="caps-warning-text"><?php _e( 'Caps lock is on.' ); ?></span>
</div>
</div>
</div>
<?php
Expand Down
Loading