Skip to content

Commit 8f5510a

Browse files
Merge pull request mui#1996 from JorgenEvens/feature/dialog-show-prop
[Dialog] Allow open state of dialog to be controlled through the show prop
2 parents dfb8363 + 801e05a commit 8f5510a

File tree

5 files changed

+156
-63
lines changed

5 files changed

+156
-63
lines changed

docs/src/app/components/pages/components/dialog.jsx

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export default class DialogPage extends React.Component {
1111
super();
1212
this.state = {
1313
modal: false,
14+
showDialogStandardActions: false,
15+
showDialogCustomActions: false,
16+
showDialogScrollable: false,
1417
};
1518
this._handleCustomDialogCancel = this._handleCustomDialogCancel.bind(this);
1619
this._handleCustomDialogSubmit = this._handleCustomDialogSubmit.bind(this);
@@ -19,6 +22,7 @@ export default class DialogPage extends React.Component {
1922
this._handleCustomDialogTouchTap = this._handleCustomDialogTouchTap.bind(this);
2023
this._handleStandardDialogTouchTap = this._handleStandardDialogTouchTap.bind(this);
2124
this._handleScrollableDialogTouchTap = this._handleScrollableDialogTouchTap.bind(this);
25+
this._handleRequestClose = this._handleRequestClose.bind(this);
2226
this._handleToggleChange = this._handleToggleChange.bind(this);
2327
}
2428

@@ -69,8 +73,20 @@ export default class DialogPage extends React.Component {
6973
name: 'openImmediately',
7074
type: 'bool',
7175
header: 'default: false',
76+
desc: 'Deprecated: Set to true to have the dialog automatically open on mount.',
77+
},
78+
{
79+
name: 'defaultIsOpen',
80+
type: 'bool',
81+
header: 'default: false',
7282
desc: 'Set to true to have the dialog automatically open on mount.',
7383
},
84+
{
85+
name: 'isOpen',
86+
type: 'bool',
87+
header: 'default: null',
88+
desc: 'Controls whether the Dialog is opened or not.',
89+
},
7490
{
7591
name: 'title',
7692
type: 'node',
@@ -95,16 +111,6 @@ export default class DialogPage extends React.Component {
95111
{
96112
name: 'Methods',
97113
infoArray: [
98-
{
99-
name: 'dismiss',
100-
header: 'Dialog.dismiss()',
101-
desc: 'Hides the dialog.',
102-
},
103-
{
104-
name: 'show',
105-
header: 'Dialog.show()',
106-
desc: 'Shows the dialog.',
107-
},
108114
{
109115
name: 'isOpen',
110116
header: 'Dialog.isOpen()',
@@ -116,14 +122,9 @@ export default class DialogPage extends React.Component {
116122
name: 'Events',
117123
infoArray: [
118124
{
119-
name: 'onDismiss',
120-
header: 'function()',
121-
desc: 'Fired when the dialog is dismissed.',
122-
},
123-
{
124-
name: 'onShow',
125-
header: 'function()',
126-
desc: 'Fired when the dialog is shown.',
125+
name: 'onRequestClose',
126+
header: 'function(buttonClicked)',
127+
desc: 'Fired when the dialog is requested to be closed by a click outside the dialog or on the buttons.',
127128
},
128129
],
129130
},
@@ -175,15 +176,17 @@ export default class DialogPage extends React.Component {
175176
title="Dialog With Standard Actions"
176177
actions={standardActions}
177178
actionFocus="submit"
178-
modal={this.state.modal}>
179+
isOpen={this.state.showDialogStandardActions}
180+
onRequestClose={this._handleRequestClose}>
179181
The actions in this window are created from the json that's passed in.
180182
</Dialog>
181183

182184
<Dialog
183185
ref="customDialog"
184186
title="Dialog With Custom Actions"
185187
actions={customActions}
186-
modal={this.state.modal}>
188+
isOpen={this.state.showDialogCustomActions}
189+
onRequestClose={this._handleRequestClose}>
187190
The actions in this window were passed in as an array of react objects.
188191
</Dialog>
189192
<div style={{width: '300px', margin: '0 auto', paddingTop: '20px'}}>
@@ -196,9 +199,10 @@ export default class DialogPage extends React.Component {
196199
ref="scrollableContentDialog"
197200
title="Dialog With Scrollable Content"
198201
actions={scrollableCustomActions}
199-
modal={this.state.modal}
200202
autoDetectWindowHeight={true}
201-
autoScrollBodyContent={true}>
203+
autoScrollBodyContent={true}
204+
isOpen={this.state.showDialogScrollable}
205+
onRequestClose={this._handleRequestClose}>
202206
<div style={{height: '1000px'}}>
203207
Really long content
204208
</div>
@@ -214,35 +218,58 @@ export default class DialogPage extends React.Component {
214218
}
215219

216220
_handleCustomDialogCancel() {
217-
this.refs.customDialog.dismiss();
221+
this.setState({
222+
showDialogCustomActions: true,
223+
});
218224
}
219225

220226
_handleCustomDialogSubmit() {
221-
this.refs.customDialog.dismiss();
227+
this.setState({
228+
showDialogCustomActions: true,
229+
});
222230
}
223231

224232
_handleToggleChange(e, toggled) {
225233
this.setState({modal: toggled});
226234
}
227235

228236
_handleScrollableDialogCancel() {
229-
this.refs.scrollableContentDialog.dismiss();
237+
this.setState({
238+
showDialogScrollable: false,
239+
});
230240
}
231241

232242
_handleScrollableDialogSubmit() {
233-
this.refs.scrollableContentDialog.dismiss();
243+
this.setState({
244+
showDialogScrollable: false,
245+
});
234246
}
235247

236248
_handleCustomDialogTouchTap() {
237-
this.refs.customDialog.show();
249+
this.setState({
250+
showDialogScrollable: true,
251+
});
238252
}
239253

240254
_handleStandardDialogTouchTap() {
241-
this.refs.standardDialog.show();
255+
this.setState({
256+
showDialogStandardActions: true,
257+
});
242258
}
243259

244260
_handleScrollableDialogTouchTap() {
245-
this.refs.scrollableContentDialog.show();
261+
this.setState({
262+
showDialogScrollable: true,
263+
});
264+
}
265+
266+
_handleRequestClose(buttonClicked) {
267+
if (!buttonClicked && this.state.modal) return;
268+
this.setState({
269+
showDialogStandardActions: false,
270+
showDialogCustomActions: false,
271+
showDialogScrollable: false,
272+
});
246273
}
247274

248275
}

docs/src/app/components/raw-code/dialog-code.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ let standardActions = [
88
title="Dialog With Standard Actions"
99
actions={standardActions}
1010
actionFocus="submit"
11-
modal={this.state.modal}>
11+
isOpen={this.state.showDialogStandardActions}
12+
onRequestClose={this._handleRequestClose}>
1213
The actions in this window are created from the json that's passed in.
1314
</Dialog>
1415

@@ -27,11 +28,19 @@ let customActions = [
2728
<Dialog
2829
title="Dialog With Custom Actions"
2930
actions={customActions}
30-
modal={this.state.modal}>
31+
isOpen={this.state.showDialogCustomActions}
32+
onRequestClose={this._handleRequestClose}>
3133
The actions in this window were passed in as an array of react objects.
3234
</Dialog>
3335

34-
<Dialog title="Dialog With Scrollable Content" actions={customActions}
35-
autoDetectWindowHeight={true} autoScrollBodyContent={true}>
36-
<div style={{height: '2000px'}}>Really long content</div>
37-
</Dialog>
36+
<Dialog
37+
title="Dialog With Scrollable Content"
38+
actions={customActions}
39+
autoDetectWindowHeight={true}
40+
autoScrollBodyContent={true}
41+
isOpen={this.state.showDialogScrollable}
42+
onRequestClose={this._handleRequestClose}>
43+
<div style={{height: '1000px'}}>
44+
Really long content
45+
</div>
46+
</Dialog>

docs/webpack-production.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ var config = {
4545
warnings: false
4646
}
4747
}),
48+
new webpack.DefinePlugin({
49+
"process.env": {
50+
NODE_ENV: JSON.stringify("production")
51+
}
52+
}),
4853
new HtmlWebpackPlugin({
4954
inject: false,
5055
template: path.join(__dirname, '/src/www/index.html')

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"homepage": "http://material-ui.com/",
3232
"dependencies": {
3333
"lodash.throttle": "~3.0.4",
34-
"lodash.debounce": "~3.1.1"
34+
"lodash.debounce": "~3.1.1",
35+
"warning": "^2.1.0"
3536
},
3637
"peerDependencies": {
3738
"inline-style-prefixer": "^0.3.3",

0 commit comments

Comments
 (0)