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

Conversation

tintin1343
Copy link
Contributor

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

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:
datepicker

Fixes #3545.

}, 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

@nathanmarks nathanmarks added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Mar 10, 2016
@nathanmarks
Copy link
Member

@tintin1343 I think we can remove that date construction in getInitialState() now.

@tintin1343
Copy link
Contributor Author

@nathanmarks : Done. The date attribute is not needed in the getInitialState() method

@mbrookes mbrookes added the bug 🐛 Something doesn't work label Mar 10, 2016
@@ -177,7 +177,6 @@ const DatePicker = React.createClass({

getInitialState() {
return {
date: this._isControlled() ? this._getControlledDate() : this.props.defaultDate,
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.

@tintin1343 You removed the wrong state item 😄

Copy link
Contributor Author

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.

@tintin1343
Copy link
Contributor Author

@nathanmarks : Made the necessary changes. 😅

@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 11, 2016
Added a check which helps pick the current system date when the date-picker dialog
 is opened.

Resolves mui#3545
@mbrookes
Copy link
Member

LGTM

oliviertassinari added a commit that referenced this pull request Mar 12, 2016
[Datepicker] Add a check to fetch current system date
@oliviertassinari oliviertassinari merged commit 092f798 into mui:master Mar 12, 2016
@oliviertassinari
Copy link
Member

@tintin1343 Thanks!

@tintin1343
Copy link
Contributor Author

@oliviertassinari : Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants