diff --git a/lib/commons/dom/is-focusable.js b/lib/commons/dom/is-focusable.js index 739c5652ab..ec272614bd 100644 --- a/lib/commons/dom/is-focusable.js +++ b/lib/commons/dom/is-focusable.js @@ -83,7 +83,11 @@ dom.isNativelyFocusable = function(el) { * if its tabindex were removed. Else, false. */ dom.insertedIntoFocusOrder = function(el) { - return ( - el.tabIndex > -1 && dom.isFocusable(el) && !dom.isNativelyFocusable(el) - ); + let tabIndex = parseInt(el.getAttribute('tabindex'), 10); + + // an element that has an invalid tabindex will return 0 or -1 based on + // if it is natively focusable or not, which will always be false for this + // check as NaN is not > 1 + // @see https://www.w3.org/TR/html51/editing.html#the-tabindex-attribute + return tabIndex > -1 && dom.isFocusable(el) && !dom.isNativelyFocusable(el); }; diff --git a/test/commons/dom/is-focusable.js b/test/commons/dom/is-focusable.js index 59f7b35c91..72835d63b3 100644 --- a/test/commons/dom/is-focusable.js +++ b/test/commons/dom/is-focusable.js @@ -563,5 +563,12 @@ describe('is-focusable', function() { assert.isFalse(axe.commons.dom.insertedIntoFocusOrder(node)); }); + + it('should return false for an invalid tabindex', function() { + fixtureSetup(''); + var node = fixture.querySelector('#spanTabindexInvalid'); + + assert.isFalse(axe.commons.dom.insertedIntoFocusOrder(node)); + }); }); });