-
Notifications
You must be signed in to change notification settings - Fork 779
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(frame-focusable-content): new rule to test iframes with tabindex=-1 do not have focusable content #2785
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d63430
feat(frame-focusable-content): new rule to test iframes with tabindex…
straker 0ae96c1
add inapplicable
straker d4eb165
fix tests
straker 10809fa
after results
straker a41fca4
test
straker 9ce6a73
hmmm
straker 46eb9be
fix
straker f21cf8b
remove after
straker 66fb51b
fix test
straker 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,12 @@ | ||
{ | ||
"id": "frame-focusable-content", | ||
"evaluate": "no-focusable-content-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function frameFocusableContentMatches(node, virtualNode, context) { | ||
return ( | ||
!context.initiator && | ||
!context.focusable && | ||
context.boundingClientRect.width * context.boundingClientRect.height > 1 | ||
); | ||
} | ||
|
||
export default frameFocusableContentMatches; |
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,13 @@ | ||
{ | ||
"id": "frame-focusable-content", | ||
"selector": "html", | ||
"matches": "frame-focusable-content-matches", | ||
"tags": ["cat.keyboard", "wcag2a", "wcag211"], | ||
"metadata": { | ||
"description": "Ensures <frame> and <iframe> elements with tabindex=-1 do not have focusable content", | ||
"help": "Frames with tabindex=-1 must not have focusable content" | ||
}, | ||
"all": [], | ||
"any": ["frame-focusable-content"], | ||
"none": [] | ||
} |
43 changes: 43 additions & 0 deletions
43
test/integration/rules/frame-focusable-content/frame-focusable-content.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,43 @@ | ||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/not-focusable.html" | ||
tabindex="-1" | ||
id="pass1" | ||
></iframe> | ||
|
||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/focusable.html" | ||
tabindex="-1" | ||
id="fail1" | ||
></iframe> | ||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/focusable.html" | ||
tabindex="-1" | ||
width="2" | ||
height="1" | ||
id="fail2" | ||
></iframe> | ||
|
||
<!-- inapplicable --> | ||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/focusable.html" | ||
id="inapplicable-1" | ||
></iframe> | ||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/focusable.html" | ||
tabindex="0" | ||
id="inapplicable-2" | ||
></iframe> | ||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/focusable.html" | ||
tabindex="-1" | ||
width="1" | ||
height="1" | ||
id="inapplicable-3" | ||
></iframe> | ||
<iframe | ||
src="/integration/rules/frame-focusable-content/frames/focusable.html" | ||
tabindex="-1" | ||
width="0" | ||
height="0" | ||
id="inapplicable-3" | ||
></iframe> |
9 changes: 9 additions & 0 deletions
9
test/integration/rules/frame-focusable-content/frame-focusable-content.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,9 @@ | ||
{ | ||
"description": "frame-focusable-content tests", | ||
"rule": "frame-focusable-content", | ||
"violations": [ | ||
["#fail1", "#focusable"], | ||
["#fail2", "#focusable"] | ||
], | ||
"passes": [["#pass1", "#not-focusable"]] | ||
} |
11 changes: 11 additions & 0 deletions
11
test/integration/rules/frame-focusable-content/frames/focusable.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,11 @@ | ||
<!DOCTYPE html> | ||
<html id="focusable"> | ||
<head> | ||
<title>Hello</title> | ||
<meta charset="utf8" /> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<button>Click</button> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
test/integration/rules/frame-focusable-content/frames/not-focusable.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,11 @@ | ||
<!DOCTYPE html> | ||
<html id="not-focusable"> | ||
<head> | ||
<title>Hello</title> | ||
<meta charset="utf8" /> | ||
<script src="/axe.js"></script> | ||
</head> | ||
<body> | ||
<p>Hello</p> | ||
</body> | ||
</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,68 @@ | ||
describe('frame-focusable-content-matches', function() { | ||
'use strict'; | ||
var rule; | ||
|
||
beforeEach(function() { | ||
rule = axe.utils.getRule('frame-focusable-content'); | ||
}); | ||
|
||
it('returns false for the top-level context', function() { | ||
var result = rule.matches(null, null, { | ||
initiator: true, | ||
focusable: false, | ||
boundingClientRect: { | ||
width: 100, | ||
height: 100 | ||
} | ||
}); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('returns false for focusable iframes', function() { | ||
var result = rule.matches(null, null, { | ||
initiator: false, | ||
focusable: true, | ||
boundingClientRect: { | ||
width: 100, | ||
height: 100 | ||
} | ||
}); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('returns false for non-focusable iframes that are too small (1x1)', function() { | ||
var result = rule.matches(null, null, { | ||
initiator: false, | ||
focusable: false, | ||
boundingClientRect: { | ||
width: 1, | ||
height: 1 | ||
} | ||
}); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('returns false for non-focusable iframes that are too small (0x0)', function() { | ||
var result = rule.matches(null, null, { | ||
initiator: false, | ||
focusable: false, | ||
boundingClientRect: { | ||
width: 0, | ||
height: 0 | ||
} | ||
}); | ||
assert.isFalse(result); | ||
}); | ||
|
||
it('returns true for non-focusable iframes', function() { | ||
var result = rule.matches(null, null, { | ||
initiator: false, | ||
focusable: false, | ||
boundingClientRect: { | ||
width: 2, | ||
height: 1 | ||
} | ||
}); | ||
assert.isTrue(result); | ||
}); | ||
}); |
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.
This prevents margin/border/padding CSS from affecting the width/height (otherwise in Chrome a width and height of 1 would result in a rect size of 5x5).