WordPress.org

Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#40301 new enhancement

New filter to disable auto-focus on the login screen

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

Description

On the login screen, wp_attempt_focus() tries to auto-focus the login input fields:

https://cldup.com/nwZk5Fa1my.png

By doing so, anything that comes before the input fields (e.g. the logo) will be "skipped" for keyboard users and screen reader users. While this may make sense when the login screen is the default one, it can be confusing when the login screen is customised.

Using filters and actions, plugin authors can heavily customise the login screen, adding any kind of content before the login default fields (including additional form fields). In this case, skipping all that content wouldn't be so ideal.

There are hacky ways to avoid the call to wp_attempt_focus(), like setting again the global $error and as far as I see, people are already doing that (just googled a bit and found some use cases). I'd propose to just add a more standard way to don't print out the call to wp_attempt_focus().

Worth noting the auto-focus will still work on other wp-login.php views like, for example, the lost password one. It probably makes sense to still have auto-focus where the users task is so specific.

It will also still work when there are error messages, because it is called by wp_shake_js(). For example, when entering a wrong password, I'd say it still makes sense to focus the password field.

In these two cases, I'd avoid any change. The filter should work just on the initial login screen.

Attachments (2)

40301.diff (778 bytes) - added by afercia 4 weeks ago.
Local Dev No Focus on WP Login.png (23.9 KB) - added by lukecavanagh 4 weeks ago.
Local Dev Autofocus not being set in Chrome

Download all attachments as: .zip

Change History (7)

@afercia
4 weeks ago

#1 @swissspidy
4 weeks ago

Sounds like a duplicate of #30023 to me. I'd love to fix it because the bug mentioned in that ticket is annoying.

#2 @afercia
4 weeks ago

  • Keywords has-patch added

Yep I've seen that ticket :) To me, it sounds more related to a (very annoying) Chrome specific behaviour.

40301.diff adds a new filter which defaults to true. Using it would be as simple as:
add_action( 'enable_login_autofocus', '__return_false' );

Also removes a space in a doc-block.

#3 @lukecavanagh
4 weeks ago

@afercia 

Patch applies cleanly and using the filter works as described and autofocus was not set in Chrome, when defined.

@lukecavanagh
4 weeks ago

Local Dev Autofocus not being set in Chrome

This ticket was mentioned in Slack in #accessibility by afercia. View the logs.


4 weeks ago

#5 @afercia
4 weeks ago

  • Milestone changed from Awaiting Review to 4.8

Discussed in today's accessibility meeting, moving to 4.8 as something to address maybe together with #30023.

Note: See TracTickets for help on using tickets.