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

[Datepicker] Add a check to fetch current system date #3656

Merged
merged 1 commit into from
Mar 12, 2016
Merged
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
18 changes: 14 additions & 4 deletions src/date-picker/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ const DatePicker = React.createClass({
getInitialState() {
return {
date: this._isControlled() ? this._getControlledDate() : this.props.defaultDate,
dialogDate: new Date(),
muiTheme: this.context.muiTheme || getMuiTheme(),
};
},
Expand Down Expand Up @@ -212,9 +211,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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have this, do we still need new Date() in getInitialState() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanmarks : good point. I think we can remove it. Let me do the changes and check

}, this.refs.dialogWindow.show);
}
},

/**
Expand Down