Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The URL http://www.example.com/user/login will display a page, where the email address is focused. However http://www.example.com/user/register does not focus the email field.
/core/modules/user/src/AccountForm.php
Proposed change. Change:
'email',
'#title' => $this->t('Email address'),
'#description' => $this->t('A valid email address. All emails from the system will be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.'),
'#required' => !(!$account->getEmail() && $user->hasPermission('administer users')),
'#default_value' => (!$register ? $account->getEmail() : ''),
);
to:
'email',
'#title' => $this->t('Email address'),
'#description' => $this->t('A valid email address. All emails from the system will be sent to this address. The email address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by email.'),
'#required' => !(!$account->getEmail() && $user->hasPermission('administer users')),
'#default_value' => (!$register ? $account->getEmail() : ''),
'#attributes' => array(
'autofocus' => 'autofocus'
),
);
Notice the autofocus attribute.
Comment | File | Size | Author |
---|---|---|---|
#8 | Afterpatch.png | 199.94 KB | Dinesh18 |
#8 | Before patch.png | 185.88 KB | Dinesh18 |
#5 | interdiff3_5.txt | 835 bytes | Munavijayalakshmi |
#5 | inconsistent_user-2861374-5.patch | 895 bytes | Munavijayalakshmi |
#3 | inconsistent_user-2861374-3.patch | 900 bytes | yogeshmpawar |
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedIf this could be considered a bug it could go in 8.3.x.
I've given up on the tagging instructions.
Comment #3
yogeshmpawarPatch for the solution of this issue.
Comment #4
CatsFromStonehenge CreditAttribution: CatsFromStonehenge commentedThanks Cilefen + Yogesh. Looks good.
Comment #5
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commenteduse short array syntax (new coding standard).
Fixed the short array syntax error and attached new patch.
Comment #6
idebr CreditAttribution: idebr at ezCompany commentedComment #7
yogeshmpawarAny Update on this issue ?
Comment #8
Dinesh18 CreditAttribution: Dinesh18 as a volunteer commentedI have manually applied the patch, mentioned in comment #5 and it works as expected.
PFA before and after patch screengrab.
Looks like RTBC.
Comment #9
alexpottWe don't auto focus on the first field of the node add form. Auto focus can be a bit tricky and needs careful consideration - see #2096347: Add "autofocus" attribute to the module search and more discussion on https://ux.stackexchange.com/questions/60026/when-is-it-appropriate-to-a...
Specifically:
From #2096347-7: Add "autofocus" attribute to the module search
Comment #10
alexpottI've pinged @yoroy about this issue for usability maintainer input. For me this is a "works as designed" or "won't fix" issue.
Comment #11
yoroy CreditAttribution: yoroy commentedSeems correct to say that this is inconsistent. Reading through the issues @alexpott linked, the heuristic is:
There's also the consideration of there being help text above the focussed form field that would be skipped when applying auto focus. In this case there isn't any help text to be missed so not an issue here.
The autofocus on /user/login seems ok, there's only 1 task at hand and only 2 form fields. The form on /user/register is quite a bit bigger and while this is also mostly about 1 task as well ("registering") I really want to be cautious here and prioritize clarity over efficiency.
So I also think this is a "works as designed". I'm assigning to @andrewmacpherson, I think he should make the call on this.
Comment #12
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commented@yoroy - I'd prefer to avoid autofocus on the
user/register
form.The main problem I see with autofocus, is that it bypasses our error messages area, and a user with a screen reader may be unaware of the message.
With a screen reader, when I first load the login page, the first thing that happens is that the
<title>
gets announced, followed by the autofocus field (type, label, current value, and description).After submitting the form, if there's a login problem, we get an error message marked up with role="alert". In theory these should be announced (they are a special case of aria-live region) but in most cases screenreaders don't actually do so; in practice they only announce the message if it changes dynamically. The only browser/AT combination I know of where role="alert" is announced on page load is ChromeVox - this behaviour seems to be very recent, and it represents just a small share of the user base.
For the login and reset-password pages, where the form is just one or two fields (all mandatory), the autofocus field is also an error field. My hunch is that this may somewhat mitigate the error message being bypassed, but could still be confusing or annoying.
The create-account page is where currently don't have autofocus.
This hits the nail on the head. As well as having more fields (in the standard install profile), it's also an entity form, using the
user.register
form mode. So it could show an arbitrary number of registration fields chosen by a site builder, with a wide mixture of validation constraints. In other words, there is a wider range of errors that might be reported, which autofocus would bypass.Comment #13
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedTags...
- a11y maintainer review is done, previous comment.
- I'm gathering issues where autofocus was requested.
One day, I'd like to be able to say yes to autofocus. But for that to happen, browsers and AT would need to implement a couple of things.
role="alert"
on page load, so autofocus bypassing the message region wouldn't be so much of a problem.Comment #14
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedAnother point against autofocus. When the Inline Form Errors module is enabled, the messages area will contain links to help users jump to errors. Specifically IFE is our implementation of WCAG technique G139: Creating a mechanism that allows users to jump to errors.
Autofocus will bypass the IFE error links, undermining our efforts to implement WCAG.
Comment #15
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedComment #18
alexpottNote that #2900908: Firefox drupal login form causing flash of unstyled content is looking to remove autofocus from the two forms where it is implemented due to a firefox bug.
Comment #19
sameeran joshi CreditAttribution: sameeran joshi at Google Summer of Code commentedhello everyone,i am a newbie and getting an error while patching in netbeans as "the patch cant be applied in selected context",any ideas?it has left my reviewing work in internet explorer incomplete?help needed
Comment #21
PanchoEven though the issue referenced in #18 has been resolved, as the Firefox bug is fixed, comments #9 through #14 and #18 unfortunately point to this being a "Won't fix".
What remains is @andrewmacpherson in #13:
Comment #22
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedfixing accessibility tag