-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
200 additions
and
5 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
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 @@ | ||
const { dom } = axe.commons; | ||
|
||
let elements = [node]; | ||
|
||
if (node.children.length) { | ||
const children = Array.prototype.slice.call(node.querySelectorAll('*')); | ||
elements = elements.concat(children); | ||
} | ||
|
||
const result = elements.every(element => { | ||
const output = dom.isFocusable(element, false) === false; | ||
return output; | ||
}); | ||
|
||
return result; |
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-hidden-focus", | ||
"evaluate": "aria-hidden-focus.js", | ||
"metadata": { | ||
"impact": "serious", | ||
"messages": { | ||
"pass": "No focusable elements under aria-hidden element", | ||
"fail": "aria-hidden=true element must not contain focusable elements" | ||
} | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"id": "aria-hidden-focus", | ||
"selector": "[aria-hidden=\"true\"]", | ||
"excludeHidden": false, | ||
"tags": [ | ||
"cat.name-role-value", | ||
"wcag2a", | ||
"wcag412" | ||
], | ||
"metadata": { | ||
"description": "Ensures aria-hidden element do not contain focusable elements", | ||
"help": "ARIA hidden element must not contain focusable elements" | ||
}, | ||
"all": [], | ||
"any": [ | ||
"aria-hidden-focus" | ||
], | ||
"none": [] | ||
} |
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,86 @@ | ||
describe('aria-hidden-focus', function() { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
var check = undefined; | ||
var checkContext = axe.testUtils.MockCheckContext(); | ||
|
||
before(function() { | ||
check = checks['aria-hidden-focus']; | ||
checkContext._data = null; | ||
}); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('returns true when content not focusable by default', function() { | ||
fixture.innerHTML = '<p id="target" aria-hidden="true">Some text</p>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isTrue(actual); | ||
}); | ||
|
||
it('returns true when content hidden through CSS', function() { | ||
fixture.innerHTML = | ||
'<div id="target" aria-hidden="true"><a href="/" style="display:none">Link</a></div>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isTrue(actual); | ||
}); | ||
|
||
it('returns true when content made unfocusable through tabindex', function() { | ||
fixture.innerHTML = | ||
'<div id="target" aria-hidden="true"><button tabindex="-1">Some button</button></div>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isTrue(actual); | ||
}); | ||
|
||
it('returns true when content made unfocusable through disabled', function() { | ||
fixture.innerHTML = '<input id="target" disabled aria-hidden="true" />'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isTrue(actual); | ||
}); | ||
|
||
it('returns false when focusable off screen link', function() { | ||
fixture.innerHTML = | ||
'<div id="target" aria-hidden="true"><a href="/" style="position:absolute; top:-999em">Link</a></div>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when focusable form field, incorrectly disabled', function() { | ||
fixture.innerHTML = | ||
'<div id="target" aria-hidden="true"><input type="text"/></div>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when aria-hidden=false does not negate aria-hidden true', function() { | ||
fixture.innerHTML = | ||
'<div id="target" aria-hidden="true"><div aria-hidden="false"><button tabindex="-1">Some button</button></div></div>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when focusable content through tabindex', function() { | ||
fixture.innerHTML = | ||
'<p id="target" tabindex="0" aria-hidden="true">Some text</p>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isFalse(actual); | ||
}); | ||
|
||
it('returns false when Focusable summary element', function() { | ||
fixture.innerHTML = | ||
'<details id="target" aria-hidden="true"><summary>Some button</summary><p>Some details</p></details>'; | ||
var node = fixture.querySelector('#target'); | ||
var actual = check.evaluate.call(checkContext, node); | ||
assert.isFalse(actual); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
test/integration/rules/aria-hidden-focus/aria-hidden-focus.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,24 @@ | ||
<!-- Pass --> | ||
<p id='pass1' aria-hidden="true">Some text</p> | ||
<div id='pass2' aria-hidden="true"><a href="/" style="display:none">Link</a></div> | ||
<div id='pass3' aria-hidden="true"><button tabindex="-1">Some button</button></div> | ||
<input id='pass4' disabled aria-hidden="true" /> | ||
<div id='pass5' aria-hidden="true"><a href="/" style="position:absolute; top:-999em">Link</a></div> | ||
|
||
<!-- Fail --> | ||
<div id='violation1' aria-hidden="true"> | ||
<a href="/" style="position:absolute; top:-999em">Link</a> | ||
</div> | ||
<div id='violation2' aria-hidden="true"> | ||
<input aria-disabled="true" /> | ||
</div> | ||
<div id='violation3' aria-hidden="true"> | ||
<div aria-hidden="false"> | ||
<button tabindex="-1">Some button</button> | ||
</div> | ||
</div> | ||
<p id='violation4' tabindex="0" aria-hidden="true">Some text</p> | ||
<details id='violation5' aria-hidden="true"> | ||
<summary>Some button</summary> | ||
<p>Some details</p> | ||
</details> |
38 changes: 38 additions & 0 deletions
38
test/integration/rules/aria-hidden-focus/aria-hidden-focus.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,38 @@ | ||
{ | ||
"description": "aria-hidden-focus tests", | ||
"rule": "aria-hidden-focus", | ||
"violations": [ | ||
[ | ||
"#violation1" | ||
], | ||
[ | ||
"#violation2" | ||
], | ||
[ | ||
"#violation3" | ||
], | ||
[ | ||
"#violation4" | ||
], | ||
[ | ||
"#violation5" | ||
] | ||
], | ||
"passes": [ | ||
[ | ||
"#pass1" | ||
], | ||
[ | ||
"#pass2" | ||
], | ||
[ | ||
"#pass3" | ||
], | ||
[ | ||
"#pass4" | ||
], | ||
[ | ||
"#pass5" | ||
] | ||
] | ||
} |