@mui/x-date-pickers 6.4.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +56 -0
- package/DateField/DateField.types.d.ts +1 -1
- package/DateField/index.d.ts +1 -1
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +9 -46
- package/DateTimeField/DateTimeField.types.d.ts +1 -1
- package/DateTimeField/index.d.ts +1 -1
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +9 -60
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
- package/DesktopTimePicker/DesktopTimePicker.js +1 -2
- package/MobileDateTimePicker/MobileDateTimePicker.js +1 -2
- package/MobileTimePicker/MobileTimePicker.js +1 -2
- package/TimeField/index.d.ts +1 -1
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +9 -50
- package/index.js +1 -1
- package/internals/hooks/useField/useField.js +10 -2
- package/internals/hooks/useViews.js +2 -0
- package/internals/index.d.ts +2 -1
- package/internals/index.js +2 -1
- package/internals/utils/fields.d.ts +5 -0
- package/internals/utils/fields.js +28 -0
- package/internals/utils/validation/extractValidationProps.d.ts +5 -1
- package/internals/utils/validation/extractValidationProps.js +4 -1
- package/legacy/DateField/useDateField.js +8 -44
- package/legacy/DateTimeField/useDateTimeField.js +8 -60
- package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
- package/legacy/DesktopTimePicker/DesktopTimePicker.js +1 -2
- package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +1 -2
- package/legacy/MobileTimePicker/MobileTimePicker.js +1 -2
- package/legacy/TimeField/useTimeField.js +8 -48
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useField/useField.js +12 -4
- package/legacy/internals/hooks/useViews.js +2 -0
- package/legacy/internals/index.js +2 -1
- package/legacy/internals/utils/fields.js +28 -0
- package/legacy/internals/utils/validation/extractValidationProps.js +4 -1
- package/legacy/tests/describeGregorianAdapter/testCalculations.js +1 -1
- package/legacy/tests/describeValue/describeValue.js +30 -3
- package/legacy/tests/describeValue/testControlledUnControlled.js +27 -21
- package/legacy/tests/describeValue/testPickerActionBar.js +40 -36
- package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +92 -71
- package/modern/DateField/useDateField.js +9 -46
- package/modern/DateTimeField/useDateTimeField.js +9 -60
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
- package/modern/DesktopTimePicker/DesktopTimePicker.js +1 -2
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -2
- package/modern/MobileTimePicker/MobileTimePicker.js +1 -2
- package/modern/TimeField/useTimeField.js +9 -50
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useField/useField.js +10 -2
- package/modern/internals/hooks/useViews.js +2 -0
- package/modern/internals/index.js +2 -1
- package/modern/internals/utils/fields.js +28 -0
- package/modern/internals/utils/validation/extractValidationProps.js +4 -1
- package/modern/tests/describeGregorianAdapter/testCalculations.js +1 -1
- package/modern/tests/describeValue/describeValue.js +29 -3
- package/modern/tests/describeValue/testControlledUnControlled.js +23 -15
- package/modern/tests/describeValue/testPickerActionBar.js +21 -14
- package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +79 -51
- package/node/DateField/useDateField.js +9 -46
- package/node/DateTimeField/useDateTimeField.js +9 -60
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -2
- package/node/DesktopTimePicker/DesktopTimePicker.js +1 -2
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -2
- package/node/MobileTimePicker/MobileTimePicker.js +1 -2
- package/node/TimeField/useTimeField.js +9 -50
- package/node/index.js +1 -1
- package/node/internals/hooks/useField/useField.js +10 -2
- package/node/internals/hooks/useViews.js +2 -0
- package/node/internals/index.js +13 -0
- package/node/internals/utils/fields.js +36 -0
- package/node/internals/utils/validation/extractValidationProps.js +8 -2
- package/node/tests/describeGregorianAdapter/testCalculations.js +1 -1
- package/node/tests/describeValue/describeValue.js +29 -3
- package/node/tests/describeValue/testControlledUnControlled.js +23 -15
- package/node/tests/describeValue/testPickerActionBar.js +21 -14
- package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +79 -51
- package/package.json +2 -2
- package/tests/describeGregorianAdapter/testCalculations.js +1 -1
- package/tests/describeValue/describeValue.js +29 -3
- package/tests/describeValue/testControlledUnControlled.js +23 -15
- package/tests/describeValue/testPickerActionBar.js +21 -14
- package/tests/describeValue/testPickerOpenCloseLifeCycle.js +79 -51
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
var _excluded = ["value", "defaultValue", "format", "formatDensity", "shouldRespectLeadingZeros", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "minTime", "maxTime", "minDateTime", "maxDateTime", "minutesStep", "disableIgnoringDatePartForTimeValidation", "shouldDisableClock", "shouldDisableTime", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
|
|
4
2
|
import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
|
|
5
3
|
import { useField } from '../internals/hooks/useField';
|
|
6
4
|
import { validateDateTime } from '../internals/utils/validation/validateDateTime';
|
|
7
5
|
import { applyDefaultDate } from '../internals/utils/date-utils';
|
|
8
6
|
import { useUtils, useDefaultDates } from '../internals/hooks/useUtils';
|
|
7
|
+
import { splitFieldInternalAndForwardedProps } from '../internals/utils/fields';
|
|
9
8
|
var useDefaultizedDateTimeField = function useDefaultizedDateTimeField(props) {
|
|
10
9
|
var _props$ampm, _props$disablePast, _props$disableFuture, _props$format, _props$minDateTime, _props$maxDateTime, _props$minDateTime2, _props$maxDateTime2;
|
|
11
10
|
var utils = useUtils();
|
|
@@ -24,67 +23,16 @@ var useDefaultizedDateTimeField = function useDefaultizedDateTimeField(props) {
|
|
|
24
23
|
});
|
|
25
24
|
};
|
|
26
25
|
export var useDateTimeField = function useDateTimeField(_ref) {
|
|
27
|
-
var
|
|
26
|
+
var inProps = _ref.props,
|
|
28
27
|
inputRef = _ref.inputRef;
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
formatDensity = _useDefaultizedDateTi.formatDensity,
|
|
34
|
-
shouldRespectLeadingZeros = _useDefaultizedDateTi.shouldRespectLeadingZeros,
|
|
35
|
-
onChange = _useDefaultizedDateTi.onChange,
|
|
36
|
-
readOnly = _useDefaultizedDateTi.readOnly,
|
|
37
|
-
onError = _useDefaultizedDateTi.onError,
|
|
38
|
-
shouldDisableDate = _useDefaultizedDateTi.shouldDisableDate,
|
|
39
|
-
shouldDisableMonth = _useDefaultizedDateTi.shouldDisableMonth,
|
|
40
|
-
shouldDisableYear = _useDefaultizedDateTi.shouldDisableYear,
|
|
41
|
-
minDate = _useDefaultizedDateTi.minDate,
|
|
42
|
-
maxDate = _useDefaultizedDateTi.maxDate,
|
|
43
|
-
disableFuture = _useDefaultizedDateTi.disableFuture,
|
|
44
|
-
disablePast = _useDefaultizedDateTi.disablePast,
|
|
45
|
-
minTime = _useDefaultizedDateTi.minTime,
|
|
46
|
-
maxTime = _useDefaultizedDateTi.maxTime,
|
|
47
|
-
minDateTime = _useDefaultizedDateTi.minDateTime,
|
|
48
|
-
maxDateTime = _useDefaultizedDateTi.maxDateTime,
|
|
49
|
-
minutesStep = _useDefaultizedDateTi.minutesStep,
|
|
50
|
-
disableIgnoringDatePartForTimeValidation = _useDefaultizedDateTi.disableIgnoringDatePartForTimeValidation,
|
|
51
|
-
shouldDisableClock = _useDefaultizedDateTi.shouldDisableClock,
|
|
52
|
-
shouldDisableTime = _useDefaultizedDateTi.shouldDisableTime,
|
|
53
|
-
selectedSections = _useDefaultizedDateTi.selectedSections,
|
|
54
|
-
onSelectedSectionsChange = _useDefaultizedDateTi.onSelectedSectionsChange,
|
|
55
|
-
ampm = _useDefaultizedDateTi.ampm,
|
|
56
|
-
unstableFieldRef = _useDefaultizedDateTi.unstableFieldRef,
|
|
57
|
-
other = _objectWithoutProperties(_useDefaultizedDateTi, _excluded);
|
|
28
|
+
var props = useDefaultizedDateTimeField(inProps);
|
|
29
|
+
var _splitFieldInternalAn = splitFieldInternalAndForwardedProps(props, 'date-time'),
|
|
30
|
+
forwardedProps = _splitFieldInternalAn.forwardedProps,
|
|
31
|
+
internalProps = _splitFieldInternalAn.internalProps;
|
|
58
32
|
return useField({
|
|
59
33
|
inputRef: inputRef,
|
|
60
|
-
forwardedProps:
|
|
61
|
-
internalProps:
|
|
62
|
-
value: value,
|
|
63
|
-
defaultValue: defaultValue,
|
|
64
|
-
format: format,
|
|
65
|
-
formatDensity: formatDensity,
|
|
66
|
-
shouldRespectLeadingZeros: shouldRespectLeadingZeros,
|
|
67
|
-
onChange: onChange,
|
|
68
|
-
readOnly: readOnly,
|
|
69
|
-
onError: onError,
|
|
70
|
-
shouldDisableDate: shouldDisableDate,
|
|
71
|
-
shouldDisableMonth: shouldDisableMonth,
|
|
72
|
-
shouldDisableYear: shouldDisableYear,
|
|
73
|
-
minDate: minDate,
|
|
74
|
-
maxDate: maxDate,
|
|
75
|
-
disableFuture: disableFuture,
|
|
76
|
-
disablePast: disablePast,
|
|
77
|
-
minTime: minTime,
|
|
78
|
-
maxTime: maxTime,
|
|
79
|
-
minutesStep: minutesStep,
|
|
80
|
-
shouldDisableClock: shouldDisableClock,
|
|
81
|
-
shouldDisableTime: shouldDisableTime,
|
|
82
|
-
disableIgnoringDatePartForTimeValidation: disableIgnoringDatePartForTimeValidation,
|
|
83
|
-
selectedSections: selectedSections,
|
|
84
|
-
onSelectedSectionsChange: onSelectedSectionsChange,
|
|
85
|
-
ampm: ampm,
|
|
86
|
-
unstableFieldRef: unstableFieldRef
|
|
87
|
-
},
|
|
34
|
+
forwardedProps: forwardedProps,
|
|
35
|
+
internalProps: internalProps,
|
|
88
36
|
valueManager: singleItemValueManager,
|
|
89
37
|
fieldValueManager: singleItemFieldValueManager,
|
|
90
38
|
validator: validateDateTime,
|
|
@@ -39,8 +39,7 @@ var DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDateTi
|
|
|
39
39
|
field: function field(ownerState) {
|
|
40
40
|
var _defaultizedProps$slo;
|
|
41
41
|
return _extends({}, resolveComponentProps((_defaultizedProps$slo = defaultizedProps.slotProps) == null ? void 0 : _defaultizedProps$slo.field, ownerState), extractValidationProps(defaultizedProps), {
|
|
42
|
-
ref: ref
|
|
43
|
-
ampm: defaultizedProps.ampm
|
|
42
|
+
ref: ref
|
|
44
43
|
});
|
|
45
44
|
},
|
|
46
45
|
toolbar: _extends({
|
|
@@ -53,8 +53,7 @@ var DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePicker
|
|
|
53
53
|
field: function field(ownerState) {
|
|
54
54
|
var _defaultizedProps$slo;
|
|
55
55
|
return _extends({}, resolveComponentProps((_defaultizedProps$slo = defaultizedProps.slotProps) == null ? void 0 : _defaultizedProps$slo.field, ownerState), extractValidationProps(defaultizedProps), {
|
|
56
|
-
ref: ref
|
|
57
|
-
ampm: defaultizedProps.ampm
|
|
56
|
+
ref: ref
|
|
58
57
|
});
|
|
59
58
|
},
|
|
60
59
|
toolbar: _extends({
|
|
@@ -37,8 +37,7 @@ var MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTime
|
|
|
37
37
|
field: function field(ownerState) {
|
|
38
38
|
var _defaultizedProps$slo;
|
|
39
39
|
return _extends({}, resolveComponentProps((_defaultizedProps$slo = defaultizedProps.slotProps) == null ? void 0 : _defaultizedProps$slo.field, ownerState), extractValidationProps(defaultizedProps), {
|
|
40
|
-
ref: ref
|
|
41
|
-
ampm: defaultizedProps.ampm
|
|
40
|
+
ref: ref
|
|
42
41
|
});
|
|
43
42
|
},
|
|
44
43
|
toolbar: _extends({
|
|
@@ -33,8 +33,7 @@ var MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker(i
|
|
|
33
33
|
field: function field(ownerState) {
|
|
34
34
|
var _defaultizedProps$slo;
|
|
35
35
|
return _extends({}, resolveComponentProps((_defaultizedProps$slo = defaultizedProps.slotProps) == null ? void 0 : _defaultizedProps$slo.field, ownerState), extractValidationProps(defaultizedProps), {
|
|
36
|
-
ref: ref
|
|
37
|
-
ampm: defaultizedProps.ampm
|
|
36
|
+
ref: ref
|
|
38
37
|
});
|
|
39
38
|
},
|
|
40
39
|
toolbar: _extends({
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
var _excluded = ["value", "defaultValue", "format", "formatDensity", "shouldRespectLeadingZeros", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
|
|
4
2
|
import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
|
|
5
3
|
import { useField } from '../internals/hooks/useField';
|
|
6
4
|
import { validateTime } from '../internals/utils/validation/validateTime';
|
|
7
5
|
import { useUtils } from '../internals/hooks/useUtils';
|
|
6
|
+
import { splitFieldInternalAndForwardedProps } from '../internals/utils/fields';
|
|
8
7
|
var useDefaultizedTimeField = function useDefaultizedTimeField(props) {
|
|
9
8
|
var _props$ampm, _props$disablePast, _props$disableFuture, _props$format;
|
|
10
9
|
var utils = useUtils();
|
|
@@ -17,55 +16,16 @@ var useDefaultizedTimeField = function useDefaultizedTimeField(props) {
|
|
|
17
16
|
});
|
|
18
17
|
};
|
|
19
18
|
export var useTimeField = function useTimeField(_ref) {
|
|
20
|
-
var
|
|
19
|
+
var inProps = _ref.props,
|
|
21
20
|
inputRef = _ref.inputRef;
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
formatDensity = _useDefaultizedTimeFi.formatDensity,
|
|
27
|
-
shouldRespectLeadingZeros = _useDefaultizedTimeFi.shouldRespectLeadingZeros,
|
|
28
|
-
onChange = _useDefaultizedTimeFi.onChange,
|
|
29
|
-
readOnly = _useDefaultizedTimeFi.readOnly,
|
|
30
|
-
onError = _useDefaultizedTimeFi.onError,
|
|
31
|
-
disableFuture = _useDefaultizedTimeFi.disableFuture,
|
|
32
|
-
disablePast = _useDefaultizedTimeFi.disablePast,
|
|
33
|
-
minTime = _useDefaultizedTimeFi.minTime,
|
|
34
|
-
maxTime = _useDefaultizedTimeFi.maxTime,
|
|
35
|
-
minutesStep = _useDefaultizedTimeFi.minutesStep,
|
|
36
|
-
shouldDisableClock = _useDefaultizedTimeFi.shouldDisableClock,
|
|
37
|
-
shouldDisableTime = _useDefaultizedTimeFi.shouldDisableTime,
|
|
38
|
-
disableIgnoringDatePartForTimeValidation = _useDefaultizedTimeFi.disableIgnoringDatePartForTimeValidation,
|
|
39
|
-
selectedSections = _useDefaultizedTimeFi.selectedSections,
|
|
40
|
-
onSelectedSectionsChange = _useDefaultizedTimeFi.onSelectedSectionsChange,
|
|
41
|
-
ampm = _useDefaultizedTimeFi.ampm,
|
|
42
|
-
unstableFieldRef = _useDefaultizedTimeFi.unstableFieldRef,
|
|
43
|
-
other = _objectWithoutProperties(_useDefaultizedTimeFi, _excluded);
|
|
21
|
+
var props = useDefaultizedTimeField(inProps);
|
|
22
|
+
var _splitFieldInternalAn = splitFieldInternalAndForwardedProps(props, 'time'),
|
|
23
|
+
forwardedProps = _splitFieldInternalAn.forwardedProps,
|
|
24
|
+
internalProps = _splitFieldInternalAn.internalProps;
|
|
44
25
|
return useField({
|
|
45
26
|
inputRef: inputRef,
|
|
46
|
-
forwardedProps:
|
|
47
|
-
internalProps:
|
|
48
|
-
value: value,
|
|
49
|
-
defaultValue: defaultValue,
|
|
50
|
-
format: format,
|
|
51
|
-
formatDensity: formatDensity,
|
|
52
|
-
shouldRespectLeadingZeros: shouldRespectLeadingZeros,
|
|
53
|
-
onChange: onChange,
|
|
54
|
-
readOnly: readOnly,
|
|
55
|
-
onError: onError,
|
|
56
|
-
disableFuture: disableFuture,
|
|
57
|
-
disablePast: disablePast,
|
|
58
|
-
minTime: minTime,
|
|
59
|
-
maxTime: maxTime,
|
|
60
|
-
minutesStep: minutesStep,
|
|
61
|
-
shouldDisableClock: shouldDisableClock,
|
|
62
|
-
shouldDisableTime: shouldDisableTime,
|
|
63
|
-
disableIgnoringDatePartForTimeValidation: disableIgnoringDatePartForTimeValidation,
|
|
64
|
-
selectedSections: selectedSections,
|
|
65
|
-
onSelectedSectionsChange: onSelectedSectionsChange,
|
|
66
|
-
ampm: ampm,
|
|
67
|
-
unstableFieldRef: unstableFieldRef
|
|
68
|
-
},
|
|
27
|
+
forwardedProps: forwardedProps,
|
|
28
|
+
internalProps: internalProps,
|
|
69
29
|
valueManager: singleItemValueManager,
|
|
70
30
|
fieldValueManager: singleItemFieldValueManager,
|
|
71
31
|
validator: validateTime,
|
package/legacy/index.js
CHANGED
|
@@ -67,10 +67,18 @@ export var useField = function useField(params) {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
var browserStartIndex = (_selectionStart = inputRef.current.selectionStart) != null ? _selectionStart : 0;
|
|
70
|
-
var nextSectionIndex
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
var nextSectionIndex;
|
|
71
|
+
if (browserStartIndex <= state.sections[0].startInInput) {
|
|
72
|
+
// Special case if browser index is in invisible characters at the beginning
|
|
73
|
+
nextSectionIndex = 1;
|
|
74
|
+
} else if (browserStartIndex >= state.sections[state.sections.length - 1].endInInput) {
|
|
75
|
+
// If the click is after the last character of the input, then we want to select the 1st section.
|
|
76
|
+
nextSectionIndex = 1;
|
|
77
|
+
} else {
|
|
78
|
+
nextSectionIndex = state.sections.findIndex(function (section) {
|
|
79
|
+
return section.startInInput - section.startSeparator.length > browserStartIndex;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
74
82
|
var sectionIndex = nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
|
|
75
83
|
_setSelectedSections(sectionIndex);
|
|
76
84
|
};
|
|
@@ -53,6 +53,8 @@ export function useViews(_ref) {
|
|
|
53
53
|
return !views.includes(previousView);
|
|
54
54
|
})) {
|
|
55
55
|
setView(views.includes(openTo) ? openTo : views[0]);
|
|
56
|
+
previousViews.current = views;
|
|
57
|
+
previousOpenTo.current = openTo;
|
|
56
58
|
}
|
|
57
59
|
}, [openTo, setView, view, views]);
|
|
58
60
|
var viewIndex = views.indexOf(view);
|
|
@@ -16,13 +16,14 @@ export { useLocalizationContext, useDefaultDates, useUtils, useLocaleText, useNo
|
|
|
16
16
|
export { useValidation } from './hooks/useValidation';
|
|
17
17
|
export { usePreviousMonthDisabled, useNextMonthDisabled } from './hooks/date-helpers-hooks';
|
|
18
18
|
export { applyDefaultDate, replaceInvalidDateByNull, areDatesEqual } from './utils/date-utils';
|
|
19
|
+
export { splitFieldInternalAndForwardedProps } from './utils/fields';
|
|
19
20
|
export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './utils/utils';
|
|
20
21
|
export { defaultReduceAnimations } from './utils/defaultReduceAnimations';
|
|
21
22
|
export { extractValidationProps } from './utils/validation/extractValidationProps';
|
|
22
23
|
export { validateDate } from './utils/validation/validateDate';
|
|
23
24
|
export { validateDateTime } from './utils/validation/validateDateTime';
|
|
24
25
|
export { validateTime } from './utils/validation/validateTime';
|
|
25
|
-
export { buildDeprecatedPropsWarning } from './utils/warning';
|
|
26
|
+
export { buildDeprecatedPropsWarning, buildWarning } from './utils/warning';
|
|
26
27
|
export { uncapitalizeObjectKeys } from './utils/slots-migration';
|
|
27
28
|
export { PickersCalendarHeader } from '../DateCalendar/PickersCalendarHeader';
|
|
28
29
|
export { DayCalendar } from '../DateCalendar/DayCalendar';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { DATE_TIME_VALIDATION_PROP_NAMES, DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES } from './validation/extractValidationProps';
|
|
3
|
+
var SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'format', 'formatDensity', 'onChange', 'readOnly', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'unstableFieldRef'];
|
|
4
|
+
export var splitFieldInternalAndForwardedProps = function splitFieldInternalAndForwardedProps(props, valueType) {
|
|
5
|
+
var forwardedProps = _extends({}, props);
|
|
6
|
+
var internalProps = {};
|
|
7
|
+
var extractProp = function extractProp(propName) {
|
|
8
|
+
if (forwardedProps.hasOwnProperty(propName)) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
internalProps[propName] = forwardedProps[propName];
|
|
11
|
+
delete forwardedProps[propName];
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
SHARED_FIELD_INTERNAL_PROP_NAMES.forEach(extractProp);
|
|
15
|
+
if (valueType === 'date') {
|
|
16
|
+
DATE_VALIDATION_PROP_NAMES.forEach(extractProp);
|
|
17
|
+
} else if (valueType === 'time') {
|
|
18
|
+
TIME_VALIDATION_PROP_NAMES.forEach(extractProp);
|
|
19
|
+
} else if (valueType === 'date-time') {
|
|
20
|
+
DATE_VALIDATION_PROP_NAMES.forEach(extractProp);
|
|
21
|
+
TIME_VALIDATION_PROP_NAMES.forEach(extractProp);
|
|
22
|
+
DATE_TIME_VALIDATION_PROP_NAMES.forEach(extractProp);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
forwardedProps: forwardedProps,
|
|
26
|
+
internalProps: internalProps
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
var
|
|
1
|
+
export var DATE_VALIDATION_PROP_NAMES = ['disablePast', 'disableFuture', 'minDate', 'maxDate', 'shouldDisableDate', 'shouldDisableMonth', 'shouldDisableYear'];
|
|
2
|
+
export var TIME_VALIDATION_PROP_NAMES = ['disablePast', 'disableFuture', 'minTime', 'maxTime', 'shouldDisableClock', 'shouldDisableTime', 'minutesStep', 'ampm', 'disableIgnoringDatePartForTimeValidation'];
|
|
3
|
+
export var DATE_TIME_VALIDATION_PROP_NAMES = ['minDateTime', 'maxDateTime'];
|
|
4
|
+
var VALIDATION_PROP_NAMES = [].concat(DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES, DATE_TIME_VALIDATION_PROP_NAMES);
|
|
2
5
|
/**
|
|
3
6
|
* Extract the validation props for the props received by a component.
|
|
4
7
|
* Limit the risk of forgetting some of them and reduce the bundle size.
|
|
@@ -21,7 +21,7 @@ export var testCalculations = function testCalculations(_ref) {
|
|
|
21
21
|
expect(adapter.date(null)).to.equal(null);
|
|
22
22
|
});
|
|
23
23
|
it('should parse undefined', function () {
|
|
24
|
-
expect(adapter.date(undefined)).
|
|
24
|
+
expect(Math.abs(adapter.toJsDate(adapter.date(undefined)).getTime() - Date.now())).to.be.lessThan(5);
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
it('Method: toJsDate', function () {
|
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import createDescribe from '@mui/monorepo/test/utils/createDescribe';
|
|
4
|
+
import { buildFieldInteractions } from 'test/utils/pickers-utils';
|
|
4
5
|
import { testControlledUnControlled } from './testControlledUnControlled';
|
|
5
6
|
import { testPickerOpenCloseLifeCycle } from './testPickerOpenCloseLifeCycle';
|
|
6
7
|
import { testPickerActionBar } from './testPickerActionBar';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
9
|
var TEST_SUITES = [testControlledUnControlled, testPickerOpenCloseLifeCycle, testPickerActionBar];
|
|
9
10
|
function innerDescribeValue(ElementToTest, getOptions) {
|
|
10
|
-
var
|
|
11
|
-
|
|
11
|
+
var options = getOptions();
|
|
12
|
+
var defaultProps = options.defaultProps,
|
|
13
|
+
render = options.render,
|
|
14
|
+
clock = options.clock,
|
|
15
|
+
componentFamily = options.componentFamily;
|
|
12
16
|
function WrappedElementToTest(props) {
|
|
13
17
|
return /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, props));
|
|
14
18
|
}
|
|
19
|
+
var renderWithProps;
|
|
20
|
+
if (componentFamily === 'field' || componentFamily === 'picker') {
|
|
21
|
+
var interactions = buildFieldInteractions({
|
|
22
|
+
clock: clock,
|
|
23
|
+
render: render,
|
|
24
|
+
Component: ElementToTest
|
|
25
|
+
});
|
|
26
|
+
renderWithProps = function renderWithProps(props) {
|
|
27
|
+
return interactions.renderWithProps(_extends({}, defaultProps, props), componentFamily);
|
|
28
|
+
};
|
|
29
|
+
} else {
|
|
30
|
+
renderWithProps = function renderWithProps(props) {
|
|
31
|
+
var response = render( /*#__PURE__*/_jsx(WrappedElementToTest, _extends({}, props)));
|
|
32
|
+
return _extends({}, response, {
|
|
33
|
+
input: null,
|
|
34
|
+
selectSection: function selectSection() {
|
|
35
|
+
throw new Error('You can only select a section on components that render a field');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
15
40
|
TEST_SUITES.forEach(function (testSuite) {
|
|
16
|
-
testSuite(WrappedElementToTest,
|
|
41
|
+
testSuite(WrappedElementToTest, _extends({}, options, {
|
|
42
|
+
renderWithProps: renderWithProps
|
|
43
|
+
}));
|
|
17
44
|
});
|
|
18
45
|
}
|
|
19
46
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["render", "values", "componentFamily", "emptyValue", "assertRenderedValue", "setNewValue", "clock"];
|
|
4
|
+
var _excluded = ["render", "renderWithProps", "values", "componentFamily", "emptyValue", "assertRenderedValue", "setNewValue", "clock"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { expect } from 'chai';
|
|
7
7
|
import { spy } from 'sinon';
|
|
@@ -10,16 +10,16 @@ import { inputBaseClasses } from '@mui/material/InputBase';
|
|
|
10
10
|
import { getExpectedOnChangeCount } from 'test/utils/pickers-utils';
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
export var testControlledUnControlled = function testControlledUnControlled(ElementToTest,
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
values =
|
|
17
|
-
componentFamily =
|
|
18
|
-
emptyValue =
|
|
19
|
-
assertRenderedValue =
|
|
20
|
-
setNewValue =
|
|
21
|
-
clock =
|
|
22
|
-
pickerParams = _objectWithoutProperties(
|
|
13
|
+
export var testControlledUnControlled = function testControlledUnControlled(ElementToTest, options) {
|
|
14
|
+
var render = options.render,
|
|
15
|
+
renderWithProps = options.renderWithProps,
|
|
16
|
+
values = options.values,
|
|
17
|
+
componentFamily = options.componentFamily,
|
|
18
|
+
emptyValue = options.emptyValue,
|
|
19
|
+
assertRenderedValue = options.assertRenderedValue,
|
|
20
|
+
setNewValue = options.setNewValue,
|
|
21
|
+
clock = options.clock,
|
|
22
|
+
pickerParams = _objectWithoutProperties(options, _excluded);
|
|
23
23
|
var params = pickerParams;
|
|
24
24
|
describe('Controlled / uncontrolled value', function () {
|
|
25
25
|
it('should render `props.defaultValue` if no `props.value` is passed', function () {
|
|
@@ -47,11 +47,14 @@ export var testControlledUnControlled = function testControlledUnControlled(Elem
|
|
|
47
47
|
});
|
|
48
48
|
it('should call onChange when updating a value defined with `props.defaultValue` and update the rendered value', function () {
|
|
49
49
|
var onChange = spy();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
var _renderWithProps = renderWithProps({
|
|
51
|
+
defaultValue: values[0],
|
|
52
|
+
onChange: onChange
|
|
53
|
+
}),
|
|
54
|
+
selectSection = _renderWithProps.selectSection;
|
|
55
|
+
var newValue = setNewValue(values[0], {
|
|
56
|
+
selectSection: selectSection
|
|
57
|
+
});
|
|
55
58
|
assertRenderedValue(newValue);
|
|
56
59
|
// TODO: Clean this exception or change the clock behavior
|
|
57
60
|
expect(onChange.callCount).to.equal(getExpectedOnChangeCount(componentFamily));
|
|
@@ -65,11 +68,14 @@ export var testControlledUnControlled = function testControlledUnControlled(Elem
|
|
|
65
68
|
});
|
|
66
69
|
it('should call onChange when updating a value defined with `props.value`', function () {
|
|
67
70
|
var onChange = spy();
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
var _renderWithProps2 = renderWithProps({
|
|
72
|
+
defaultValue: values[0],
|
|
73
|
+
onChange: onChange
|
|
74
|
+
}),
|
|
75
|
+
selectSection = _renderWithProps2.selectSection;
|
|
76
|
+
var newValue = setNewValue(values[0], {
|
|
77
|
+
selectSection: selectSection
|
|
78
|
+
});
|
|
73
79
|
expect(onChange.callCount).to.equal(getExpectedOnChangeCount(componentFamily));
|
|
74
80
|
if (Array.isArray(newValue)) {
|
|
75
81
|
newValue.forEach(function (value, index) {
|
|
@@ -4,14 +4,14 @@ import { spy } from 'sinon';
|
|
|
4
4
|
import { screen, userEvent } from '@mui/monorepo/test/utils';
|
|
5
5
|
import { adapterToUse } from 'test/utils/pickers-utils';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
export var testPickerActionBar = function testPickerActionBar(ElementToTest,
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
values =
|
|
12
|
-
emptyValue =
|
|
13
|
-
setNewValue =
|
|
14
|
-
type =
|
|
7
|
+
export var testPickerActionBar = function testPickerActionBar(ElementToTest, options) {
|
|
8
|
+
var componentFamily = options.componentFamily,
|
|
9
|
+
render = options.render,
|
|
10
|
+
renderWithProps = options.renderWithProps,
|
|
11
|
+
values = options.values,
|
|
12
|
+
emptyValue = options.emptyValue,
|
|
13
|
+
setNewValue = options.setNewValue,
|
|
14
|
+
type = options.type;
|
|
15
15
|
if (componentFamily !== 'picker') {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
@@ -83,23 +83,25 @@ export var testPickerActionBar = function testPickerActionBar(ElementToTest, get
|
|
|
83
83
|
var onChange = spy();
|
|
84
84
|
var onAccept = spy();
|
|
85
85
|
var onClose = spy();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
var _renderWithProps = renderWithProps({
|
|
87
|
+
onChange: onChange,
|
|
88
|
+
onAccept: onAccept,
|
|
89
|
+
onClose: onClose,
|
|
90
|
+
open: true,
|
|
91
|
+
value: values[0],
|
|
92
|
+
slotProps: {
|
|
93
|
+
actionBar: {
|
|
94
|
+
actions: ['cancel']
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
closeOnSelect: false
|
|
98
|
+
}),
|
|
99
|
+
selectSection = _renderWithProps.selectSection;
|
|
99
100
|
|
|
100
101
|
// Change the value (already tested)
|
|
101
102
|
setNewValue(values[0], {
|
|
102
|
-
isOpened: true
|
|
103
|
+
isOpened: true,
|
|
104
|
+
selectSection: selectSection
|
|
103
105
|
});
|
|
104
106
|
|
|
105
107
|
// Cancel the modifications
|
|
@@ -145,23 +147,25 @@ export var testPickerActionBar = function testPickerActionBar(ElementToTest, get
|
|
|
145
147
|
var onChange = spy();
|
|
146
148
|
var onAccept = spy();
|
|
147
149
|
var onClose = spy();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
var _renderWithProps2 = renderWithProps({
|
|
151
|
+
onChange: onChange,
|
|
152
|
+
onAccept: onAccept,
|
|
153
|
+
onClose: onClose,
|
|
154
|
+
open: true,
|
|
155
|
+
defaultValue: values[0],
|
|
156
|
+
slotProps: {
|
|
157
|
+
actionBar: {
|
|
158
|
+
actions: ['accept']
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
closeOnSelect: false
|
|
162
|
+
}),
|
|
163
|
+
selectSection = _renderWithProps2.selectSection;
|
|
161
164
|
|
|
162
165
|
// Change the value (already tested)
|
|
163
166
|
setNewValue(values[0], {
|
|
164
|
-
isOpened: true
|
|
167
|
+
isOpened: true,
|
|
168
|
+
selectSection: selectSection
|
|
165
169
|
});
|
|
166
170
|
|
|
167
171
|
// Accept the modifications
|