From 426e8077870bf1bb659c388fe9ee761d63c349cb Mon Sep 17 00:00:00 2001 From: Nitin Shetty Date: Thu, 10 Mar 2016 11:26:00 -0600 Subject: [PATCH] [Datepicker] Add a check to fetch current system date Added a check which helps pick the current system date when the date-picker dialog is opened. Resolves callemall/material-ui#3545 --- src/date-picker/date-picker.jsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/date-picker/date-picker.jsx b/src/date-picker/date-picker.jsx index 6deaac9a871cc2..6628f818deb92a 100644 --- a/src/date-picker/date-picker.jsx +++ b/src/date-picker/date-picker.jsx @@ -187,7 +187,6 @@ const DatePicker = React.createClass({ getInitialState() { return { date: this._isControlled() ? this._getControlledDate() : this.props.defaultDate, - dialogDate: new Date(), muiTheme: this.context.muiTheme || getMuiTheme(), }; }, @@ -221,9 +220,20 @@ const DatePicker = React.createClass({ * Open the date-picker dialog programmatically from a parent. */ openDialog() { - this.setState({ - dialogDate: this.getDate(), - }, this.refs.dialogWindow.show); + /** + * if the date is not selected then set it to new date + * (get the current system date while doing so) + * else set it to the currently selected date + */ + if (this.state.date !== undefined) { + this.setState({ + dialogDate: this.getDate(), + }, this.refs.dialogWindow.show); + } else { + this.setState({ + dialogDate: new Date(), + }, this.refs.dialogWindow.show); + } }, /**