diff --git a/lib/checks/keyboard/tabindex.js b/lib/checks/keyboard/tabindex.js index 709783dadb..ddfdc7ed51 100644 --- a/lib/checks/keyboard/tabindex.js +++ b/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; diff --git a/test/checks/keyboard/tabindex.js b/test/checks/keyboard/tabindex.js index 8ae2c90dc5..9c1b8ba49b 100644 --- a/test/checks/keyboard/tabindex.js +++ b/test/checks/keyboard/tabindex.js @@ -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)); + }); });