From c3f8a51c3d1d47fa0fda554cb5c05a0019836755 Mon Sep 17 00:00:00 2001 From: Ives van Hoorne Date: Wed, 9 Mar 2016 16:42:26 +0100 Subject: [PATCH 1/2] [fixed] Clear the delayed close timer when modal opens again --- lib/components/ModalPortal.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/components/ModalPortal.js b/lib/components/ModalPortal.js index 56dc3076..c38c0878 100644 --- a/lib/components/ModalPortal.js +++ b/lib/components/ModalPortal.js @@ -72,15 +72,20 @@ var ModalPortal = module.exports = React.createClass({ }, open: function() { - focusManager.setupScopedFocus(this.node); - focusManager.markForFocusLater(); - this.setState({isOpen: true}, function() { - this.setState({afterOpen: true}); - - if (this.props.isOpen && this.props.onAfterOpen) { - this.props.onAfterOpen(); - } - }.bind(this)); + if (this.state.afterOpen && this.state.beforeClose) { + clearTimeout(this.closeTimer); + this.setState({ beforeClose: false }); + } else { + focusManager.setupScopedFocus(this.node); + focusManager.markForFocusLater(); + this.setState({isOpen: true}, function() { + this.setState({afterOpen: true}); + + if (this.props.isOpen && this.props.onAfterOpen) { + this.props.onAfterOpen(); + } + }.bind(this)); + } }, close: function() { From a032778133efd8a8ba24b420f63b469847af32bc Mon Sep 17 00:00:00 2001 From: Bruno Dias Date: Tue, 31 May 2016 10:52:37 -0300 Subject: [PATCH 2/2] [fixed] added test for the timeout case. continuation of the PR #134. thanks, @CompuIves. --- lib/components/ModalPortal.js | 3 ++- specs/Modal.spec.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/components/ModalPortal.js b/lib/components/ModalPortal.js index c38c0878..5e887b4f 100644 --- a/lib/components/ModalPortal.js +++ b/lib/components/ModalPortal.js @@ -109,8 +109,9 @@ var ModalPortal = module.exports = React.createClass({ closeWithoutTimeout: function() { this.setState({ + beforeClose: false, + isOpen: false, afterOpen: false, - beforeClose: false }, this.afterClose); }, diff --git a/specs/Modal.spec.js b/specs/Modal.spec.js index 3fb2f967..bafbbbcb 100644 --- a/specs/Modal.spec.js +++ b/specs/Modal.spec.js @@ -200,6 +200,20 @@ describe('Modal', function () { unmountModal(); }); + it('check the state of the modal after close with time out and reopen it', function() { + var afterOpenCallback = sinon.spy(); + var modal = renderModal({ + isOpen: true, + closeTimeoutMS: 2000, + onRequestClose: function() {} + }); + modal.portal.closeWithTimeout(); + modal.portal.open(); + modal.portal.closeWithoutTimeout(); + ok(!modal.portal.state.isOpen); + unmountModal(); + }); + describe('should close on overlay click', function() { afterEach('Unmount modal', function() { unmountModal();