-
-
Notifications
You must be signed in to change notification settings - Fork 334
Add onSelect callback for range picker #93
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
Add onSelect callback for range picker #93
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/react-component/picker/5ifysxder |
Codecov Report
@@ Coverage Diff @@
## master #93 +/- ##
=======================================
Coverage 99.57% 99.57%
=======================================
Files 43 43
Lines 1900 1901 +1
Branches 569 577 +8
=======================================
+ Hits 1892 1893 +1
Misses 6 6
Partials 2 2
Continue to review full report at Codecov.
|
Just add param for |
@zombieJ Unfortunately, adding params to onCalendarChange would not allow the desired functionality and would change existing behaviour of onCalendarChange. The onSelect api is added in order to mirror the functionality of onSelect in the PickerPanel component. onCalendarChange is only triggered when a complete action is made i.e. both the start date and end date values have been entered, however the onSelect is intended to trigger when either the start date or end date values have been entered. One example of a use case is being able to disable certain end dates based on the selected start date. Since onCalendarChange only triggers when both start date and end date are entered, it is currently not possible to determine what the selected start date is before an end date has been entered or vice versa. If there are issues with introducing a new api, I am very open to alternative approaches to determine the selected start date or end date individually. |
if (onSelect) {
if (!isEqual(generateConfig, getValue(mergedValue, 0), startValue)) {
onSelect(startValue, startStr, 'start');
}
if (!isEqual(generateConfig, getValue(mergedValue, 1), endValue)) {
onSelect(endValue, endStr, 'end');
}
}
if (onCalendarChange) {
onCalendarChange(values, [startStr, endStr]);
} |
@zombieJ apologies for my confusion between onCalendarChange and onChange. I will re-examine the onCalendarChange functionality. Thank you for your clarification. |
…ub.com/Kim-Wing-Fung/picker into add-onselect-callback-for-range-picker
@zombieJ as you mentioned, I've now updated the onCalendarChange parameters to incorporate additional information. This should not break existing functionality or change any APIs. |
Thanks for quick response. Could you help to update info to an object like: Line 68 in 2b5a239
|
src/RangePicker.tsx
Outdated
|
||
if (onCalendarChange) { | ||
onCalendarChange(values, [startStr, endStr]); | ||
const startChanged = !isEqual(generateConfig, getValue(selectedValue, 0), startValue); |
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 use sourceIndex
to get the updated input.
@zombieJ updated info as requested. Please take another look. |
Merged. Could you help to update doc in antd also? |
|
@zombieJ Sure, I will do a PR for antd doc soon. |
Added onSelect callback to RangePicker to match the functionality in PickerPanel.