Skip to content

Commit 7999ff2

Browse files
authored
Merge pull request #46 from browserstack/autocomplete-bug-fixes
Autocomplete bug fixes
2 parents bb4338c + 4182917 commit 7999ff2

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

lib/checks/forms/autocomplete-a11y-evaluate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isValidAutocomplete } from "../../commons/text";
33
function checkIsElementValidAutocomplete(node, options, virtualNode) {
44
const autocomplete = virtualNode.attr('autocomplete')?.toLowerCase().trim();
55
// if element has autocomplete attribute as off then it is not a violation
6-
if(autocomplete === "off") {
6+
if(autocomplete === "off" || autocomplete==="chrome-off") {
77
return true;
88
}
99

@@ -33,7 +33,8 @@ function checkIsElementValidAutocomplete(node, options, virtualNode) {
3333
const closestForm = virtualNode.actualNode.closest("form");
3434

3535
//if it exists inside the form and autocomplete for form is off
36-
if(closestForm && closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "off") {
36+
if(closestForm && (closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "off"
37+
|| closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "chrome-off")) {
3738
// if autocomplete attribute is not present for element then its a pass in this scenario
3839
// otherwise check all posibilities with the method
3940
return autocomplete ? checkIsElementValidAutocomplete(node, options, virtualNode) : true;

lib/checks/forms/autocomplete-valid.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"id": "autocomplete-valid",
33
"evaluate": "autocomplete-a11y-evaluate",
44
"metadata": {
5-
"impact": "serious",
5+
"impact": "moderate",
66
"messages": {
77
"pass": "the autocomplete attribute is correctly formatted",
8-
"fail": "the autocomplete attribute is incorrectly formatted"
8+
"fail": "Add autocomplete attribute to form fields with a valid value as per HTML specification. In 'name' attribute of field, prefer to use standard autocomplete value since browsers use 'name' to suggest autofill. For field with no standard autocomplete value (eg: College ID), prefer to use autocomplete='on'."
99
}
1010
},
1111
"options": {

lib/rules/autocomplete-matches.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { sanitize } from '../commons/text';
22
import standards from '../standards';
33
import { isVisible } from '../commons/dom';
44

5-
function autocompleteMatches(node, virtualNode, flag=false) {
5+
function autocompleteMatches(node, virtualNode, flag = false) {
66
const autocomplete = virtualNode.attr('autocomplete');
77
if ((!autocomplete || sanitize(autocomplete) === '') && !flag) {
88
return false;
@@ -13,8 +13,17 @@ function autocompleteMatches(node, virtualNode, flag=false) {
1313
return false;
1414
}
1515

16-
// The element is an `input` element a `type` of `hidden`, `button`, `submit` or `reset`
17-
const excludedInputTypes = ['submit', 'reset', 'button', 'hidden'];
16+
// The element is an `input` element a `type` of `hidden`, `reset`,`button`, `submit` , 'checkbox', 'file', 'image', or 'radio'
17+
const excludedInputTypes = [
18+
'submit',
19+
'reset',
20+
'button',
21+
'hidden',
22+
'checkbox',
23+
'file',
24+
'image',
25+
'radio'
26+
];
1827
if (
1928
nodeName === 'input' &&
2029
excludedInputTypes.includes(virtualNode.props.type)

lib/rules/autocomplete-valid.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
{
22
"id": "autocomplete-valid",
33
"matches": "autocomplete-a11y-matches",
4-
"tags": ["cat.forms", "wcag21aa", "wcag135"],
4+
"tags": [
5+
"cat.forms",
6+
"wcag21aa",
7+
"wcag22aa",
8+
"wcag135",
9+
"a11y-engine",
10+
"a11y-engine-experimental"
11+
],
512
"actIds": ["73f2c2"],
613
"metadata": {
7-
"description": "Ensure the autocomplete attribute is correct and suitable for the form field",
8-
"help": "autocomplete attribute must be used correctly"
14+
"description": "Ensure that the necessary form fields use the autocomplete attribute with a valid input.",
15+
"help": "Autocomplete attribute must have a valid value"
916
},
1017
"all": ["autocomplete-valid"],
1118
"any": [],

0 commit comments

Comments
 (0)