-
Notifications
You must be signed in to change notification settings - Fork 832
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 ability to select same date in date range picker #1759
Comments
For benchmark https://www.google.com/flights and https://www.airbnb.com/ allows selecting the same date while https://www.booking.com/ doesn't. |
Would be great to add a prop to the api to allow or not allow the same date validation |
I am wondering about the better API for that. Maybe something like |
@dmtrKovalenko A side but related question. Should we move the validation outside of the DateRangePicker, as we did for the DatePicker? In this approach, developers would have the following workaround: they could flag same-day selection as valid. |
It already has the same validation as |
@dmtrKovalenko So people can already add a conditional to their onError handler? |
Yes, but it will look like const [error, setError] = React.useState([null, null])
<DateRange
onError={([startReason, endReason], [start, end]) => {
if (startReason === 'invalidRange' && isSameDay(start, end)) {
setError([null, null])
return;
}
setError([startReason, endReason])
})}
renderInput={props => <TextField {...props} error={Boolean(error[0])} /> }
/> |
@dmtrKovalenko This looks perfect for the "lazy" solution, to let end-users fall into this trap and get visual/text feedback 👌. However, there is another side to the problem. I assume the concern now is about: Should the UI prevent this case in the first place? It would give faster feedback in the UI, this sounds fair. Should it be done with a Related: |
I thought about such api, and prepeared special design for this case – we have a function https://github.com/mui-org/material-ui-pickers/blob/7bed283699ef768936a3ec7c5dc89571492dddd4/lib/src/DateRangePicker/date-range-manager.ts#L12 that calculates range changes, we can expose the prop that will replace function and will make possible to significantly customize range picking behavior |
@dmtrKovalenko Awesome. Maybe we should wait to get more feedback from the developers before making a step further in any direction :D? |
Determining the kind of error in Taking into account that this component might be part of something like |
@kirill-konshin You are free to override the built-in validation. If it's what you are looking for, then you are already covered. |
Will it allow to suppress the same-day error? Can you point on any example how to do it? |
Hi folks. |
@sergiolenza Interesting, thanks for raising. This makes me think of:
Do you have a preference on how the problem should be fixed? |
This comment has been minimized.
This comment has been minimized.
I had that in mind but upon checking Kayak, Google Flights and some others I noticed they are not allowing this. But I personally agree that it’s useful. |
That’s where I think exposing custom range strategy should help: #1759 (comment) |
I think the issue begins here, where we get var validationError = useDateRangeValidation(value, restProps); Inside the var useDateRangeValidation = makeValidationHook(validateDateRange, {
defaultValidationError: [null, null],
isSameError: function isSameError(a, b) {
return a[1] === b[1] && a[0] === b[0];
}
}); I see the So should we can start solve this issue here? |
This comment has been minimized.
This comment has been minimized.
@dmtrKovalenko What do you think about this resolution?
/**
* Determine if the current range can be selected by the user.
* For instance, it can be used to prevent the selected range to end the weekend.
*/
isRangeAvailable?: (range: [ParsableDate, ParsableDate]) => boolean; While 1. is breaking, 2. could be implemented later on. |
Users can select the same day without any error would be sufficient here imho |
Just noting that even though the option |
@bsides Please try with @material-ui/lab@v5.0.0-alpha.21. |
Unfortunatelly it's hard to test @oliviertassinari because I do use other stuff from the lab and they're not at that version (should be bumped?) |
@bsides Make sure all your dependencies are on v5 |
Oh, I was using It used to be... Thanks again |
@bsides Please have a look at https://next.material-ui.com/guides/pickers-migration/. If you see anything missing, let us know. |
Bump, I have completely opposite issue, where by default it allows selecting the same date on both fields, wondering how to disable that, and ensure dates are at least a day apart? I tried in the onChange method to set the second date to null if its teh same, it works when first clicking it but on the second click it ignores it and just sets the same date again. |
@anthony-brown-5pm Just a friendly reminder that this package is no longer maintained. |
Hi all, this isn't so much a solution, but rather a work around. Basically, if only one date is selected a button will pop up below the calendar. Now you will only have one date in your date input. Without the button visually popping up, it is confusing for the user to know that they are allowed to just exit the calendar without selecting an end date and that is why I added a button that manually closes the calendar. On your following page when you are reading the form data, just account for the fact that you only have one date and implement the logic as your app requires. e.g if end_date not set, end_date = start_date In this code snippet, the button logic is just in the onShow and onSelect methods.
|
It possible to select same date to make one day range. It currently gives validation error: https://dev.material-ui-pickers.dev/demo/daterangepicker
image
Follow up for #364 (comment)
The text was updated successfully, but these errors were encountered: