Skip to content

Commit

Permalink
[fixed] onAfterClose prop falsly called on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
gados3 authored and diasbruno committed Aug 21, 2019
1 parent 1b80146 commit 8a71f71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scripts/__pycache__/
examples/**/*-bundle.js
node_modules/
.idea/
.vscode
_book
*.patch
*.diff
Expand Down
17 changes: 16 additions & 1 deletion specs/Modal.events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
escKeyDown,
tabKeyDown,
renderModal,
emptyDOM
emptyDOM,
unmountModal
} from "./helper";

export default () => {
Expand All @@ -36,6 +37,20 @@ export default () => {
onAfterCloseCallback.called.should.be.ok();
});

it("should not trigger onAfterClose callback when unmounting a closed modal", () => {
const onAfterCloseCallback = sinon.spy();
renderModal({ isOpen: false, onAfterClose: onAfterCloseCallback });
unmountModal();
onAfterCloseCallback.called.should.not.be.ok();
});

it("should trigger onAfterClose callback when unmounting an opened modal", () => {
const onAfterCloseCallback = sinon.spy();
renderModal({ isOpen: true, onAfterClose: onAfterCloseCallback });
unmountModal();
onAfterCloseCallback.called.should.be.ok();
});

it("keeps focus inside the modal when child has no tabbable elements", () => {
let tabPrevented = false;
const modal = renderModal({ isOpen: true }, "hello");
Expand Down
4 changes: 3 additions & 1 deletion src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export default class ModalPortal extends Component {
}

componentWillUnmount() {
this.afterClose();
if (this.state.isOpen) {
this.afterClose();
}
clearTimeout(this.closeTimer);
}

Expand Down

0 comments on commit 8a71f71

Please sign in to comment.