Skip to content

Commit

Permalink
fix(is-focusable): use tabindex attribute instead of property (#1912)
Browse files Browse the repository at this point in the history
* fix(is-focusable): use tabindex attribute instead of property

* typo
  • Loading branch information
straker committed Nov 21, 2019
1 parent 19a75c6 commit 042a148
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/commons/dom/is-focusable.js
Expand Up @@ -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);
};
7 changes: 7 additions & 0 deletions test/commons/dom/is-focusable.js
Expand Up @@ -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('<span id="spanTabindexInvalid" tabindex="invalid"></span>');
var node = fixture.querySelector('#spanTabindexInvalid');

assert.isFalse(axe.commons.dom.insertedIntoFocusOrder(node));
});
});
});

0 comments on commit 042a148

Please sign in to comment.