MDL-85774 login: Remove visually-hidden links

Visually hidden links on login error/info disrupt tab order. We must
remove them.

Instead, announce the div containing the login error/info messages on
page reload.

The visually hidden signup link has also been removed.
This commit is contained in:
Jun Pataleta
2025-10-23 11:28:39 +08:00
parent 21be86fb7f
commit fe7d26d33f
2 changed files with 29 additions and 11 deletions
+3 -1
View File
@@ -96,13 +96,15 @@ Feature: Test if the login form provides the correct feedback
And I follow "Log in"
Then the focused element is "Password" "field"
@accessibility
Scenario: Test the login page focus after error feature
Given I follow "Log in"
And I set the field "Username" to "admin"
And I set the field "Password" to "wrongpassword"
And I press "Log in"
And I press the tab key
And I wait until the page is ready
Then the focused element is "Username" "field"
And the page should meet accessibility standards with "best-practice" extra tests
Scenario: Display the password visibility toggle icon
Given the following config values are set as admin:
+26 -10
View File
@@ -115,16 +115,11 @@
</div>
{{/maintenance}}
{{#error}}
<a href="#" id="loginerrormessage" class="visually-hidden">{{error}}</a>
<div class="alert alert-danger" role="alert">{{error}}</div>
<div class="alert alert-danger" id="loginerrormessage" role="alert">{{error}}</div>
{{/error}}
{{#info}}
<a href="#" id="logininfomessage" class="visually-hidden">{{info}}</a>
<div class="alert alert-info" role="alert">{{info}}</div>
<div class="alert alert-info" id="logininfomessage" role="status">{{info}}</div>
{{/info}}
{{#cansignup}}
<a href="{{signupurl}}" class="visually-hidden">{{#str}} tocreatenewaccount {{/str}}</a>
{{/cansignup}}
{{#showloginform}}
<form class="login-form" action="{{loginurl}}" method="post" id="login">
<input id="anchor" type="hidden" name="anchor" value="">
@@ -235,9 +230,30 @@
});
{{/autofocusform}}
{{/error}}
{{#error}}
document.getElementById('loginerrormessage').focus();
{{/error}}
require(['core/pending'], function(Pending) {
const errorMessageDiv = document.getElementById('loginerrormessage');
const infoMessageDiv = document.getElementById('logininfomessage');
const errorMessage = errorMessageDiv?.textContent.trim();
const infoMessage = infoMessageDiv?.textContent.trim();
if (errorMessage || infoMessage) {
const pendingJS = new Pending('login-move-focus');
const usernameField = document.getElementById('username');
setTimeout(function() {
// Focus on the username field on error.
if (errorMessage && usernameField) {
usernameField.focus();
}
// Append a non-breaking space to the error/status message so screen readers will announce them after page load.
if (errorMessage) {
errorMessageDiv.innerHTML += "&nbsp;";
}
if (infoMessage) {
infoMessageDiv.innerHTML += "&nbsp;";
}
pendingJS.resolve();
}, 500);
}
});
{{#togglepassword}}
require(['core/togglesensitive'], function(ToggleSensitive) {
ToggleSensitive.init("password", {{smallscreensonly}});