Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});
});