Skip to content

Commit 1e0fa81

Browse files
sjolicoeurpivotal
authored andcommitted
Fixed warning when unmounting animated modals
Signed-off-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent 8ac9be5 commit 1e0fa81

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

spec/pivotal-ui-react/modals/modals_spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '../spec_helper';
22
import {findByClass, findAllByClass, clickOn} from '../spec_helper';
33
import {Modal, BaseModal} from '../../../src/react/modals';
4+
import AnimationMixin from 'pui-react-animation';
45

56
let result;
67

@@ -238,6 +239,20 @@ describe('BaseModal', () => {
238239

239240
expect(onHide).not.toHaveBeenCalled();
240241
});
242+
243+
describe('when animation is true', () => {
244+
beforeEach(() => {
245+
spyOn(AnimationMixin, 'componentWillUnmount').and.callThrough();
246+
});
247+
248+
it('resets animation if unmounted before animation finishes', () => {
249+
result = renderIntoDom({show: true, onHide, animation: true});
250+
ReactDOM.unmountComponentAtNode(root);
251+
MockRaf.next();
252+
253+
expect(AnimationMixin.componentWillUnmount).toHaveBeenCalled();
254+
});
255+
});
241256
});
242257

243258
describe('acquireFocus', () => {

src/react/modals/modals.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export class BaseModal extends mixin(React.PureComponent).with(Animation) {
7676
}
7777

7878
componentWillUnmount() {
79+
if (super.componentWillUnmount) super.componentWillUnmount();
7980
const document = this.props.getDocument();
8081
if (typeof document !== 'object') return;
8182
document.removeEventListener('keydown', this.onKeyDown);

0 commit comments

Comments
 (0)