picker
picker copied to clipboard
Rangepicker - If end date is before start date, set start date to end date
We are trying to provide a slightly different user experience when using the date range picker.
Steps:
- Select a start date 07/21/2022
- Select an end date 07/23/2022
- Close the picker
- Click in the end date
- Change the end date to be before the start date
Current Behavior:
End date is set to clicked on date and cursor is moved back to start date
Desired behavior:
Start date is set to the clicked on date and the end date stays focused with no date selected yet (only if the selected date is before the original start date)
Potential Solutions
I haven't been able to find a solution using the available methods/props to quite fit our needs. I raised this issue on the Ant github repo with the linked codesandbox. My "quick" solution was as followed inside of RangePicker.tsx starting at lines 440
// RangePicker.tsx starting line 440
// New Code
if (!startValue && endValue) {
startValue = endValue;
endValue = null;
values = [startValue, endValue];
sourceIndex = 0;
openRecordsRef.current = {
[sourceIndex]: true,
};
}
// Currently code
setSelectedValue(values);
Is this something that can be accomplished with the current API?