Skip to content

Commit

Permalink
fix(frame-title): ignore frames with negative tabindex
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Jun 27, 2022
1 parent 1b1eb91 commit f61f825
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/frame-title.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"id": "frame-title",
"selector": "frame, iframe",
"matches": "no-negative-tabindex-matches",
"tags": [
"cat.text-alternatives",
"wcag2a",
Expand Down
6 changes: 6 additions & 0 deletions lib/rules/no-negative-tabindex-matches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function noNegativeTabindexMatches(node, virtualNode) {
const tabindex = parseInt(virtualNode.attr('tabindex'), 10);
return isNaN(tabindex) || tabindex >= 0;
}

export default noNegativeTabindexMatches;
5 changes: 5 additions & 0 deletions test/integration/rules/frame-title/frame-title.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@
role="presentation"
tabindex="0"
></iframe>
<iframe
src="/integration/rules/frame-title/frames/level1a.html"
id="inapplicable1"
tabindex="-1"
></iframe>
41 changes: 41 additions & 0 deletions test/rule-matches/no-negative-tabindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
describe('no-negative-tabindex-matches', function() {
'use strict';

var fixture = document.getElementById('fixture');
var queryFixture = axe.testUtils.queryFixture;
var rule = axe.utils.getRule('frame-title');

afterEach(function() {
fixture.innerHTML = '';
});

it('returns true for nodes with no tabindex', function() {
var vNode = queryFixture('<div id="target"></div>');
var actual = rule.matches(null, vNode);
assert.isTrue(actual);
});

it('returns true for nodes with a zero tabindex', function() {
var vNode = queryFixture('<div id="target" tabindex="0"></div>');
var actual = rule.matches(null, vNode);
assert.isTrue(actual);
});

it('returns true for nodes with a positive tabindex', function() {
var vNode = queryFixture('<div id="target" tabindex="4"></div>');
var actual = rule.matches(null, vNode);
assert.isTrue(actual);
});

it('returns true for nodes with an invalid tabindex', function() {
var vNode = queryFixture('<div id="target" tabindex="foo"></div>');
var actual = rule.matches(null, vNode);
assert.isTrue(actual);
});

it('returns false for nodes with an invalid tabindex', function() {
var vNode = queryFixture('<div id="target" tabindex="-10"></div>');
var actual = rule.matches(null, vNode);
assert.isFalse(actual);
});
});

0 comments on commit f61f825

Please sign in to comment.