File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,11 @@ dom.isNativelyFocusable = function(el) {
83
83
* if its tabindex were removed. Else, false.
84
84
*/
85
85
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 ) ;
89
93
} ;
Original file line number Diff line number Diff line change @@ -563,5 +563,12 @@ describe('is-focusable', function() {
563
563
564
564
assert . isFalse ( axe . commons . dom . insertedIntoFocusOrder ( node ) ) ;
565
565
} ) ;
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
+ } ) ;
566
573
} ) ;
567
574
} ) ;
You can’t perform that action at this time.
0 commit comments