Skip to content

Commit 58f3130

Browse files
committed
fix: component unmount anim, close #1
1 parent 82df3a1 commit 58f3130

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rmc-dialog",
3-
"version": "0.0.1-alpha.0",
3+
"version": "0.0.1-alpha.1",
44
"description": "mobile dialog ui component for react",
55
"keywords": [
66
"react",
@@ -34,7 +34,7 @@
3434
"watch-tsc": "rc-tools run watch-tsc",
3535
"build": "rc-tools run build",
3636
"gh-pages": "rc-tools run gh-pages",
37-
"start": "DEMO_ENV=preact rc-tools run server",
37+
"start": "rc-tools run server",
3838
"compile": "rc-tools run compile --babel-runtime",
3939
"pub": "rc-tools run pub --babel-runtime",
4040
"lint": "rc-tools run lint --no-js-lint",

src/DialogWrap.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,26 @@ export default class DialogWrap extends React.Component<IDialogPropTypes, any> {
1919
}
2020
}
2121

22+
componentWillUnmount() {
23+
this.renderDialog(false);
24+
}
25+
2226
shouldComponentUpdate(nextProps) {
2327
return nextProps.visible !== this.props.visible;
2428
}
2529

2630
componentDidUpdate() {
27-
this.renderDialog();
31+
this.renderDialog(this.props.visible);
2832
}
2933

30-
getComponent() {
31-
return <Dialog {...this.props} onAnimateLeave={this.removeContainer} />;
34+
getComponent(visible) {
35+
const props = {...this.props};
36+
['visible', 'onAnimateLeave'].forEach(key => {
37+
if (props.hasOwnProperty(key)) {
38+
delete props[key];
39+
}
40+
});
41+
return <Dialog {...props} visible={visible} onAnimateLeave={this.removeContainer} />;
3242
}
3343

3444
removeContainer = () => {
@@ -39,7 +49,7 @@ export default class DialogWrap extends React.Component<IDialogPropTypes, any> {
3949
}
4050
}
4151

42-
renderDialog() {
52+
renderDialog(visible) {
4353
const prefixCls = this.props.prefixCls;
4454
let container = document.querySelector(`#${prefixCls}-container`);
4555
if (!container) {
@@ -49,7 +59,7 @@ export default class DialogWrap extends React.Component<IDialogPropTypes, any> {
4959
}
5060
ReactDOM.unstable_renderSubtreeIntoContainer(
5161
this,
52-
this.getComponent(),
62+
this.getComponent(visible),
5363
container,
5464
);
5565
}

tests/index.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable func-names */
22
import expect from 'expect.js';
33
import Dialog from '../index';
4-
import '../assets/bootstrap.less';
4+
// import '../assets/bootstrap.less';
55
import $ from 'jquery';
66
import React from 'react';
77
import ReactDOM from 'react-dom';
@@ -63,7 +63,7 @@ describe('dialog', () => {
6363
visible: true,
6464
});
6565
setTimeout(() => {
66-
expect($('.rc-dialog-wrap').css('display'))
66+
expect($('.rmc-dialog-wrap').css('display'))
6767
.to.be('block');
6868
done();
6969
}, 10);
@@ -77,20 +77,16 @@ describe('dialog', () => {
7777
visible: false,
7878
});
7979
setTimeout(() => {
80-
expect($('.rc-dialog-wrap').length).to.be(0);
80+
expect($('.rmc-dialog-wrap').length).to.be(0);
8181
done();
8282
}, 10);
8383
});
8484

85-
it('create', () => {
86-
expect($('.rc-dialog').length).to.be(0);
87-
});
88-
8985
it('mask', () => {
9086
dialog.setState({
9187
visible: true,
9288
});
93-
expect($('.rc-dialog-mask').length).to.be(1);
89+
expect($('.rmc-dialog-mask').length).to.be(1);
9490
});
9591

9692
it('click close', (finish) => {
@@ -100,12 +96,12 @@ describe('dialog', () => {
10096
});
10197
setTimeout(done, 10);
10298
}, (done) => {
103-
const btn = $('.rc-dialog-close')[0];
99+
const btn = $('.rmc-dialog-close')[0];
104100
Simulate.click(btn);
105101
setTimeout(done, 10);
106102
}, (done) => {
107103
expect(callback1).to.be(1);
108-
expect($('.rc-dialog-wrap').length).to.be(0);
104+
expect($('.rmc-dialog-wrap').length).to.be(0);
109105
done();
110106
}], finish);
111107
});
@@ -117,13 +113,13 @@ describe('dialog', () => {
117113
});
118114
setTimeout(done, 500);
119115
}, (done) => {
120-
const mask = $('.rc-dialog-wrap')[0];
116+
const mask = $('.rmc-dialog-wrap')[0];
121117
Simulate.click(mask);
122118
setTimeout(done, 10);
123119
}, (done) => {
124120
// dialog should closed after mask click
125121
expect(callback1).to.be(1);
126-
expect($('.rc-dialog-wrap').length).to.be(0);
122+
expect($('.rmc-dialog-wrap').length).to.be(0);
127123
done();
128124
}, (done) => {
129125
dialog.setState({
@@ -135,7 +131,7 @@ describe('dialog', () => {
135131
}, (done) => {
136132
// dialog should stay on visible after mask click if set maskClosable to false
137133
// expect(callback1).to.be(0);
138-
expect($('.rc-dialog-wrap').css('display'))
134+
expect($('.rmc-dialog-wrap').css('display'))
139135
.to.be('block');
140136
done();
141137
}], finish);

0 commit comments

Comments
 (0)