Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] clear the delayed close timer when modal opens again. #189

Merged
merged 2 commits into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -104,8 +109,9 @@ var ModalPortal = module.exports = React.createClass({

closeWithoutTimeout: function() {
this.setState({
beforeClose: false,
isOpen: false,
afterOpen: false,
beforeClose: false
}, this.afterClose);
},

Expand Down
14 changes: 14 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down