-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(presentation-role-conflict): create rule to flag elements with r…
…ole conflict resolution (#2440) * Add checks and tests for flag-role rule * Format files * test: add integration tests * Add checks and tests for flag-role rule * Format files * test: add integration tests * PR changes * Fix integration test * Enrich message with global attribute information
- Loading branch information
Showing
12 changed files
with
170 additions
and
28 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
import getGlobalAriaAttrs from '../../commons/standards/get-global-aria-attrs'; | ||
|
||
function hasGlobalAriaAttributeEvaluate(node, options, virtualNode) { | ||
const globalAttrs = getGlobalAriaAttrs().filter(attr => | ||
virtualNode.hasAttr(attr) | ||
); | ||
this.data(globalAttrs); | ||
return globalAttrs.length > 0; | ||
} | ||
|
||
export default hasGlobalAriaAttributeEvaluate; |
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,14 @@ | ||
{ | ||
"id": "has-global-aria-attribute", | ||
"evaluate": "has-global-aria-attribute-evaluate", | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": { | ||
"singular": "Element has global ARIA attribute: ${data.values}", | ||
"plural": "Element has global ARIA attributes: ${data.values}" | ||
}, | ||
"fail": "Element does not have global ARIA attribute" | ||
} | ||
} | ||
} |
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,7 @@ | ||
import { isFocusable } from '../../commons/dom'; | ||
|
||
function isElementFocusableEvaluate(node, options, virtualNode) { | ||
return isFocusable(virtualNode); | ||
} | ||
|
||
export default isElementFocusableEvaluate; |
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": "is-element-focusable", | ||
"evaluate": "is-element-focusable-evaluate", | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": "Element is focusable.", | ||
"fail": "Element is not focusable." | ||
} | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"id": "presentation-role-conflict", | ||
"selector": "[role=\"none\"], [role=\"presentation\"]", | ||
"tags": ["cat.aria", "best-practice"], | ||
"metadata": { | ||
"description": "Flags elements whose role is none or presentation and which cause the role conflict resolution to trigger.", | ||
"help": "Elements of role none or presentation should be flagged" | ||
}, | ||
"all": [], | ||
"any": [], | ||
"none": ["is-element-focusable", "has-global-aria-attribute"] | ||
} |
Empty file.
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,31 @@ | ||
describe('has-global-aria-attribute', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var checkSetup = axe.testUtils.checkSetup; | ||
|
||
var checkContext = axe.testUtils.MockCheckContext(); | ||
var evaluate = axe.testUtils.getCheckEvaluate('has-global-aria-attribute'); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
axe._tree = undefined; | ||
checkContext.reset(); | ||
}); | ||
|
||
it('should return true if any global ARIA attributes are found', function() { | ||
var node = document.createElement('div'); | ||
node.id = 'test'; | ||
node.setAttribute('aria-label', 'hello'); | ||
var params = checkSetup(node); | ||
assert.isTrue(evaluate.apply(checkContext, params)); | ||
}); | ||
|
||
it('should return false if no valid ARIA attributes are found', function() { | ||
var node = document.createElement('div'); | ||
node.id = 'test'; | ||
node.setAttribute('aria-random', 'hello'); | ||
var params = checkSetup(node); | ||
assert.isFalse(evaluate.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
describe('is-element-focusable', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var checkContext = axe.testUtils.MockCheckContext(); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
checkContext.reset(); | ||
}); | ||
|
||
it('should return true for div with a tabindex', function() { | ||
var node = document.createElement('div'); | ||
node.id = 'target'; | ||
node.tabIndex = 1; | ||
fixture.appendChild(node); | ||
axe._tree = axe.utils.getFlattenedTree(fixture); | ||
var virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node); | ||
|
||
assert.isTrue( | ||
axe.testUtils | ||
.getCheckEvaluate('is-element-focusable') | ||
.call(checkContext, node, {}, virtualNode) | ||
); | ||
}); | ||
|
||
it('should return false for natively unfocusable element', function() { | ||
var node = document.createElement('span'); | ||
node.id = 'target'; | ||
node.role = 'link'; | ||
node.href = '#'; | ||
fixture.appendChild(node); | ||
axe._tree = axe.utils.getFlattenedTree(fixture); | ||
var virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node); | ||
assert.isFalse( | ||
axe.testUtils | ||
.getCheckEvaluate('is-element-focusable') | ||
.call(checkContext, node, {}, virtualNode) | ||
); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
test/integration/rules/presentation-role-conflict/presentation-role-conflict.html
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,4 @@ | ||
<div id="pass1" role="presentation">Test</div> | ||
<div id="pass2" role="presentation">Test Button</div> | ||
<li id="violation1" role="presentation" aria-label="My Heading">Hello</li> | ||
<h1 id="violation2" role="none" aria-label="My Heading">Hello</h1> |
6 changes: 6 additions & 0 deletions
6
test/integration/rules/presentation-role-conflict/presentation-role-conflict.json
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,6 @@ | ||
{ | ||
"rule": "presentation-role-conflict", | ||
"description": "presentation-role-conflict tests", | ||
"violations": [["#violation1"], ["#violation2"]], | ||
"passes": [["#pass1"], ["#pass2"]] | ||
} |