-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aria-allowed-attr): add ARIA 1.2 prohibited attrs check (#2764)
* chore: add prohibited attrs to aria-allowed-attr * fix ie11
- Loading branch information
Showing
8 changed files
with
183 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { getRole } from '../../commons/aria'; | ||
import standards from '../../standards'; | ||
|
||
/** | ||
* Check that an element does not use any prohibited ARIA attributes. | ||
* | ||
* Prohibited attributes are taken from the `ariaAttrs` standards object from the attributes `prohibitedAttrs` property. | ||
* | ||
* ##### Data: | ||
* <table class="props"> | ||
* <thead> | ||
* <tr> | ||
* <th>Type</th> | ||
* <th>Description</th> | ||
* </tr> | ||
* </thead> | ||
* <tbody> | ||
* <tr> | ||
* <td><code>String[]</code></td> | ||
* <td>List of all prohibited attributes</td> | ||
* </tr> | ||
* </tbody> | ||
* </table> | ||
* | ||
* @memberof checks | ||
* @return {Boolean} True if the element does not use any prohibited ARIA attributes. False otherwise. | ||
*/ | ||
function ariaProhibitedAttrEvaluate(node, options, virtualNode) { | ||
const prohibited = []; | ||
const role = getRole(virtualNode); | ||
|
||
if (!role) { | ||
return false; | ||
} | ||
|
||
const attrs = virtualNode.attrNames; | ||
const prohibitedAttrs = standards.ariaRoles[role].prohibitedAttrs; | ||
|
||
if (!prohibitedAttrs) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < attrs.length; i++) { | ||
const attrName = attrs[i]; | ||
if (prohibitedAttrs.includes(attrName)) { | ||
prohibited.push(attrName); | ||
} | ||
} | ||
|
||
if (prohibited.length) { | ||
this.data(prohibited); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export default ariaProhibitedAttrEvaluate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "aria-prohibited-attr", | ||
"evaluate": "aria-prohibited-attr-evaluate", | ||
"metadata": { | ||
"impact": "critical", | ||
"messages": { | ||
"pass": "ARIA attribute is allowed", | ||
"fail": "ARIA attribute cannot be used: ${data.values}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
describe.only('aria-prohibited-attr', function() { | ||
'use strict'; | ||
|
||
var checkContext = axe.testUtils.MockCheckContext(); | ||
var checkSetup = axe.testUtils.checkSetup; | ||
var checkEvaluate = axe.testUtils.getCheckEvaluate('aria-prohibited-attr'); | ||
|
||
afterEach(function() { | ||
checkContext.reset(); | ||
}); | ||
|
||
it('should return true for prohibited attributes', function() { | ||
var params = checkSetup( | ||
'<div id="target" role="code" aria-hidden="false" aria-label="foo">Contents</div>' | ||
); | ||
assert.isTrue(checkEvaluate.apply(checkContext, params)); | ||
assert.deepEqual(checkContext._data, ['aria-label']); | ||
}); | ||
|
||
it('should return true for multiple prohibited attributes', function() { | ||
var params = checkSetup( | ||
'<div id="target" role="code" aria-hidden="false" aria-label="foo" aria-labelledby="foo">Contents</div>' | ||
); | ||
assert.isTrue(checkEvaluate.apply(checkContext, params)); | ||
|
||
// attribute order not important | ||
assert.sameDeepMembers(checkContext._data, [ | ||
'aria-label', | ||
'aria-labelledby' | ||
]); | ||
}); | ||
|
||
it('should return false if all attributes are allowed', function() { | ||
var params = checkSetup( | ||
'<div id="target" role="button" aria-label="foo" aria-labelledby="foo">Contents</div>' | ||
); | ||
assert.isFalse(checkEvaluate.apply(checkContext, params)); | ||
}); | ||
|
||
it('should return false if element has no role', function() { | ||
var params = checkSetup( | ||
'<div id="target" aria-label="foo" aria-labelledby="foo">Contents</div>' | ||
); | ||
assert.isFalse(checkEvaluate.apply(checkContext, params)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
{ | ||
"description": "aria-allowed-attr failing tests", | ||
"rule": "aria-allowed-attr", | ||
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"]] | ||
"violations": [ | ||
["#fail1"], | ||
["#fail2"], | ||
["#fail3"], | ||
["#fail4"], | ||
["#fail5"], | ||
["#fail6"], | ||
["#fail7"], | ||
["#fail8"], | ||
["#fail9"], | ||
["#fail10"], | ||
["#fail11"], | ||
["#fail12"], | ||
["#fail13"], | ||
["#fail14"], | ||
["#fail15"], | ||
["#fail16"], | ||
["#fail17"], | ||
["#fail18"], | ||
["#fail19"], | ||
["#fail20"], | ||
["#fail21"], | ||
["#fail22"] | ||
] | ||
} |