Skip to content

Commit e6875ee

Browse files
committed
fix(tabindex): don't error when tabindex property is overridden (#1910)
* fix(tabindex): dont error when tabindex attribute is overridden * solve for NaN * add radix * test rolling build
1 parent aa5314d commit e6875ee

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/checks/keyboard/tabindex.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
return node.tabIndex <= 0;
1+
const tabIndex = parseInt(node.getAttribute('tabindex'), 10);
2+
3+
// an invalid tabindex will either return 0 or -1 (based on the element) so
4+
// will never be above 0
5+
// @see https://www.w3.org/TR/html51/editing.html#the-tabindex-attribute
6+
return isNaN(tabIndex) ? true : tabIndex <= 0;

test/checks/keyboard/tabindex.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,21 @@ describe('tabindex', function() {
2222

2323
assert.isTrue(checks.tabindex.evaluate(node));
2424
});
25+
26+
it('should look at the attribute and not the property', function() {
27+
var node = document.createElement('div');
28+
node.setAttribute('tabindex', '1');
29+
node.tabindex = null;
30+
fixture.appendChild(node);
31+
32+
assert.isFalse(checks.tabindex.evaluate(node));
33+
});
34+
35+
it('should pass if tabindex is NaN', function() {
36+
var node = document.createElement('div');
37+
node.setAttribute('tabindex', 'foobar');
38+
fixture.appendChild(node);
39+
40+
assert.isTrue(checks.tabindex.evaluate(node));
41+
});
2542
});

0 commit comments

Comments
 (0)