Skip to content

Commit e31a974

Browse files
gaiety-dequeWilcoFiersstraker
authored
fix(autocomplete-valid): incomplete for invalid but safe values (#4500)
Resolves #4492 `incomplete`'s some invalid, but safe to use, values for `autocomplete`. The common mistake in the original issue was `autocomplete="text"` and I've added a few more I'd expect to see. Open to suggestions for more, or removing some of the ones below. --- - text https://github.com/search?q=autocomplete%3D%22text%22&type=code - pronouns https://github.com/search?q=autocomplete%3D%22pronouns%22&type=code - gender https://github.com/search?q=autocomplete%3D%22gender%22&type=code - message https://github.com/search?q=autocomplete%3D%22message%22&type=code - content https://github.com/search?q=autocomplete%3D%22content%22&type=code --- There are other ways to determine usage, GitHub is only one platform code is hosted for example. But it's a way to get a quick view into what's out there in production. --------- Co-authored-by: Wilco Fiers <[email protected]> Co-authored-by: Steven Lambert <[email protected]>
1 parent 50e7c23 commit e31a974

File tree

10 files changed

+96
-11
lines changed

10 files changed

+96
-11
lines changed

doc/check-options.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [aria-required-children](#aria-required-children)
1111
- [aria-required-parent](#aria-required-parent)
1212
- [aria-roledescription](#aria-roledescription)
13+
- [autocomplete-valid](#autocomplete-valid)
1314
- [color-contrast](#color-contrast)
1415
- [page-has-heading-one](#page-has-heading-one)
1516
- [page-has-main](#page-has-main)
@@ -237,6 +238,52 @@ Previously supported properties `validTreeRowAttrs` is no longer available. `inv
237238
</tbody>
238239
</table>
239240

241+
### autocomplete-valid
242+
243+
<table>
244+
<thead>
245+
<tr>
246+
<th>Option</th>
247+
<th align="left">Default</th>
248+
<th align="left">Description</th>
249+
</tr>
250+
</thead>
251+
<tbody>
252+
<tr>
253+
<td>
254+
<code>stateTerms</code>
255+
</td>
256+
<td align="left">
257+
<pre lang=js><code>[
258+
'none',
259+
'false',
260+
'true',
261+
'disabled',
262+
'enabled',
263+
'undefined',
264+
'null',
265+
]</code></pre>
266+
</td>
267+
<td align="left">List of allowed autocomplete state terms other than "on" and "off."</td>
268+
</tr>
269+
<tr>
270+
<td>
271+
<code>ignoredValues</code>
272+
</td>
273+
<td align="left">
274+
<pre lang=js><code>[
275+
'text',
276+
'pronouns',
277+
'gender',
278+
'message',
279+
'content'
280+
]</code></pre>
281+
</td>
282+
<td align="left">List of autocomplete values that are technically invalid but will be ignored as they may not necessarily cause accessibility problems</td>
283+
</tr>
284+
</tbody>
285+
</table>
286+
240287
### color-contrast
241288

242289
| Option | Default | Description |

doc/rule-descriptions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777

7878
## WCAG 2.1 Level A & AA Rules
7979

80-
| Rule ID | Description | Impact | Tags | Issue Type | ACT Rules |
81-
| :----------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- | :------ | :-------------------------------------------------------------- | :--------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
82-
| [autocomplete-valid](https://dequeuniversity.com/rules/axe/4.9/autocomplete-valid?application=RuleDescription) | Ensure the autocomplete attribute is correct and suitable for the form field | Serious | cat.forms, wcag21aa, wcag135, EN-301-549, EN-9.1.3.5, ACT | failure | [73f2c2](https://act-rules.github.io/rules/73f2c2) |
83-
| [avoid-inline-spacing](https://dequeuniversity.com/rules/axe/4.9/avoid-inline-spacing?application=RuleDescription) | Ensure that text spacing set through style attributes can be adjusted with custom stylesheets | Serious | cat.structure, wcag21aa, wcag1412, EN-301-549, EN-9.1.4.12, ACT | failure | [24afc2](https://act-rules.github.io/rules/24afc2), [9e45ec](https://act-rules.github.io/rules/9e45ec), [78fd32](https://act-rules.github.io/rules/78fd32) |
80+
| Rule ID | Description | Impact | Tags | Issue Type | ACT Rules |
81+
| :----------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- | :------ | :-------------------------------------------------------------- | :------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
82+
| [autocomplete-valid](https://dequeuniversity.com/rules/axe/4.9/autocomplete-valid?application=RuleDescription) | Ensure the autocomplete attribute is correct and suitable for the form field | Serious | cat.forms, wcag21aa, wcag135, EN-301-549, EN-9.1.3.5, ACT | failure, needs&nbsp;review | [73f2c2](https://act-rules.github.io/rules/73f2c2) |
83+
| [avoid-inline-spacing](https://dequeuniversity.com/rules/axe/4.9/avoid-inline-spacing?application=RuleDescription) | Ensure that text spacing set through style attributes can be adjusted with custom stylesheets | Serious | cat.structure, wcag21aa, wcag1412, EN-301-549, EN-9.1.4.12, ACT | failure | [24afc2](https://act-rules.github.io/rules/24afc2), [9e45ec](https://act-rules.github.io/rules/9e45ec), [78fd32](https://act-rules.github.io/rules/78fd32) |
8484

8585
## WCAG 2.2 Level A & AA Rules
8686

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isValidAutocomplete } from '../../commons/text';
22

3-
function autocompleteValidEvaluate(node, options, virtualNode) {
3+
function autocompleteValidEvaluate(_node, options, virtualNode) {
44
const autocomplete = virtualNode.attr('autocomplete') || '';
55
return isValidAutocomplete(autocomplete, options);
66
}

lib/checks/forms/autocomplete-valid.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
"metadata": {
55
"impact": "serious",
66
"messages": {
7-
"pass": "The autocomplete attribute is correctly formatted",
8-
"fail": "The autocomplete attribute is incorrectly formatted"
7+
"pass": "the autocomplete attribute is correctly formatted",
8+
"fail": "the autocomplete attribute is incorrectly formatted",
9+
"incomplete": "the autocomplete attribute has a non-standard value. Check whether any standard value could be used instead."
910
}
1011
},
1112
"options": {
@@ -17,6 +18,7 @@
1718
"enabled",
1819
"undefined",
1920
"null"
20-
]
21+
],
22+
"ignoredValues": ["text", "pronouns", "gender", "message", "content"]
2123
}
2224
}

lib/commons/text/is-valid-autocomplete.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ function isValidAutocomplete(
7070
locations = [],
7171
qualifiers = [],
7272
standaloneTerms = [],
73-
qualifiedTerms = []
73+
qualifiedTerms = [],
74+
ignoredValues = []
7475
} = {}
7576
) {
7677
autocompleteValue = autocompleteValue.toLowerCase().trim();
@@ -117,6 +118,11 @@ function isValidAutocomplete(
117118
}
118119

119120
const purposeTerm = autocompleteTerms[autocompleteTerms.length - 1];
121+
122+
if (ignoredValues.includes(purposeTerm)) {
123+
return undefined;
124+
}
125+
120126
return (
121127
standaloneTerms.includes(purposeTerm) ||
122128
qualifiedTerms.includes(purposeTerm)

locales/_template.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,9 @@
682682
"fail": "The autocomplete value is inappropriate for this type of input"
683683
},
684684
"autocomplete-valid": {
685-
"pass": "The autocomplete attribute is correctly formatted",
686-
"fail": "The autocomplete attribute is incorrectly formatted"
685+
"pass": "the autocomplete attribute is correctly formatted",
686+
"fail": "the autocomplete attribute is incorrectly formatted",
687+
"incomplete": "the autocomplete attribute has a non-standard value. Check whether any standard value could be used instead."
687688
},
688689
"accesskeys": {
689690
"pass": "Accesskey attribute value is unique",

test/checks/forms/autocomplete-valid.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ describe('autocomplete-valid', function () {
2121
assert.isFalse(evaluate.apply(checkContext, params));
2222
});
2323

24+
it('returns undefined (incomplete) if autocomplete is ignored', function () {
25+
var params = checkSetup('<input autocomplete="text" id="target" />');
26+
assert.isUndefined(evaluate.apply(checkContext, params));
27+
});
28+
2429
it('uses options to change what is valid autocomplete', function () {
2530
var options = { stateTerms: ['foo'] };
2631
var params = checkSetup(

test/commons/text/is-valid-autocomplete.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,14 @@ describe('text.isValidAutocomplete', () => {
206206
);
207207
});
208208
});
209+
210+
describe('options.ignoredValues', () => {
211+
it('returns undefined if value is invalid and ignored', () => {
212+
assert.isUndefined(
213+
isValidAutocomplete('bad-term', {
214+
ignoredValues: ['bad-term']
215+
})
216+
);
217+
});
218+
});
209219
});

test/integration/rules/autocomplete-valid/autocomplete-valid.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,10 @@
170170
<input autocomplete="section-foo email webauthn" id="pass92" />
171171
<input autocomplete="section-foo work email webauthn" id="pass93" />
172172
<input autocomplete="section-foo billing work email webauthn" id="pass94" />
173+
174+
<!-- Incomplete, ignored values -->
175+
<input autocomplete="text" id="incomplete1" />
176+
<input autocomplete="pronouns" id="incomplete2" />
177+
<input autocomplete="gender" id="incomplete3" />
178+
<input autocomplete="message" id="incomplete4" />
179+
<input autocomplete="content" id="incomplete5" />

test/integration/rules/autocomplete-valid/autocomplete-valid.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
"description": "autocomplete-valid tests",
33
"rule": "autocomplete-valid",
44
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"], ["#fail5"]],
5+
"incomplete": [
6+
["#incomplete1"],
7+
["#incomplete2"],
8+
["#incomplete3"],
9+
["#incomplete4"],
10+
["#incomplete5"]
11+
],
512
"passes": [
613
["#pass1"],
714
["#pass2"],

0 commit comments

Comments
 (0)