-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[DateRangePicker] disable day on date range #5773
[DateRangePicker] disable day on date range #5773
Conversation
These are the results for the performance tests:
|
The POC looks superb 🙌 |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
c73f74f
to
882feff
Compare
Why not, but The helper
|
For now indeed |
* @returns {boolean} Returns `true` if the date should be disabled. | ||
*/ | ||
shouldDisableDate?: (day: TDate) => boolean; | ||
shouldDisableDate?: (day: TDate, position?: 'start' | 'end') => boolean; |
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.
It would be nice to only add it to the range interfaces
But that may add a lot of complexity :/
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.
Yes, I wanted to comment on this as well. 🤔
Seems a bit counter intuitive to provide optional field for every picker, when only range
ones have this field present.
I'll look into whether it would be feasible to have separate interfaces for range and other pickers.
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.
Yes, because this is propagated nearly everywhere. But I can give a second try to override it properly
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.
For a reason I ignore, it seems to work without any complex modification 🤯
I'm happy and suspicious at the same time because docs:API generate the expected output (one parameter for basic input, and two for range inputs) but I did not had to Omit
shouldDisableDate
anywhere 🤔
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.
You have to omit if you want to make this param non-nullable for range pickers
diff --git a/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerView.tsx b/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerView.tsx
index 3ec1c82fa..f80b83938 100644
--- a/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerView.tsx
+++ b/packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerView.tsx
@@ -40,7 +40,7 @@ export interface ExportedDateRangePickerViewProps<TDate>
extends ExportedDesktopDateRangeCalendarProps<TDate>,
Omit<
ExportedCalendarPickerProps<TDate>,
- 'onYearChange' | 'renderDay' | keyof BaseDateValidationProps<TDate>
+ 'onYearChange' | 'renderDay' | keyof BaseDateValidationProps<TDate> | 'shouldDisableDate'
> {
/**
* Overrideable components.
@@ -81,7 +81,7 @@ export interface ExportedDateRangePickerViewProps<TDate>
* @param {string} position The date to test, 'start' or 'end'.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
- shouldDisableDate?: (day: TDate, position?: 'start' | 'end') => boolean;
+ shouldDisableDate?: (day: TDate, position: 'start' | 'end') => boolean;
}
interface DateRangePickerViewProps<TInputDate, TDate>
diff --git a/packages/x-date-pickers-pro/src/internal/hooks/validation/useDateRangeValidation.ts b/packages/x-date-pickers-pro/src/internal/hooks/validation/useDateRangeValidation.ts
index 969eb1f59..c61bbcce3 100644
--- a/packages/x-date-pickers-pro/src/internal/hooks/validation/useDateRangeValidation.ts
+++ b/packages/x-date-pickers-pro/src/internal/hooks/validation/useDateRangeValidation.ts
@@ -5,14 +5,12 @@ import {
DateValidationError,
validateDate,
BaseDateValidationProps,
- DayValidationProps,
} from '@mui/x-date-pickers/internals';
import { isRangeValid, parseRangeInputValue } from '../../utils/date-utils';
import { DateRange } from '../../models';
export interface DateRangeValidationProps<TInputDate, TDate>
- extends DayValidationProps<TDate>,
- Required<BaseDateValidationProps<TDate>>,
+ extends Required<BaseDateValidationProps<TDate>>,
ValidationProps<DateRangeValidationError, DateRange<TInputDate>> {
/**
* Disable specific date. @DateIOType
@@ -21,7 +19,7 @@ export interface DateRangeValidationProps<TInputDate, TDate>
* @param {string} position The date to test, 'start' or 'end'.
* @returns {boolean} Returns `true` if the date should be disabled.
*/
- shouldDisableDate?: (day: TDate, position?: 'start' | 'end') => boolean;
+ shouldDisableDate?: (day: TDate, position: 'start' | 'end') => boolean;
}
export const validateDateRange: Validator<any, DateRangeValidationProps<any, any>> = ({
I just have one issue which is that the doc generation looses the enum.
Most likely during the proptype generation phase:
@param {string} position The date to test, 'start' or 'end'.
But that's a different topic that probably impact other parts of our codebase and should be adressed
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.
By the way, I would be in favor of having a DayRangeValidationProps
containing only shouldDisableDate
And have the two interface with the range shouldDisableDate
extend it.
To be consistent with DayValidationProps
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.
I just have one issue which is that the doc generation looses the enum.
Most likely during the proptype generation phase:
@param {string} position The date to test, 'start' or 'end'.
The string
does not come from the typescript definition but from the comment line
/**
* @param {string} position The date to test, 'start' or 'end'.
* /
I did that because using @param {'start' | 'end'}
or
type RangePosition = 'start' | 'end'
/**
* @param {RangePosition}
*/
ends up with an error in the doc generation saying the Template Literal Types are not supported by the documentation build, so instead of fixing the script I put string
and listed the values.
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.
LGTM. Very nice final result! 🚀 💯 ❤️
Fix #5769
I tried a POC for #5769 to add a parameter
'start'
and'end'
for now only onDesktopDateRangePicker
. It will need some cleaning but seems to work.