Skip to content

Commit

Permalink
fix(tabindex): don't error when tabindex property is overridden (#1910)
Browse files Browse the repository at this point in the history
* fix(tabindex): dont error when tabindex attribute is overridden

* solve for NaN

* add radix

* test rolling build
  • Loading branch information
straker committed Nov 21, 2019
1 parent 042a148 commit 6b82a4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/checks/keyboard/tabindex.js
@@ -1 +1,6 @@
return node.tabIndex <= 0;
const tabIndex = parseInt(node.getAttribute('tabindex'), 10);

// an invalid tabindex will either return 0 or -1 (based on the element) so
// will never be above 0
// @see https://www.w3.org/TR/html51/editing.html#the-tabindex-attribute
return isNaN(tabIndex) ? true : tabIndex <= 0;
17 changes: 17 additions & 0 deletions test/checks/keyboard/tabindex.js
Expand Up @@ -22,4 +22,21 @@ describe('tabindex', function() {

assert.isTrue(checks.tabindex.evaluate(node));
});

it('should look at the attribute and not the property', function() {
var node = document.createElement('div');
node.setAttribute('tabindex', '1');
node.tabindex = null;
fixture.appendChild(node);

assert.isFalse(checks.tabindex.evaluate(node));
});

it('should pass if tabindex is NaN', function() {
var node = document.createElement('div');
node.setAttribute('tabindex', 'foobar');
fixture.appendChild(node);

assert.isTrue(checks.tabindex.evaluate(node));
});
});

0 comments on commit 6b82a4c

Please sign in to comment.