File tree Expand file tree Collapse file tree 2 files changed +30
-10
lines changed
Expand file tree Collapse file tree 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({
7272 } ,
7373
7474 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+ }
8489 } ,
8590
8691 close : function ( ) {
@@ -104,8 +109,9 @@ var ModalPortal = module.exports = React.createClass({
104109
105110 closeWithoutTimeout : function ( ) {
106111 this . setState ( {
112+ beforeClose : false ,
113+ isOpen : false ,
107114 afterOpen : false ,
108- beforeClose : false
109115 } , this . afterClose ) ;
110116 } ,
111117
Original file line number Diff line number Diff line change @@ -200,6 +200,20 @@ describe('Modal', function () {
200200 unmountModal ( ) ;
201201 } ) ;
202202
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+
203217 describe ( 'should close on overlay click' , function ( ) {
204218 afterEach ( 'Unmount modal' , function ( ) {
205219 unmountModal ( ) ;
You can’t perform that action at this time.
0 commit comments