File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ var findTabbable = require('../helpers/tabbable');
2
2
3
3
module . exports = function ( node , event ) {
4
4
var tabbable = findTabbable ( node ) ;
5
- if ( ! tabbable . length ) return ;
5
+ if ( ! tabbable . length ) {
6
+ event . preventDefault ( ) ;
7
+ return ;
8
+ }
6
9
var finalTabbable = tabbable [ event . shiftKey ? 0 : tabbable . length - 1 ] ;
7
10
var leavingFinalTabbable = (
8
11
finalTabbable === document . activeElement ||
Original file line number Diff line number Diff line change @@ -102,6 +102,19 @@ describe('Modal', function () {
102
102
unmountModal ( ) ;
103
103
} ) ;
104
104
105
+ it ( 'keeps focus inside the modal when child has no tabbable elements' , function ( ) {
106
+ var tabPrevented = false ;
107
+ var modal = renderModal ( { isOpen : true } , 'hello' ) ;
108
+ strictEqual ( document . activeElement , modal . portal . refs . content ) ;
109
+ Simulate . keyDown ( modal . portal . refs . content , {
110
+ key : "Tab" ,
111
+ keyCode : 9 ,
112
+ which : 9 ,
113
+ preventDefault : function ( ) { tabPrevented = true ; }
114
+ } ) ;
115
+ equal ( tabPrevented , true ) ;
116
+ } ) ;
117
+
105
118
it ( 'supports custom className' , function ( ) {
106
119
var modal = renderModal ( { isOpen : true , className : 'myClass' } ) ;
107
120
notEqual ( modal . portal . refs . content . className . indexOf ( 'myClass' ) , - 1 ) ;
You can’t perform that action at this time.
0 commit comments