-
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.
refactor(check): split no-focusable-content rule into three.
That rule is now: no-focusable-content-for-aria-text, no-focusable-content-for-nested-interactive, and no-focusable-content-for-frame These three are all copy-and-pastes of each other, so far.
- Loading branch information
Showing
12 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
lib/checks/keyboard/no-focusable-content-for-aria-text-evaluate.js
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,35 @@ | ||
import isFocusable from '../../commons/dom/is-focusable'; | ||
|
||
function focusableDescendants(vNode) { | ||
if (isFocusable(vNode)) { | ||
return true; | ||
} | ||
|
||
if (!vNode.children) { | ||
if (vNode.props.nodeType === 1) { | ||
throw new Error('Cannot determine children'); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return vNode.children.some(child => { | ||
return focusableDescendants(child); | ||
}); | ||
} | ||
|
||
function noFocusableContentForAriaTextEvaluate(node, options, virtualNode) { | ||
if (!virtualNode.children) { | ||
return undefined; | ||
} | ||
|
||
try { | ||
return !virtualNode.children.some(child => { | ||
return focusableDescendants(child); | ||
}); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
|
||
export default noFocusableContentForAriaTextEvaluate; |
4 changes: 2 additions & 2 deletions
4
...checks/keyboard/no-focusable-content.json → ...d/no-focusable-content-for-aria-text.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
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
4 changes: 2 additions & 2 deletions
4
...cks/keyboard/frame-focusable-content.json → ...board/no-focusable-content-for-frame.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
35 changes: 35 additions & 0 deletions
35
lib/checks/keyboard/no-focusable-content-for-nested-interactive-evaluate.js
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,35 @@ | ||
import isFocusable from '../../commons/dom/is-focusable'; | ||
|
||
function focusableDescendants(vNode) { | ||
if (isFocusable(vNode)) { | ||
return true; | ||
} | ||
|
||
if (!vNode.children) { | ||
if (vNode.props.nodeType === 1) { | ||
throw new Error('Cannot determine children'); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return vNode.children.some(child => { | ||
return focusableDescendants(child); | ||
}); | ||
} | ||
|
||
function noFocusableContentForNestedInteractiveEvaluate(node, options, virtualNode) { | ||
if (!virtualNode.children) { | ||
return undefined; | ||
} | ||
|
||
try { | ||
return !virtualNode.children.some(child => { | ||
return focusableDescendants(child); | ||
}); | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
|
||
export default noFocusableContentForNestedInteractiveEvaluate; |
12 changes: 12 additions & 0 deletions
12
lib/checks/keyboard/no-focusable-content-for-nested-interactive.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,12 @@ | ||
{ | ||
"id": "no-focusable-content-for-nested-interactive", | ||
"evaluate": "no-focusable-content-for-nested-interactive-evaluate", | ||
"metadata": { | ||
"impact": "serious", | ||
"messages": { | ||
"pass": "Element does not have focusable descendants", | ||
"fail": "Element has focusable descendants", | ||
"incomplete": "Could not determine if element has descendants" | ||
} | ||
} | ||
} |
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
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
41 changes: 41 additions & 0 deletions
41
test/checks/keyboard/no-focusable-content-for-nested-interactive.js
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('no-focusable-content-for-nested-interactive tests', function() { | ||
var fixture = document.querySelector('#fixture'); | ||
var queryFixture = axe.testUtils.queryFixture; | ||
var noFocusableContentForNestedInteractive = axe.testUtils.getCheckEvaluate( | ||
'no-focusable-content-for-nested-interactive' | ||
); | ||
|
||
afterEach(function() { | ||
fixture.innerHTML = ''; | ||
}); | ||
|
||
it('should return true if element has no focusable content', function() { | ||
var vNode = queryFixture('<button id="target"><span>Hello</span></button>'); | ||
assert.isTrue(noFocusableContentForNestedInteractive(null, null, vNode)); | ||
}); | ||
|
||
it('should return true if element is empty', function() { | ||
var vNode = queryFixture('<button id="target"></button>'); | ||
assert.isTrue(noFocusableContentForNestedInteractive(null, null, vNode)); | ||
}); | ||
|
||
it('should return true if element only has text content', function() { | ||
var vNode = queryFixture('<button id="target">Hello</button>'); | ||
assert.isTrue(noFocusableContentForNestedInteractive(null, null, vNode)); | ||
}); | ||
|
||
it('should return false if element has focusable content', function() { | ||
var vNode = queryFixture( | ||
'<button id="target"><span tabindex="0">Hello</span></button>' | ||
); | ||
assert.isFalse(noFocusableContentForNestedInteractive(null, null, vNode)); | ||
}); | ||
|
||
it('should return false if element has natively focusable content', function() { | ||
var vNode = queryFixture( | ||
'<button id="target"><a href="foo.html">Hello</a></button>' | ||
); | ||
assert.isFalse(noFocusableContentForNestedInteractive(null, null, vNode)); | ||
}); | ||
|
||
}); |