Skip to content

Commit d34e9ad

Browse files
committed
Merge branch 'main' of github.com:browserstack/a11y-engine-axe-core into a11y-commons
2 parents a5d9116 + 200f4e7 commit d34e9ad

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

lib/checks/color/link-in-text-block-evaluate.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function isBlock(elm) {
2828
}
2929

3030
function linkInTextBlockEvaluate(node) {
31+
if(node.getAttribute('type') ==='button' || node.tagName.toLowerCase() === 'button' || node.getAttribute('role') === 'button') {
32+
return true;
33+
}
34+
3135
var options = arguments.length > 1 && arguments[1] ? arguments[1] : {};
3236
if (isBlock(node)) {
3337
return false;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { isValidAutocomplete } from "../../commons/text";
2+
3+
function checkIsElementValidAutocomplete(node, options, virtualNode) {
4+
const autocomplete = virtualNode.attr('autocomplete')?.toLowerCase().trim();
5+
// if element has autocomplete attribute as off then it is not a violation
6+
if(autocomplete === "off") {
7+
return true;
8+
}
9+
10+
// if it is on then we check whether name / id have valid autocomplete value or not
11+
// same for the case if autocomplete is not present or has a non-standard value
12+
if(!autocomplete || autocomplete === "on" || !isValidAutocomplete(autocomplete, options)) {
13+
const name = virtualNode.attr('name');
14+
const id = virtualNode.attr('id');
15+
if((name && isValidAutocomplete(name, options)) || (id && isValidAutocomplete(id, options)))
16+
return true;
17+
return false;
18+
}
19+
20+
// if element autocomplete attribute is neither off nor on then we check if its a standard value
21+
if(isValidAutocomplete(autocomplete, options)) {
22+
return true;
23+
}
24+
25+
return false;
26+
}
27+
28+
function autocompleteA11yEvaluate(node, options, virtualNode) {
29+
try {
30+
const autocomplete = virtualNode.attr('autocomplete');
31+
32+
// check if the autocomplete applicable element is inside form or exist freely
33+
const closestForm = virtualNode.actualNode.closest("form");
34+
35+
//if it exists inside the form and autocomplete for form is off
36+
if(closestForm && closestForm.getAttribute('autocomplete')?.toLowerCase().trim() === "off") {
37+
// if autocomplete attribute is not present for element then its a pass in this scenario
38+
// otherwise check all posibilities with the method
39+
return autocomplete ? checkIsElementValidAutocomplete(node, options, virtualNode) : true;
40+
} else {
41+
// The else case is if form is present and it has autocomplete as on or not set and
42+
// the other case this handles is that element exists independently
43+
44+
// this method would check for all posibilities
45+
return checkIsElementValidAutocomplete(node, options, virtualNode);
46+
}
47+
}
48+
catch(err) {
49+
ErrorHandler.addCheckError("autocomplete-attribute-valid-check", err);
50+
return undefined;
51+
}
52+
}
53+
54+
export default autocompleteA11yEvaluate;

lib/checks/forms/autocomplete-valid.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "autocomplete-valid",
3-
"evaluate": "autocomplete-valid-evaluate",
3+
"evaluate": "autocomplete-a11y-evaluate",
44
"metadata": {
55
"impact": "serious",
66
"messages": {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import autocompleteMatches from "./autocomplete-matches";
2+
3+
function autocompleteA11yMatches(node, virtualNode) {
4+
const a11yEngineFlag = true;
5+
// the flag is used to tell autocomplete matcher that it is being called
6+
// by a11y-engine and thus bypass an if block
7+
return autocompleteMatches(node, virtualNode, a11yEngineFlag);
8+
}
9+
10+
export default autocompleteA11yMatches;

lib/rules/autocomplete-matches.js

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

5-
function autocompleteMatches(node, virtualNode) {
5+
function autocompleteMatches(node, virtualNode, flag=false) {
66
const autocomplete = virtualNode.attr('autocomplete');
7-
if (!autocomplete || sanitize(autocomplete) === '') {
7+
if ((!autocomplete || sanitize(autocomplete) === '') && !flag) {
88
return false;
99
}
1010

lib/rules/autocomplete-valid.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "autocomplete-valid",
3-
"matches": "autocomplete-matches",
3+
"matches": "autocomplete-a11y-matches",
44
"tags": ["cat.forms", "wcag21aa", "wcag135"],
55
"actIds": ["73f2c2"],
66
"metadata": {

0 commit comments

Comments
 (0)