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 @@ -100,6 +100,19 @@ describe('Modal', function () {
100
100
unmountModal ( ) ;
101
101
} ) ;
102
102
103
+ it ( 'keeps focus inside the modal when child has no tabbable elements' , function ( ) {
104
+ var tabPrevented = false ;
105
+ var modal = renderModal ( { isOpen : true } , 'hello' ) ;
106
+ strictEqual ( document . activeElement , modal . portal . refs . content ) ;
107
+ Simulate . keyDown ( modal . portal . refs . content , {
108
+ key : "Tab" ,
109
+ keyCode : 9 ,
110
+ which : 9 ,
111
+ preventDefault : function ( ) { tabPrevented = true ; }
112
+ } ) ;
113
+ equal ( tabPrevented , true ) ;
114
+ } ) ;
115
+
103
116
it ( 'supports custom className' , function ( ) {
104
117
var modal = renderModal ( { isOpen : true , className : 'myClass' } ) ;
105
118
equal ( modal . portal . refs . content . className . contains ( 'myClass' ) , true ) ;
You can’t perform that action at this time.
0 commit comments