WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 11 days ago

#40302 new defect (bug)

Reset password field is not auto-focused

Reported by: afercia Owned by:
Milestone: 5.3 Priority: normal
Severity: normal Version:
Component: Login and Registration Keywords: has-screenshots has-patch
Focuses: ui Cc:

Description

See also #40301 and #30023.

Although auto-focusing form fields can be arguable in some cases, I'd say it makes sense when there's a very specific task to accomplish and when there's no relevant content before the auto-focused field. In that case, the relevant content would be "skipped" for some users, see #40301.

Ideally, there should be some consistency. I see no reasons why, for example, the lost password field gets auto-focused and the reset password field doesn't.

As far as I see, this has always worked this way, even before the introduction of auto-generated password, because in the reset password screen there's no field with an user_pass ID.

With JS on, the field to focus has a pass1-text ID but the only relevant code in the page tries to target an element with the ID user_pass:

https://cldup.com/WGKMt1gJ8B.png

With JS off, well... I guess it's a bit pointless but the relevant field has a pass1 ID.

https://cldup.com/-V8oLmKKZF.png

Attachments (1)

40302.diff (704 bytes) - added by donmhico 3 weeks ago.
Patch to focus on new password field on reset password page.

Download all attachments as: .zip

Change History (3)

@donmhico
3 weeks ago

Patch to focus on new password field on reset password page.

#1 @donmhico
3 weeks ago

  • Keywords has-patch added

My patch above includes 2 changes on 2 different files.

  1. admin/user-profile.js - Inside the generatePassword() function. After the generated password was set, the new password field will be focused. The generatePassword() is also use in wp-admin/user-new.php page, but the added code below doesn't produce any unwanted behaviour.
// Focus the password field.
$($pass1Text).focus();
  1. wp-login.php - I changed login_footer( 'user_pass' ); to login_footer( 'pass1-text' );. This is to correct the target field of the code below. $input_id is the string passed in login_footer().
<script type="text/javascript">
    try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
    if(typeof wpOnload=='function')wpOnload();
</script>

Reference:
https://developer.wordpress.org/reference/functions/login_footer/

#2 @SergeyBiryukov
11 days ago

  • Milestone changed from Awaiting Review to 5.3
Note: See TracTickets for help on using tickets.