Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dialog is not visible, when initialize dialog with forceRender a… #194

Merged
merged 2 commits into from Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,7 @@ notifications:
- hust2012jiangkai@gmail.com

node_js:
- 6.9.1
- 10

before_install:
- |
Expand Down
34 changes: 34 additions & 0 deletions examples/ant-design.tsx
Expand Up @@ -31,6 +31,7 @@ class MyControl extends React.Component<any, any> {
state = {
visible: false,
visible2: false,
visible3: true,
width: 600,
destroyOnClose: false,
center: false,
Expand Down Expand Up @@ -62,6 +63,10 @@ class MyControl extends React.Component<any, any> {
});
}

onClose3 = (e: React.SyntheticEvent) => {
this.setState({ visible3: false });
}

onDestroyOnCloseChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.setState({
destroyOnClose: e.target.checked,
Expand Down Expand Up @@ -143,6 +148,13 @@ class MyControl extends React.Component<any, any> {
>
<input autoFocus />
<p>basic modal</p>
<button onClick={() => {
this.setState({
visible: true,
visible2: true,
visible3: true,
});
}}>打开第三个</button>
<button onClick={() => {
this.setState({
visible2: false,
Expand All @@ -157,6 +169,27 @@ class MyControl extends React.Component<any, any> {
</Dialog>
);

const dialog3 = (
<Dialog
forceRender
visible={this.state.visible3}
onClose={this.onClose3}
>
<p>initialized with forceRender and visbile true</p>
<button onClick={() => {
this.setState({
visible3: false,
});
}}>关闭当前</button>
<button onClick={this.onClose2}>关闭所有</button>
<button onClick={this.changeWidth}>change width</button>
<button onClick={this.toggleCloseIcon}>
use custom icon, is using icon: {this.state.useIcon && 'true' || 'false'}.
</button>
<div style={{ height: 200 }} />
</Dialog>
);

return (
<div style={{ width: '90%', margin: '0 auto' }}>
<style>
Expand Down Expand Up @@ -202,6 +235,7 @@ class MyControl extends React.Component<any, any> {
</p>
{dialog}
{dialog2}
{dialog3}
</div>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Dialog.tsx
Expand Up @@ -83,6 +83,9 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
componentDidMount() {
this.componentDidUpdate({});
// if forceRender is true, set element style display to be none;
if (this.props.forceRender && this.props.visible) {
return;
}
if (
(this.props.forceRender || (this.props.getContainer === false && !this.props.visible)) &&
this.wrap
Expand Down
30 changes: 30 additions & 0 deletions tests/index.js
Expand Up @@ -432,4 +432,34 @@ describe('dialog', () => {
expect($('.rc-dialog-wrap').css("zIndex")).to.be('1000');

});

it('should show dialog when initialize dialog, given forceRender and visible is true', () => {
class DialogWrap extends React.Component {
state = {
visible: true,
forceRender: true,
};
render() {
return (
<Dialog
forceRender={this.state.forceRender}
visible={this.state.visible}
/>
);
}
}
ReactDOM.render((
<DialogWrap
visible
forceRender
>
<div>Show dialog with forceRender and visible is true</div>
</DialogWrap>
),container);
setTimeout(() => {
expect($('.rc-dialog-wrap').css('display'))
.to.be('block');
done();
}, 10);
});
});