Skip to content

Commit

Permalink
Merge pull request react-bootstrap#1079 from zerkms/modal-unmount
Browse files Browse the repository at this point in the history
Modal: added finalisation for the component when it was unbound from the tree
  • Loading branch information
taion committed Jul 30, 2015
2 parents 9b8089d + a4ce7e1 commit 96ef53a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions test/ModalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ describe('Modal', function () {
, mountPoint);
});

it('Should unbind listeners when unmounted', function() {
render(
<div>
<Modal show onHide={() => null} animation={false}>
<strong>Foo bar</strong>
</Modal>
</div>
, mountPoint);

assert.include(document.body.className, 'modal-open');

render(<div />, mountPoint);

assert.notInclude(document.body.className, 'modal-open');
});

describe('Focused state', function () {
let focusableContainer = null;

Expand Down

0 comments on commit 96ef53a

Please sign in to comment.