-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[DateRangePicker] Allow same date selection #23603
Comments
I have this problem also. I would appreciate if it could be fixed as fast as possible. Thanks! |
Please fix this. We need it! |
This comment has been minimized.
This comment has been minimized.
It looks like we should remove the As far as I know, there are no valid use cases for it, no matter a date picker, time picker, date range picker, etc. One thing that we have seen in the past is the capability to control the range that can be selected, this is a different problem and require a broader solution. |
@oliviertassinari Is this a matter of applying the old PR to this repository or is there more to it? |
@havgry I can't say. I didn't look at the pull request in detail. |
@oliviertassinari Maybe you can introduce an or clause like below? diff --git a/packages/material-ui-lab/src/internal/pickers/date-utils.ts b/packages/material-ui-lab/src/internal/pickers/date-utils.ts
index c3d17b5703..4c1c7a7aa0 100644
--- a/packages/material-ui-lab/src/internal/pickers/date-utils.ts
+++ b/packages/material-ui-lab/src/internal/pickers/date-utils.ts
@@ -128,7 +128,7 @@ export const isRangeValid = <TDate>(
utils: MuiPickersAdapter<TDate>,
range: DateRange<TDate> | null,
): range is NonEmptyDateRange<TDate> => {
- return Boolean(range && range[0] && range[1] && utils.isBefore(range[0], range[1]));
+ return Boolean(range && range[0] && range[1] && (utils.isBefore(range[0], range[1]) || utils.isEqual(range[0], range[1])));
};
export const isWithinRange = <TDate>(
|
@hmaddisb I think that we can be more efficient: diff --git a/packages/material-ui-lab/src/internal/pickers/date-utils.ts b/packages/material-ui-lab/src/internal/pickers/date-utils.ts
index c3d17b5703..63fb4aef06 100644
--- a/packages/material-ui-lab/src/internal/pickers/date-utils.ts
+++ b/packages/material-ui-lab/src/internal/pickers/date-utils.ts
@@ -128,7 +128,8 @@ export const isRangeValid = <TDate>(
utils: MuiPickersAdapter<TDate>,
range: DateRange<TDate> | null,
): range is NonEmptyDateRange<TDate> => {
- return Boolean(range && range[0] && range[1] && utils.isBefore(range[0], range[1]));
+ // isBefore is exclusive, if two dates are equal, it returns false.
+ return Boolean(range && range[0] && range[1] && !utils.isBefore(range[1], range[0]));
};
export const isWithinRange = <TDate>( |
@oliviertassinari that's fair! Should I make a PR for that? Or do you want to introduce more changes for this issue? |
@hmaddisb I think that we can try a pull request :), we would need to add a test. |
i think the issue is in the validateDateRange function. This function not use the allowSameDateSelection to pass the validate of utils.isBefore(range[0], range[1])
The text was updated successfully, but these errors were encountered: