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;