Skip to content

Commit 1531fe1

Browse files
fix: dialog is not visible, when initialize dialog with forceRender a… (#194)
* fix: dialog is not visible, when initialize dialog with forceRender and visible is true * Update .travis.yml Co-authored-by: 偏右 <[email protected]>
1 parent d96907a commit 1531fe1

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ notifications:
88
99

1010
node_js:
11-
- 6.9.1
11+
- 10
1212

1313
before_install:
1414
- |

examples/ant-design.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MyControl extends React.Component<any, any> {
3131
state = {
3232
visible: false,
3333
visible2: false,
34+
visible3: true,
3435
width: 600,
3536
destroyOnClose: false,
3637
center: false,
@@ -62,6 +63,10 @@ class MyControl extends React.Component<any, any> {
6263
});
6364
}
6465

66+
onClose3 = (e: React.SyntheticEvent) => {
67+
this.setState({ visible3: false });
68+
}
69+
6570
onDestroyOnCloseChange = (e: React.ChangeEvent<HTMLInputElement>) => {
6671
this.setState({
6772
destroyOnClose: e.target.checked,
@@ -143,6 +148,13 @@ class MyControl extends React.Component<any, any> {
143148
>
144149
<input autoFocus />
145150
<p>basic modal</p>
151+
<button onClick={() => {
152+
this.setState({
153+
visible: true,
154+
visible2: true,
155+
visible3: true,
156+
});
157+
}}>打开第三个</button>
146158
<button onClick={() => {
147159
this.setState({
148160
visible2: false,
@@ -157,6 +169,27 @@ class MyControl extends React.Component<any, any> {
157169
</Dialog>
158170
);
159171

172+
const dialog3 = (
173+
<Dialog
174+
forceRender
175+
visible={this.state.visible3}
176+
onClose={this.onClose3}
177+
>
178+
<p>initialized with forceRender and visbile true</p>
179+
<button onClick={() => {
180+
this.setState({
181+
visible3: false,
182+
});
183+
}}>关闭当前</button>
184+
<button onClick={this.onClose2}>关闭所有</button>
185+
<button onClick={this.changeWidth}>change width</button>
186+
<button onClick={this.toggleCloseIcon}>
187+
use custom icon, is using icon: {this.state.useIcon && 'true' || 'false'}.
188+
</button>
189+
<div style={{ height: 200 }} />
190+
</Dialog>
191+
);
192+
160193
return (
161194
<div style={{ width: '90%', margin: '0 auto' }}>
162195
<style>
@@ -202,6 +235,7 @@ class MyControl extends React.Component<any, any> {
202235
</p>
203236
{dialog}
204237
{dialog2}
238+
{dialog3}
205239
</div>
206240
);
207241
}

src/Dialog.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
8383
componentDidMount() {
8484
this.componentDidUpdate({});
8585
// if forceRender is true, set element style display to be none;
86+
if (this.props.forceRender && this.props.visible) {
87+
return;
88+
}
8689
if (
8790
(this.props.forceRender || (this.props.getContainer === false && !this.props.visible)) &&
8891
this.wrap

tests/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,34 @@ describe('dialog', () => {
432432
expect($('.rc-dialog-wrap').css("zIndex")).to.be('1000');
433433

434434
});
435+
436+
it('should show dialog when initialize dialog, given forceRender and visible is true', () => {
437+
class DialogWrap extends React.Component {
438+
state = {
439+
visible: true,
440+
forceRender: true,
441+
};
442+
render() {
443+
return (
444+
<Dialog
445+
forceRender={this.state.forceRender}
446+
visible={this.state.visible}
447+
/>
448+
);
449+
}
450+
}
451+
ReactDOM.render((
452+
<DialogWrap
453+
visible
454+
forceRender
455+
>
456+
<div>Show dialog with forceRender and visible is true</div>
457+
</DialogWrap>
458+
),container);
459+
setTimeout(() => {
460+
expect($('.rc-dialog-wrap').css('display'))
461+
.to.be('block');
462+
done();
463+
}, 10);
464+
});
435465
});

0 commit comments

Comments
 (0)