From a4ce7e1aeb589a408261de9898933c3f7b61102e Mon Sep 17 00:00:00 2001 From: Ivan Kurnosov Date: Wed, 29 Jul 2015 21:53:29 +1200 Subject: [PATCH] [fixed] added finalisation for the Modal when it was unbound from the tree --- src/Modal.js | 6 ++++++ test/ModalSpec.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Modal.js b/src/Modal.js index 7a24bd1b2d..78c983bc96 100644 --- a/src/Modal.js +++ b/src/Modal.js @@ -277,6 +277,12 @@ const Modal = React.createClass({ } }, + componentWillUnmount() { + if (this.props.show) { + this.onHide(); + } + }, + onShow() { const doc = domUtils.ownerDocument(this); const win = domUtils.ownerWindow(this); diff --git a/test/ModalSpec.js b/test/ModalSpec.js index 019a4925a1..7ea08e9260 100644 --- a/test/ModalSpec.js +++ b/test/ModalSpec.js @@ -197,6 +197,22 @@ describe('Modal', function () { , mountPoint); }); + it('Should unbind listeners when unmounted', function() { + render( +
+ null} animation={false}> + Foo bar + +
+ , mountPoint); + + assert.include(document.body.className, 'modal-open'); + + render(
, mountPoint); + + assert.notInclude(document.body.className, 'modal-open'); + }); + describe('Focused state', function () { let focusableContainer = null;