-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aria-roles): report error for fallback roles (#1970)
* fix(aria-roles): report error for fallback roles * message * allow all checks to look at multiple roles * fix * revert playground * add roles as data
- Loading branch information
Showing
12 changed files
with
237 additions
and
29 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 |
---|---|---|
@@ -1 +1,10 @@ | ||
return axe.commons.aria.getRoleType(node.getAttribute('role')) === 'abstract'; | ||
const abstractRoles = axe.utils | ||
.tokenList(virtualNode.attr('role')) | ||
.filter(role => axe.commons.aria.getRoleType(role) === 'abstract'); | ||
|
||
if (abstractRoles.length > 0) { | ||
this.data(abstractRoles); | ||
return true; | ||
} | ||
|
||
return false; |
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 @@ | ||
return axe.utils.tokenList(virtualNode.attr('role')).length > 1; |
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": "fallbackrole", | ||
"evaluate": "fallbackrole.js", | ||
"metadata": { | ||
"impact": "serious", | ||
"messages": { | ||
"pass": "Only one role value used", | ||
"fail": "Use only one role value, since fallback roles are not supported in older browsers" | ||
} | ||
} | ||
} |
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,3 +1,14 @@ | ||
return !axe.commons.aria.isValidRole(node.getAttribute('role'), { | ||
allowAbstract: true | ||
}); | ||
const invalidRoles = axe.utils | ||
.tokenList(virtualNode.attr('role')) | ||
.filter(role => { | ||
return !axe.commons.aria.isValidRole(role, { | ||
allowAbstract: true | ||
}); | ||
}); | ||
|
||
if (invalidRoles.length > 0) { | ||
this.data(invalidRoles); | ||
return true; | ||
} | ||
|
||
return false; |
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,40 @@ | ||
describe('fallbackrole', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should return true if fallback role is used', function() { | ||
var virtualNode = queryFixture( | ||
'<div id="target" role="button foobar">Foo</div>' | ||
); | ||
assert.isTrue( | ||
checks.fallbackrole.evaluate(virtualNode.actualNode, 'radio', virtualNode) | ||
); | ||
}); | ||
|
||
it('should return false if fallback role is not used', function() { | ||
var virtualNode = queryFixture('<div id="target" role="button">Foo</div>'); | ||
assert.isFalse( | ||
checks.fallbackrole.evaluate(virtualNode.actualNode, 'radio', virtualNode) | ||
); | ||
}); | ||
|
||
it('should return false if applied to an invalid role', function() { | ||
var virtualNode = queryFixture('<div id="target" role="foobar">Foo</div>'); | ||
assert.isFalse( | ||
checks.fallbackrole.evaluate(virtualNode.actualNode, 'radio', virtualNode) | ||
); | ||
}); | ||
|
||
it('should return false if applied to an invalid role', function() { | ||
var virtualNode = queryFixture('<div id="target" role="foobar">Foo</div>'); | ||
assert.isFalse( | ||
checks.fallbackrole.evaluate(virtualNode.actualNode, 'radio', virtualNode) | ||
); | ||
}); | ||
}); |
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