Skip to content

Commit 8088972

Browse files
committed
多个Dialog同时显示时的层次问题
close ant-design/ant-design#1546
1 parent 716d222 commit 8088972

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

assets/index/Mask.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
.@{prefixCls} {
2+
&-container{
3+
position: absolute;
4+
top: 0;
5+
left: 0;
6+
z-index: 990;
7+
}
28
&-mask {
39
position: fixed;
410
top: 0;

examples/multiple.html

Whitespace-only changes.

examples/multiple.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* eslint no-console:0 */
2+
3+
import 'rc-dialog/assets/index.less';
4+
import React from 'react';
5+
import ReactDOM from 'react-dom';
6+
import Dialog from 'rc-dialog';
7+
8+
const MyControl = React.createClass({
9+
getInitialState() {
10+
return {
11+
visible: false,
12+
visible2: false,
13+
width: 600,
14+
destroyOnClose: false,
15+
};
16+
},
17+
18+
onClick(e) {
19+
this.setState({
20+
mousePosition: {
21+
x: e.pageX,
22+
y: e.pageY,
23+
},
24+
visible: true,
25+
});
26+
},
27+
onClick2() {
28+
this.setState({
29+
visible2: true,
30+
});
31+
},
32+
33+
onClose(e) {
34+
console.log(e);
35+
this.setState({
36+
visible: false,
37+
});
38+
},
39+
40+
onClose2() {
41+
this.setState({
42+
visible2: false,
43+
});
44+
},
45+
46+
onDestroyOnCloseChange(e) {
47+
this.setState({
48+
destroyOnClose: e.target.checked,
49+
});
50+
},
51+
52+
changeWidth() {
53+
this.setState({
54+
width: this.state.width === 600 ? 800 : 600,
55+
});
56+
},
57+
58+
render() {
59+
let dialog;
60+
let dialog2;
61+
if (this.state.visible || !this.state.destroyOnClose) {
62+
dialog = (
63+
<Dialog
64+
visible={this.state.visible}
65+
animation="zoom"
66+
maskAnimation="fade"
67+
onClose={this.onClose}
68+
style={{ width: this.state.width }}
69+
mousePosition={this.state.mousePosition}
70+
title={<div>第一个弹框</div>}
71+
>
72+
<input />
73+
<p>basic modal</p>
74+
<button onClick={this.onClick2}> Open Second Dialog</button>
75+
<div style={{ height: 200 }}></div>
76+
</Dialog>
77+
);
78+
}
79+
if (this.state.visible2) {
80+
dialog2 = (
81+
<Dialog
82+
visible={this.state.visible2}
83+
animation="zoom"
84+
maskAnimation="fade"
85+
onClose={this.onClose2}
86+
mousePosition={this.state.mousePosition}
87+
title={<div>第二个弹框</div>}
88+
>
89+
<input />
90+
<p> SecondModal </p>
91+
</Dialog>
92+
);
93+
}
94+
95+
return (
96+
<div>
97+
<p>
98+
<button className="btn btn-primary" onClick={this.onClick}>show dialog</button>
99+
&nbsp;
100+
<label>destroy on close:
101+
<input
102+
type="checkbox"
103+
checked={this.state.destroyOnClose}
104+
onChange={this.onDestroyOnCloseChange}
105+
/>
106+
</label>
107+
</p>
108+
{dialog}
109+
{dialog2}
110+
</div>
111+
);
112+
},
113+
});
114+
115+
ReactDOM.render(
116+
<div>
117+
<h2>ant-design dialog</h2>
118+
<MyControl />
119+
</div>,
120+
document.getElementById('__react-content')
121+
);

src/DialogWrap.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class DialogWrap extends React.Component {
7070
getDialogContainer() {
7171
if (!this.dialogContainer) {
7272
this.dialogContainer = document.createElement('div');
73+
const dialogProps = copy(this.props, ['prefixCls']);
74+
this.dialogContainer.className = `${dialogProps.prefixCls}-container`;
7375
document.body.appendChild(this.dialogContainer);
7476
}
7577
return this.dialogContainer;

0 commit comments

Comments
 (0)