File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 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');
22
33module . exports = function ( node , event ) {
44 var tabbable = findTabbable ( node ) ;
5- if ( ! tabbable . length ) return ;
5+ if ( ! tabbable . length ) {
6+ event . preventDefault ( ) ;
7+ return ;
8+ }
69 var finalTabbable = tabbable [ event . shiftKey ? 0 : tabbable . length - 1 ] ;
710 var leavingFinalTabbable = (
811 finalTabbable === document . activeElement ||
Original file line number Diff line number Diff line change @@ -100,6 +100,19 @@ describe('Modal', function () {
100100 unmountModal ( ) ;
101101 } ) ;
102102
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+
103116 it ( 'supports custom className' , function ( ) {
104117 var modal = renderModal ( { isOpen : true , className : 'myClass' } ) ;
105118 equal ( modal . portal . refs . content . className . contains ( 'myClass' ) , true ) ;
You can’t perform that action at this time.
0 commit comments