-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix end time selection before selecting date #6858
Conversation
Generate changelog in
|
Fix end time selection before selecting dateBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
lintBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
prettier and test fixBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
fix testBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
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.
Thank you!
this.props.onChange?.(newDateRange); | ||
this.setState({ value: newDateRange, time: newTimeRange }); | ||
}; | ||
|
||
private getDefaultDate = (dateIndex: number) => { | ||
const { value } = this.state; |
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.
nitpick: I'm not too worried about this since this is already happening in the existing code, but I wonder if we need to grab existing state in the setState
callback rather than reading directly off of this.state
.
Otherwise we could end up with weird bugs if this.state
is referring to stale values.
In general, any time "next state" is computed from some kind of prior state, I usually read the prior state in a setState
callback.
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.
oof yea, I remember dealing with stuff like this back when seeing class components more often
in this case I'm thinking let's leave as is since as you call out we access this.state
just before calling this helper method
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.
Agree! Let's leave as-is. I almost didn't make this comment because it was an existing issue.
this.props.onChange?.(newDateRange); | ||
this.setState({ value: newDateRange, time: newTimeRange }); | ||
}; | ||
|
||
private getDefaultDate = (dateIndex: number) => { |
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.
Just as a suggestion, I think we can add an inline source code comment to explain why we need to be careful about selecting the next default date.
Maybe something around:
- When someone sets the time value before choosing a date, we need to "infer" or pick a date for them to initialize.
- The next default date for the 0 or 1 index depends on the value of the other index since there's an invariant that the left/0 date is always less than the right/1 date.
packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx
Show resolved
Hide resolved
packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx
Outdated
Show resolved
Hide resolved
Update packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsxBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
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.
Sweet! Thanks for the comment on getDefaultDate
.
Add generated changelog entriesBuild artifact links for this commit: documentation | landing | table | demoThis is an automated comment from the deploy-preview CircleCI job. |
Fixes #6863
Fixes #6856
Previously, users could end up with a reversed selection range if modifying the time input of the end date before selecting a date. Today's date was used as the default in these cases, leaving the user with a reversed range if the start date was later than today's date.
Checklist
Changes proposed in this pull request:
allowSingleDayRange
is nottrue
, ensure the default date is 1 day off from the already selected date (otherwise keep today's date as default if no dates are selected).Reviewers should focus on:
allowSingleDayRange
is nottrue
?allowSingleDayRange
change split out?