-
Notifications
You must be signed in to change notification settings - Fork 783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rule): aria-allowed-role #945
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
63c947b
feat: initial work for new rule > aria-allowed-role
jeeyyy 7298f15
fix: aria-allowed-role rule
jeeyyy ee23a9d
chore: merge from > develop
jeeyyy 03af3af
fix: integration test fixes.
jeeyyy 9646b5b
chore: merge from > develop
jeeyyy 5a040ef
refactor: amends based on review.
jeeyyy 4642828
fix: merge from develop
jeeyyy 099c8d1
fix: update aria.isAllowedRole check to be self sufficient.
jeeyyy 75331d1
fix: merge from develop
jeeyyy 56df2df
fix: update checks based on review comments
jeeyyy 3cbd477
fix: editorial fixes based on review
jeeyyy 604b4ea
fix: refactored roleMap to have allowedElements
jeeyyy 2570ae1
test: update integration tests
jeeyyy 788dca2
test: deprecate old test unncessary due to refactor
jeeyyy 078c75c
fix: merge from develop
jeeyyy f725e21
fix: refactor based on code review
jeeyyy 256db5d
test: update unit/ integration tests
jeeyyy 5b44d65
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 79b00e0
refactor: change pass/ fail messages to respect plurals
jeeyyy b893dc7
refactor: update rule description
jeeyyy 4c3261d
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 9b686ea
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 5cd376a
fix: updates based on review
jeeyyy 8384f65
test: add more integration tests
jeeyyy 9e31d79
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 257a789
fix: swap node.matches with axe.utils.matchesSelector method
jeeyyy 5ecb795
chore: Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy a6d5bba
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 02c15cf
fix: updates based on review
jeeyyy 3502365
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy d69a797
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 87929c7
fix: improve test and refactor based on review
jeeyyy 7a0df2c
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy 2d86762
fix: enhance no role and any role as per aria spec
jeeyyy 8f16a86
test: add tests for aria-allowed-role related functions
jeeyyy d72a247
Merge branch 'develop' into new-rule-aria-allowed-role
jeeyyy ac0ba14
test: fix tests allowedElement object structure
jeeyyy 2777dbc
chore: merge from develop
jeeyyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,23 @@ | ||
/** | ||
* Implements allowed roles defined at: | ||
* https://www.w3.org/TR/html-aria/#docconformance | ||
* https://www.w3.org/TR/SVG2/struct.html#implicit-aria-semantics | ||
*/ | ||
const { allowImplicit = true, ignoredTags = [] } = options || {}; | ||
const tagName = node.nodeName.toUpperCase(); | ||
|
||
// check if the element should be ignored, by an user setting | ||
if (ignoredTags.map(t => t.toUpperCase()).includes(tagName)) { | ||
return true; | ||
} | ||
|
||
const unallowedRoles = axe.commons.aria.getElementUnallowedRoles( | ||
node, | ||
allowImplicit | ||
); | ||
|
||
if (unallowedRoles.length) { | ||
this.data(unallowedRoles); | ||
return false; | ||
} | ||
return true; |
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,15 @@ | ||
{ | ||
"id": "aria-allowed-role", | ||
"evaluate": "aria-allowed-role.js", | ||
"options": { | ||
"allowImplicit": true, | ||
"ignoredTags": [] | ||
}, | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": "ARIA role is allowed for given element", | ||
"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" | ||
} | ||
} | ||
} |
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,80 @@ | ||
/* global aria */ | ||
/** | ||
* gets all unallowed roles for a given node | ||
* @method getElementUnallowedRoles | ||
* @param {Object} node HTMLElement to validate | ||
* @param {String} tagName tag name of a node | ||
* @param {String} allowImplicit option to allow implicit roles, defaults to true | ||
* @return {Array<String>} retruns an array of roles that are not allowed on the given node | ||
*/ | ||
aria.getElementUnallowedRoles = function getElementUnallowedRoles( | ||
node, | ||
allowImplicit | ||
) { | ||
/** | ||
* Get roles applied to a given node | ||
* @param {HTMLElement} node HTMLElement | ||
* @return {Array<String>} return an array of roles applied to the node, if no roles, return an empty array. | ||
*/ | ||
// TODO: not moving this to outer namespace yet, work with wilco to see overlap with his PR(WIP) - aria.getRole | ||
function getRoleSegments(node) { | ||
let roles = []; | ||
if (!node) { | ||
return roles; | ||
} | ||
if (node.hasAttribute('role')) { | ||
const nodeRoles = axe.utils.tokenList( | ||
node.getAttribute('role').toLowerCase() | ||
); | ||
roles = roles.concat(nodeRoles); | ||
} | ||
if (node.hasAttributeNS('http://www.idpf.org/2007/ops', 'type')) { | ||
const epubRoles = axe.utils | ||
.tokenList( | ||
node | ||
.getAttributeNS('http://www.idpf.org/2007/ops', 'type') | ||
.toLowerCase() | ||
) | ||
.map(role => `doc-${role}`); | ||
roles = roles.concat(epubRoles); | ||
} | ||
return roles; | ||
} | ||
|
||
const tagName = node.nodeName.toUpperCase(); | ||
|
||
// by pass custom elements | ||
if (!axe.utils.isHtmlElement(node)) { | ||
return []; | ||
} | ||
|
||
const roleSegments = getRoleSegments(node); | ||
const implicitRole = axe.commons.aria.implicitRole(node); | ||
|
||
// stores all roles that are not allowed for a specific element most often an element only has one explicit role | ||
const unallowedRoles = roleSegments.filter(role => { | ||
if (!axe.commons.aria.isValidRole(role)) { | ||
// do not check made-up/ fake roles | ||
return false; | ||
} | ||
|
||
// check if an implicit role may be set explicit following a setting | ||
if (!allowImplicit && role === implicitRole) { | ||
// edge case: setting implicit role row on tr element is allowed when child of table[role='grid'] | ||
if ( | ||
!( | ||
role === 'row' && | ||
tagName === 'TR' && | ||
axe.utils.matchesSelector(node, 'table[role="grid"] > tr') | ||
) | ||
) { | ||
return true; | ||
} | ||
} | ||
if (!aria.isAriaRoleAllowedOnElement(node, role)) { | ||
return true; | ||
} | ||
}); | ||
|
||
return unallowedRoles; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we shouldn't move this into the matcher instead; make these nodes inapplicable instead of passing them. Seems slightly more appropriate. Maybe just create a ticket for it?