Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
83 changes: 82 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 = window.safari !== 'undefined' && typeof window.safari === 'object',
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,79 @@
}
}

/**
* Bind Caps Lock detection to a password input field.
*
* @param {jQuery} $input The password input field.
*/
function bindCapsLockWarning( $input ) {
var $capsWarning,
$capsIcon,
$capsText,
capsLockOn = false;

// Skip warning on macOS Safari + Firefox (they show native indicators).
if ( isMac && ( isSafari || isFirefox ) ) {
return;
}

$capsWarning = $( '<div id="caps-warning" class="caps-warning"></div>' );
$capsIcon = $( '<span class="caps-icon" aria-hidden="true"><svg viewBox="0 0 24 26" xmlns="http://www.w3.org/2000/svg" fill="#3c434a" stroke="#3c434a" 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>' );
$capsText = $( '<span>', { 'class': 'caps-warning-text', text: __( 'Caps lock is on.' ) } );
$capsWarning.append( $capsIcon, $capsText );

$input.parent( 'div' ).append( $capsWarning );

$input.on( 'keydown', function( jqEvent ) {
var event = jqEvent.originalEvent;

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

var state = isCapsLockOn( event );

// React when the state changes or if caps lock is on when the user starts typing.
if ( state !== capsLockOn ) {
capsLockOn = state;

if ( capsLockOn ) {
$capsWarning.show();
// Don't duplicate existing screen reader Caps lock notifications.
if ( event.key !== 'CapsLock' ) {
wp.a11y.speak( __( 'Caps lock is on.' ), 'assertive' );
}
} else {
$capsWarning.hide();
}
}
} );

$input.on( 'blur', function() {
if ( ! document.hasFocus() ) {
return;
}
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( event ) {
return event.getModifierState( 'CapsLock' );
}

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

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

/* Caps lock warning */
.wp-pwd .caps-warning {
display: none;
position: relative;
background: #fcf9e8;
border: 1px solid #f0c33c;
color: #1d2327;
padding: 6px 10px;
top: -8px;
}

.profile-php .wp-pwd .caps-warning {
padding: 3px 5px;
top: -4px;
border-radius: 4px;
}

.wp-pwd .caps-icon {
display: inline-flex;
justify-content: center;
width: 20px;
height: 20px;
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 Expand Up @@ -1641,6 +1672,10 @@ table.form-table td .updated p {
padding: 8px;
}

.profile-php .wp-pwd .caps-warning {
padding: 8px;
}

.password-input-wrapper {
display: block;
}
Expand Down
Loading