Skip to content

Commit

Permalink
fix: autocomplete appropriate to handle state terms (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeyyy authored Sep 7, 2018
1 parent a0f9b31 commit 35a4d11
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/checks/forms/autocomplete-appropriate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ const autocomplete = node.getAttribute('autocomplete');
const autocompleteTerms = autocomplete
.split(/\s+/g)
.map(term => term.toLowerCase());

const purposeTerm = autocompleteTerms[autocompleteTerms.length - 1];
const allowedTypes = allowedTypesMap[purposeTerm];
if (axe.commons.text.autocomplete.stateTerms.includes(purposeTerm)) {
return true;
}

const allowedTypes = allowedTypesMap[purposeTerm];
if (typeof allowedTypes === 'undefined') {
return node.type === 'text';
}
Expand Down
12 changes: 12 additions & 0 deletions test/checks/forms/autocomplete-appropriate.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ describe('autocomplete-appropriate', function() {
assert.isTrue(evaluate.apply(checkContext, params));
});

it('returns true if the input type is tel and the term is off', function() {
var options = {};
var params = autocompleteCheckParams('off', 'tel', options);
assert.isTrue(evaluate.apply(checkContext, params));
});

it('returns true if the input type is url and the term is on', function() {
var options = {};
var params = autocompleteCheckParams('on', 'url', options);
assert.isTrue(evaluate.apply(checkContext, params));
});

it('returns false if the input type is text and the term maps to an empty array', function() {
var options = { foo: [] };
var params = autocompleteCheckParams('foo', 'text', options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@
<input autocomplete="SECTION-foo mobile tel-extension" id="pass61" />
<input autocomplete="fax email" id="pass62" />
<input autocomplete="pager impp" id="pass63" />
<input autocomplete="off" id="pass64" name="input_1" placeholder="Numeric Input Field" value="42" type="tel">
<input autocomplete="on" id="pass65" value="" type="url">
<input autocomplete="off" id="pass66" value="42" type="datetime-local">

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
["#pass60"],
["#pass61"],
["#pass62"],
["#pass63"]
["#pass63"],
["#pass64"],
["#pass65"],
["#pass66"]
]
}

0 comments on commit 35a4d11

Please sign in to comment.