Skip to content

Commit bdff141

Browse files
authored
fix: flag hidden elms with disallowed role(s) for review (#1225)
1 parent 0e0063c commit bdff141

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed

lib/checks/aria/aria-allowed-role.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* https://www.w3.org/TR/html-aria/#docconformance
44
* https://www.w3.org/TR/SVG2/struct.html#implicit-aria-semantics
55
*/
6+
const { dom } = axe.commons;
67
const { allowImplicit = true, ignoredTags = [] } = options || {};
78
const tagName = node.nodeName.toUpperCase();
89

@@ -18,6 +19,10 @@ const unallowedRoles = axe.commons.aria.getElementUnallowedRoles(
1819

1920
if (unallowedRoles.length) {
2021
this.data(unallowedRoles);
22+
if (!dom.isVisible(node, true)) {
23+
// flag hidden elements for review
24+
return undefined;
25+
}
2126
return false;
2227
}
2328
return true;

lib/checks/aria/aria-allowed-role.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"impact": "minor",
1010
"messages": {
1111
"pass": "ARIA role is allowed for given element",
12-
"fail": "role{{=it.data && it.data.length > 1 ? 's' : ''}} {{=it.data.join(', ')}} {{=it.data && it.data.length > 1 ? 'are' : ' is'}} not allowed for given element"
12+
"fail": "ARIA role{{=it.data && it.data.length > 1 ? 's' : ''}} {{=it.data.join(', ')}} {{=it.data && it.data.length > 1 ? 'are' : ' is'}} not allowed for given element",
13+
"incomplete": "ARIA role{{=it.data && it.data.length > 1 ? 's' : ''}} {{=it.data.join(', ')}} must be removed when the element is made visible, as {{=it.data && it.data.length > 1 ? 'they are' : 'it is'}} not allowed for the element"
1314
}
1415
}
15-
}
16+
}

test/checks/aria/aria-allowed-role.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('aria-allowed-role', function() {
1212
it('returns true if given element is an ignoredTag in options', function() {
1313
var node = document.createElement('article');
1414
node.setAttribute('role', 'presentation');
15+
fixture.appendChild(node);
1516
var options = {
1617
ignoredTags: ['article']
1718
};
@@ -26,16 +27,15 @@ describe('aria-allowed-role', function() {
2627
});
2728

2829
it('returns false with implicit role of row for TR when allowImplicit is set to false via options', function() {
29-
var node = document.createElement('table');
30-
node.setAttribute('role', 'grid');
31-
var row = document.createElement('tr');
32-
row.setAttribute('role', 'row');
30+
fixture.innerHTML =
31+
'<table role="grid"><tr id="target" role="row"></tr></table>';
32+
var target = fixture.querySelector('#target');
3333
var options = {
3434
allowImplicit: false
3535
};
3636
var actual = checks['aria-allowed-role'].evaluate.call(
3737
checkContext,
38-
row,
38+
target,
3939
options
4040
);
4141
var expected = false;
@@ -51,6 +51,32 @@ describe('aria-allowed-role', function() {
5151
);
5252
});
5353

54+
it('returns undefined (needs review) when element is hidden and has unallowed role', function() {
55+
fixture.innerHTML =
56+
'<button id="target" type="button" aria-hidden="true"' +
57+
'role="presentation"></button>';
58+
var target = fixture.querySelector('#target');
59+
var actual = checks['aria-allowed-role'].evaluate.call(
60+
checkContext,
61+
target
62+
);
63+
assert.isUndefined(actual);
64+
});
65+
66+
it('returns undefined (needs review) when element is with in hidden parent and has unallowed role', function() {
67+
fixture.innerHTML =
68+
'<div style="display:none">' +
69+
'<button id="target" class="mm-tabstart" type="button"' +
70+
'role="presentation"></button>' +
71+
'</div>';
72+
var target = fixture.querySelector('#target');
73+
var actual = checks['aria-allowed-role'].evaluate.call(
74+
checkContext,
75+
target
76+
);
77+
assert.isUndefined(actual);
78+
});
79+
5480
it('returns true when BUTTON has type menu and role as menuitem', function() {
5581
var node = document.createElement('button');
5682
node.setAttribute('type', 'menu');

test/integration/rules/aria-allowed-role/aria-allowed-role.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ <h1 id='pass-h1-valid-role' role='none'></h1>
5555
<aside id="fail-aside-role-tab" role='tab'></aside>
5656
<button id='fail-button-role-gridcell' role="gridcell" title="IconCheckmark" aria-label="IconCheckmark icon"></button>
5757
<input id='fail-input-role-gridcell-multiple-role' role="gridcell combobox">
58+
<div style="display:none">
59+
<button id="incomplete1" class="mm-tabstart" type="button" role="presentation"></button>
60+
</div>
61+
<button id="incomplete2" type="button" aria-hidden="true" role="presentation"></button>
62+

test/integration/rules/aria-allowed-role/aria-allowed-role.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
["#pass-li-role-doc-biblioentry"],
1313
["#pass-aside-doc-example"],
1414
["#pass-div-valid-role"],
15-
["#pass-ol-valid-role"],
15+
["#pass-ol-valid-role"],
1616
["#pass-nav-role-doc-index"],
1717
["#pass-h1-role-doc-subtitle"],
1818
["#pass-video-valid-role"],
@@ -26,7 +26,7 @@
2626
["#pass-section-valid-role-application"],
2727
["#pass-section-valid-role-content-info"],
2828
["#pass-section-valid-role-dialog"],
29-
["#pass-button-valid-role-checkbox"],
29+
["#pass-button-valid-role-checkbox"],
3030
["#pass-header-valid-role"],
3131
["#pass-footer-valid-role"],
3232
["#pass-embed-valid-role"],
@@ -51,7 +51,7 @@
5151
["#fail-dd-no-role"],
5252
["#fail-dt-no-role"],
5353
["#fail-label-no-role"],
54-
["#fail-ol-invalid-role"],
54+
["#fail-ol-invalid-role"],
5555
["#fail-a-invalid-role"],
5656
["#fail-section-invalid-role"],
5757
["#fail-embed-invalid-role"],
@@ -61,5 +61,9 @@
6161
["#fail-aside-role-tab"],
6262
["#fail-button-role-gridcell"],
6363
["#fail-input-role-gridcell-multiple-role"]
64-
]
65-
}
64+
],
65+
"incomplete": [
66+
["#incomplete1"],
67+
["#incomplete2"]
68+
]
69+
}

0 commit comments

Comments
 (0)