File tree 2 files changed +30
-10
lines changed
2 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -72,15 +72,20 @@ var ModalPortal = module.exports = React.createClass({
72
72
} ,
73
73
74
74
open : function ( ) {
75
- focusManager . setupScopedFocus ( this . node ) ;
76
- focusManager . markForFocusLater ( ) ;
77
- this . setState ( { isOpen : true } , function ( ) {
78
- this . setState ( { afterOpen : true } ) ;
79
-
80
- if ( this . props . isOpen && this . props . onAfterOpen ) {
81
- this . props . onAfterOpen ( ) ;
82
- }
83
- } . bind ( this ) ) ;
75
+ if ( this . state . afterOpen && this . state . beforeClose ) {
76
+ clearTimeout ( this . closeTimer ) ;
77
+ this . setState ( { beforeClose : false } ) ;
78
+ } else {
79
+ focusManager . setupScopedFocus ( this . node ) ;
80
+ focusManager . markForFocusLater ( ) ;
81
+ this . setState ( { isOpen : true } , function ( ) {
82
+ this . setState ( { afterOpen : true } ) ;
83
+
84
+ if ( this . props . isOpen && this . props . onAfterOpen ) {
85
+ this . props . onAfterOpen ( ) ;
86
+ }
87
+ } . bind ( this ) ) ;
88
+ }
84
89
} ,
85
90
86
91
close : function ( ) {
@@ -104,8 +109,9 @@ var ModalPortal = module.exports = React.createClass({
104
109
105
110
closeWithoutTimeout : function ( ) {
106
111
this . setState ( {
112
+ beforeClose : false ,
113
+ isOpen : false ,
107
114
afterOpen : false ,
108
- beforeClose : false
109
115
} , this . afterClose ) ;
110
116
} ,
111
117
Original file line number Diff line number Diff line change @@ -200,6 +200,20 @@ describe('Modal', function () {
200
200
unmountModal ( ) ;
201
201
} ) ;
202
202
203
+ it ( 'check the state of the modal after close with time out and reopen it' , function ( ) {
204
+ var afterOpenCallback = sinon . spy ( ) ;
205
+ var modal = renderModal ( {
206
+ isOpen : true ,
207
+ closeTimeoutMS : 2000 ,
208
+ onRequestClose : function ( ) { }
209
+ } ) ;
210
+ modal . portal . closeWithTimeout ( ) ;
211
+ modal . portal . open ( ) ;
212
+ modal . portal . closeWithoutTimeout ( ) ;
213
+ ok ( ! modal . portal . state . isOpen ) ;
214
+ unmountModal ( ) ;
215
+ } ) ;
216
+
203
217
describe ( 'should close on overlay click' , function ( ) {
204
218
afterEach ( 'Unmount modal' , function ( ) {
205
219
unmountModal ( ) ;
You can’t perform that action at this time.
0 commit comments