Skip to content

Commit aa5314d

Browse files
committed
fix(is-focusable): use tabindex attribute instead of property (#1912)
* fix(is-focusable): use tabindex attribute instead of property * typo
1 parent f189a02 commit aa5314d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/commons/dom/is-focusable.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ dom.isNativelyFocusable = function(el) {
8383
* if its tabindex were removed. Else, false.
8484
*/
8585
dom.insertedIntoFocusOrder = function(el) {
86-
return (
87-
el.tabIndex > -1 && dom.isFocusable(el) && !dom.isNativelyFocusable(el)
88-
);
86+
let tabIndex = parseInt(el.getAttribute('tabindex'), 10);
87+
88+
// an element that has an invalid tabindex will return 0 or -1 based on
89+
// if it is natively focusable or not, which will always be false for this
90+
// check as NaN is not > 1
91+
// @see https://www.w3.org/TR/html51/editing.html#the-tabindex-attribute
92+
return tabIndex > -1 && dom.isFocusable(el) && !dom.isNativelyFocusable(el);
8993
};

test/commons/dom/is-focusable.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,12 @@ describe('is-focusable', function() {
563563

564564
assert.isFalse(axe.commons.dom.insertedIntoFocusOrder(node));
565565
});
566+
567+
it('should return false for an invalid tabindex', function() {
568+
fixtureSetup('<span id="spanTabindexInvalid" tabindex="invalid"></span>');
569+
var node = fixture.querySelector('#spanTabindexInvalid');
570+
571+
assert.isFalse(axe.commons.dom.insertedIntoFocusOrder(node));
572+
});
566573
});
567574
});

0 commit comments

Comments
 (0)