-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Conversation
ed159c2
to
6d8a952
Compare
}, this.refs.dialogWindow.show); | ||
} else { | ||
this.setState({ | ||
dialogDate: new Date(), |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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
@tintin1343 I think we can remove that date construction in |
6d8a952
to
d7292a0
Compare
@nathanmarks : Done. The date attribute is not needed in the getInitialState() method |
@@ -177,7 +177,6 @@ const DatePicker = React.createClass({ | |||
|
|||
getInitialState() { | |||
return { | |||
date: this._isControlled() ? this._getControlledDate() : this.props.defaultDate, | |||
dialogDate: new Date(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tintin1343 You removed the wrong state item 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U wanted me to remove the dialogDate? But even removing the earlier statement didn't make.any difference.
d7292a0
to
5847f99
Compare
@nathanmarks : Made the necessary changes. 😅 |
Added a check which helps pick the current system date when the date-picker dialog is opened. Resolves mui#3545
LGTM |
[Datepicker] Add a check to fetch current system date
@tintin1343 Thanks! |
@oliviertassinari : Thanks! |
tests/ docs demo, and is linted.The current issue #3545 deals with the date picker not picking up the updated system date when the dialog opens. This happens because if the system date updates but the page is not refreshed then the date which the dialog box gets is the old system date as the system date is set in the getinitialState() of the date picker and is not updated on the system date change.
I observed that there is no check when the openDialog() to get the updated date, which is what I added. I check if the Datepicker has a pre-existing selected date , if it does show that date on openDialog() else if the Datepicker is empty pick up the current system date (this will always pick up the updated date) and hence solves the problem.
Heres the example:
Fixes #3545.