@mui/x-date-pickers 6.1.0 → 6.2.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/AdapterDayjs/AdapterDayjs.d.ts +114 -0
- package/AdapterDayjs/AdapterDayjs.js +387 -0
- package/AdapterDayjs/index.d.ts +1 -28
- package/AdapterDayjs/index.js +1 -102
- package/CHANGELOG.md +53 -1
- package/DateCalendar/DateCalendar.types.d.ts +1 -1
- package/DateCalendar/DayCalendar.d.ts +1 -1
- package/DateField/DateField.js +6 -0
- package/DateField/useDateField.js +3 -1
- package/DatePicker/DatePicker.js +6 -0
- package/DateTimeField/DateTimeField.js +6 -0
- package/DateTimeField/useDateTimeField.js +3 -1
- package/DateTimePicker/DateTimePicker.js +6 -0
- package/DateTimePicker/shared.js +3 -1
- package/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/MobileDatePicker/MobileDatePicker.js +6 -0
- package/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/MobileTimePicker/MobileTimePicker.js +6 -0
- package/README.md +1 -0
- package/TimeClock/TimeClock.types.d.ts +1 -1
- package/TimeField/TimeField.js +6 -0
- package/TimeField/useTimeField.js +3 -1
- package/TimePicker/TimePicker.js +6 -0
- package/index.js +1 -1
- package/internals/components/PickersModalDialog.d.ts +1 -1
- package/internals/components/PickersPopper.d.ts +1 -1
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +1 -1
- package/internals/hooks/useField/useField.types.d.ts +6 -0
- package/internals/hooks/useField/useField.utils.d.ts +1 -1
- package/internals/hooks/useField/useField.utils.js +16 -4
- package/internals/hooks/useField/useFieldState.js +3 -2
- package/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/index.d.ts +1 -1
- package/internals/hooks/usePicker/usePicker.types.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -1
- package/internals/hooks/usePicker/usePickerValue.d.ts +3 -179
- package/internals/hooks/usePicker/usePickerValue.js +187 -153
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +233 -0
- package/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/internals/hooks/usePicker/usePickerViews.d.ts +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/models/props/basePickerProps.d.ts +6 -0
- package/legacy/AdapterDayjs/AdapterDayjs.js +403 -0
- package/legacy/AdapterDayjs/index.js +1 -119
- package/legacy/DateField/DateField.js +6 -0
- package/legacy/DateField/useDateField.js +3 -1
- package/legacy/DatePicker/DatePicker.js +6 -0
- package/legacy/DateTimeField/DateTimeField.js +6 -0
- package/legacy/DateTimeField/useDateTimeField.js +3 -1
- package/legacy/DateTimePicker/DateTimePicker.js +6 -0
- package/legacy/DateTimePicker/shared.js +3 -1
- package/legacy/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/legacy/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/legacy/MobileDatePicker/MobileDatePicker.js +6 -0
- package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/legacy/MobileTimePicker/MobileTimePicker.js +6 -0
- package/legacy/TimeField/TimeField.js +6 -0
- package/legacy/TimeField/useTimeField.js +3 -1
- package/legacy/TimePicker/TimePicker.js +6 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/legacy/internals/hooks/useField/useField.utils.js +24 -9
- package/legacy/internals/hooks/useField/useFieldState.js +5 -3
- package/legacy/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/legacy/internals/hooks/usePicker/usePickerValue.js +184 -153
- package/legacy/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/legacy/tests/describeGregorianAdapter/index.js +1 -0
- package/legacy/tests/describeGregorianAdapter/testCalculations.js +273 -0
- package/legacy/tests/describeGregorianAdapter/testFormat.js +26 -0
- package/legacy/tests/describeGregorianAdapter/testLocalization.js +15 -0
- package/legacy/tests/describeValidation/describeValidation.js +2 -1
- package/legacy/tests/describeValidation/testMinutesViewValidation.js +201 -0
- package/legacy/tests/describeValue/testPickerActionBar.js +52 -3
- package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/models/adapters.d.ts +21 -20
- package/modern/AdapterDayjs/AdapterDayjs.js +386 -0
- package/modern/AdapterDayjs/index.js +1 -101
- package/modern/DateField/DateField.js +6 -0
- package/modern/DateField/useDateField.js +3 -1
- package/modern/DatePicker/DatePicker.js +6 -0
- package/modern/DateTimeField/DateTimeField.js +6 -0
- package/modern/DateTimeField/useDateTimeField.js +3 -1
- package/modern/DateTimePicker/DateTimePicker.js +6 -0
- package/modern/DateTimePicker/shared.js +3 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/modern/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +6 -0
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/modern/MobileTimePicker/MobileTimePicker.js +6 -0
- package/modern/TimeField/TimeField.js +6 -0
- package/modern/TimeField/useTimeField.js +3 -1
- package/modern/TimePicker/TimePicker.js +6 -0
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/modern/internals/hooks/useField/useField.utils.js +16 -4
- package/modern/internals/hooks/useField/useFieldState.js +3 -2
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/modern/internals/hooks/usePicker/usePickerValue.js +187 -153
- package/modern/internals/hooks/usePicker/usePickerValue.types.js +1 -0
- package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/modern/tests/describeGregorianAdapter/index.js +1 -0
- package/modern/tests/describeGregorianAdapter/testCalculations.js +272 -0
- package/modern/tests/describeGregorianAdapter/testFormat.js +27 -0
- package/modern/tests/describeGregorianAdapter/testLocalization.js +16 -0
- package/modern/tests/describeValidation/describeValidation.js +2 -1
- package/modern/tests/describeValidation/testMinutesViewValidation.js +200 -0
- package/modern/tests/describeValue/testPickerActionBar.js +52 -3
- package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/node/AdapterDayjs/AdapterDayjs.js +395 -0
- package/node/AdapterDayjs/index.js +6 -104
- package/node/DateField/DateField.js +6 -0
- package/node/DateField/useDateField.js +3 -1
- package/node/DatePicker/DatePicker.js +6 -0
- package/node/DateTimeField/DateTimeField.js +6 -0
- package/node/DateTimeField/useDateTimeField.js +3 -1
- package/node/DateTimePicker/DateTimePicker.js +6 -0
- package/node/DateTimePicker/shared.js +3 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +6 -0
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
- package/node/DesktopTimePicker/DesktopTimePicker.js +6 -0
- package/node/MobileDatePicker/MobileDatePicker.js +6 -0
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
- package/node/MobileTimePicker/MobileTimePicker.js +6 -0
- package/node/TimeField/TimeField.js +6 -0
- package/node/TimeField/useTimeField.js +3 -1
- package/node/TimePicker/TimePicker.js +6 -0
- package/node/index.js +1 -1
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
- package/node/internals/hooks/useField/useField.utils.js +16 -4
- package/node/internals/hooks/useField/useFieldState.js +3 -2
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
- package/node/internals/hooks/usePicker/usePickerValue.js +187 -152
- package/node/internals/hooks/usePicker/usePickerValue.types.js +5 -0
- package/node/tests/describeGregorianAdapter/describeGregorianAdapter.js +29 -0
- package/node/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +5 -0
- package/node/tests/describeGregorianAdapter/index.js +18 -0
- package/node/tests/describeGregorianAdapter/testCalculations.js +279 -0
- package/node/tests/describeGregorianAdapter/testFormat.js +34 -0
- package/node/tests/describeGregorianAdapter/testLocalization.js +23 -0
- package/node/tests/describeValidation/describeValidation.js +2 -1
- package/node/tests/describeValidation/testMinutesViewValidation.js +210 -0
- package/node/tests/describeValue/testPickerActionBar.js +52 -3
- package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
- package/package.json +9 -9
- package/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
- package/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
- package/tests/describeGregorianAdapter/index.js +1 -0
- package/tests/describeGregorianAdapter/testCalculations.js +272 -0
- package/tests/describeGregorianAdapter/testFormat.js +27 -0
- package/tests/describeGregorianAdapter/testLocalization.js +16 -0
- package/tests/describeValidation/describeValidation.js +2 -1
- package/tests/describeValidation/testMinutesViewValidation.js +200 -0
- package/tests/describeValue/testPickerActionBar.js +52 -3
- package/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
|
@@ -5,26 +5,91 @@ import useEventCallback from '@mui/utils/useEventCallback';
|
|
|
5
5
|
import { useOpenState } from '../useOpenState';
|
|
6
6
|
import { useLocalizationContext, useUtils } from '../useUtils';
|
|
7
7
|
import { useValidation } from '../validation/useValidation';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Props used to handle the value that are common to all pickers.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
8
|
/**
|
|
14
|
-
*
|
|
9
|
+
* Decide if the new value should be published
|
|
10
|
+
* The published value will be passed to `onChange` if defined.
|
|
15
11
|
*/
|
|
12
|
+
const shouldPublishValue = params => {
|
|
13
|
+
const {
|
|
14
|
+
action,
|
|
15
|
+
hasChanged,
|
|
16
|
+
dateState,
|
|
17
|
+
isControlled
|
|
18
|
+
} = params;
|
|
19
|
+
const isCurrentValueTheDefaultValue = !isControlled && !dateState.hasBeenModifiedSinceMount;
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
// The field is responsible for only calling `onChange` when needed.
|
|
22
|
+
if (action.name === 'setValueFromField') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (action.name === 'setValueFromAction') {
|
|
26
|
+
// If the component is not controlled, and the value has not been modified since the mount,
|
|
27
|
+
// Then we want to publish the default value whenever the user pressed the "Accept", "Today" or "Clear" button.
|
|
28
|
+
if (isCurrentValueTheDefaultValue && ['accept', 'today', 'clear'].includes(action.pickerAction)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return hasChanged(dateState.lastPublishedValue);
|
|
32
|
+
}
|
|
33
|
+
if (action.name === 'setValueFromView' && action.selectionState !== 'shallow') {
|
|
34
|
+
// On the first view,
|
|
35
|
+
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
|
|
36
|
+
if (isCurrentValueTheDefaultValue) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return hasChanged(dateState.lastPublishedValue);
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
20
43
|
|
|
21
44
|
/**
|
|
22
|
-
*
|
|
45
|
+
* Decide if the new value should be committed.
|
|
46
|
+
* The committed value will be passed to `onAccept` if defined.
|
|
47
|
+
* It will also be used as a reset target when calling the `cancel` picker action (when clicking on the "Cancel" button).
|
|
23
48
|
*/
|
|
49
|
+
const shouldCommitValue = params => {
|
|
50
|
+
const {
|
|
51
|
+
action,
|
|
52
|
+
hasChanged,
|
|
53
|
+
dateState,
|
|
54
|
+
isControlled,
|
|
55
|
+
closeOnSelect
|
|
56
|
+
} = params;
|
|
57
|
+
const isCurrentValueTheDefaultValue = !isControlled && !dateState.hasBeenModifiedSinceMount;
|
|
58
|
+
if (action.name === 'setValueFromAction') {
|
|
59
|
+
// If the component is not controlled, and the value has not been modified since the mount,
|
|
60
|
+
// Then we want to commit the default value whenever the user pressed the "Accept", "Today" or "Clear" button.
|
|
61
|
+
if (isCurrentValueTheDefaultValue && ['accept', 'today', 'clear'].includes(action.pickerAction)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return hasChanged(dateState.lastCommittedValue);
|
|
65
|
+
}
|
|
66
|
+
if (action.name === 'setValueFromView' && action.selectionState === 'finish' && closeOnSelect) {
|
|
67
|
+
// On picker where the 1st view is also the last view,
|
|
68
|
+
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onAccept`
|
|
69
|
+
if (isCurrentValueTheDefaultValue) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return hasChanged(dateState.lastCommittedValue);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
24
76
|
|
|
25
77
|
/**
|
|
26
|
-
*
|
|
78
|
+
* Decide if the picker should be closed after the value is updated.
|
|
27
79
|
*/
|
|
80
|
+
const shouldClosePicker = params => {
|
|
81
|
+
const {
|
|
82
|
+
action,
|
|
83
|
+
closeOnSelect
|
|
84
|
+
} = params;
|
|
85
|
+
if (action.name === 'setValueFromAction') {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (action.name === 'setValueFromView') {
|
|
89
|
+
return action.selectionState === 'finish' && closeOnSelect;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
28
93
|
|
|
29
94
|
/**
|
|
30
95
|
* Manage the value lifecycle of all the pickers.
|
|
@@ -36,22 +101,38 @@ export const usePickerValue = ({
|
|
|
36
101
|
validator
|
|
37
102
|
}) => {
|
|
38
103
|
const {
|
|
39
|
-
onAccept
|
|
104
|
+
onAccept,
|
|
40
105
|
onChange,
|
|
41
106
|
value: inValue,
|
|
42
|
-
defaultValue,
|
|
107
|
+
defaultValue: inDefaultValue,
|
|
43
108
|
closeOnSelect = wrapperVariant === 'desktop',
|
|
44
109
|
selectedSections: selectedSectionsProp,
|
|
45
110
|
onSelectedSectionsChange
|
|
46
111
|
} = props;
|
|
112
|
+
const {
|
|
113
|
+
current: defaultValue
|
|
114
|
+
} = React.useRef(inDefaultValue);
|
|
115
|
+
const {
|
|
116
|
+
current: isControlled
|
|
117
|
+
} = React.useRef(inValue !== undefined);
|
|
118
|
+
|
|
119
|
+
/* eslint-disable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
120
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
121
|
+
React.useEffect(() => {
|
|
122
|
+
if (isControlled !== (inValue !== undefined)) {
|
|
123
|
+
console.error([`MUI: A component is changing the ${isControlled ? '' : 'un'}controlled value of a picker to be ${isControlled ? 'un' : ''}controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', `Decide between using a controlled or uncontrolled value` + 'for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
|
|
124
|
+
}
|
|
125
|
+
}, [inValue]);
|
|
126
|
+
React.useEffect(() => {
|
|
127
|
+
if (!isControlled && defaultValue !== inDefaultValue) {
|
|
128
|
+
console.error([`MUI: A component is changing the defaultValue of an uncontrolled picker after being initialized. ` + `To suppress this warning opt to use a controlled value.`].join('\n'));
|
|
129
|
+
}
|
|
130
|
+
}, [JSON.stringify(defaultValue)]);
|
|
131
|
+
}
|
|
132
|
+
/* eslint-enable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
133
|
+
|
|
47
134
|
const utils = useUtils();
|
|
48
135
|
const adapter = useLocalizationContext();
|
|
49
|
-
const [value, setValue] = useControlled({
|
|
50
|
-
controlled: inValue,
|
|
51
|
-
default: defaultValue ?? valueManager.emptyValue,
|
|
52
|
-
name: 'usePickerValue',
|
|
53
|
-
state: 'value'
|
|
54
|
-
});
|
|
55
136
|
const [selectedSections, setSelectedSections] = useControlled({
|
|
56
137
|
controlled: selectedSectionsProp,
|
|
57
138
|
default: null,
|
|
@@ -62,170 +143,123 @@ export const usePickerValue = ({
|
|
|
62
143
|
isOpen,
|
|
63
144
|
setIsOpen
|
|
64
145
|
} = useOpenState(props);
|
|
65
|
-
const [dateState, setDateState] = React.useState(() =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
146
|
+
const [dateState, setDateState] = React.useState(() => {
|
|
147
|
+
let initialValue;
|
|
148
|
+
if (inValue !== undefined) {
|
|
149
|
+
initialValue = inValue;
|
|
150
|
+
} else if (defaultValue !== undefined) {
|
|
151
|
+
initialValue = defaultValue;
|
|
152
|
+
} else {
|
|
153
|
+
initialValue = valueManager.emptyValue;
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
draft: initialValue,
|
|
157
|
+
lastPublishedValue: initialValue,
|
|
158
|
+
lastCommittedValue: initialValue,
|
|
159
|
+
lastControlledValue: inValue,
|
|
160
|
+
hasBeenModifiedSinceMount: false
|
|
161
|
+
};
|
|
162
|
+
});
|
|
70
163
|
useValidation(_extends({}, props, {
|
|
71
|
-
value
|
|
164
|
+
value: dateState.draft
|
|
72
165
|
}), validator, valueManager.isSameError, valueManager.defaultErrorState);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
setValue(params.value);
|
|
106
|
-
if (onChange) {
|
|
107
|
-
const context = {
|
|
108
|
-
validationError: params.contextFromField == null ? validator({
|
|
109
|
-
adapter,
|
|
110
|
-
value: params.value,
|
|
111
|
-
props: _extends({}, props, {
|
|
112
|
-
value: params.value
|
|
113
|
-
})
|
|
114
|
-
}) : params.contextFromField.validationError
|
|
115
|
-
};
|
|
116
|
-
onChange(params.value, context);
|
|
117
|
-
}
|
|
166
|
+
const updateDate = useEventCallback(action => {
|
|
167
|
+
const updaterParams = {
|
|
168
|
+
action,
|
|
169
|
+
dateState,
|
|
170
|
+
hasChanged: comparison => !valueManager.areValuesEqual(utils, action.value, comparison),
|
|
171
|
+
isControlled,
|
|
172
|
+
closeOnSelect
|
|
173
|
+
};
|
|
174
|
+
const shouldPublish = shouldPublishValue(updaterParams);
|
|
175
|
+
const shouldCommit = shouldCommitValue(updaterParams);
|
|
176
|
+
const shouldClose = shouldClosePicker(updaterParams);
|
|
177
|
+
setDateState(prev => _extends({}, prev, {
|
|
178
|
+
draft: action.value,
|
|
179
|
+
lastPublishedValue: shouldPublish ? action.value : prev.lastPublishedValue,
|
|
180
|
+
lastCommittedValue: shouldCommit ? action.value : prev.lastCommittedValue,
|
|
181
|
+
hasBeenModifiedSinceMount: true
|
|
182
|
+
}));
|
|
183
|
+
if (shouldPublish && onChange) {
|
|
184
|
+
const validationError = action.name === 'setValueFromField' ? action.context.validationError : validator({
|
|
185
|
+
adapter,
|
|
186
|
+
value: action.value,
|
|
187
|
+
props: _extends({}, props, {
|
|
188
|
+
value: action.value
|
|
189
|
+
})
|
|
190
|
+
});
|
|
191
|
+
const context = {
|
|
192
|
+
validationError
|
|
193
|
+
};
|
|
194
|
+
onChange(action.value, context);
|
|
195
|
+
}
|
|
196
|
+
if (shouldCommit && onAccept) {
|
|
197
|
+
onAccept(action.value);
|
|
118
198
|
}
|
|
119
|
-
if (
|
|
199
|
+
if (shouldClose) {
|
|
120
200
|
setIsOpen(false);
|
|
121
|
-
if (onAcceptProp && !valueManager.areValuesEqual(utils, dateState.resetFallback, params.value)) {
|
|
122
|
-
onAcceptProp(params.value);
|
|
123
|
-
}
|
|
124
201
|
}
|
|
125
202
|
});
|
|
126
203
|
React.useEffect(() => {
|
|
127
204
|
if (isOpen) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
value,
|
|
132
|
-
skipOnChangeCall: true
|
|
133
|
-
});
|
|
205
|
+
setDateState(prev => _extends({}, prev, {
|
|
206
|
+
lastCommittedValue: dateState.draft
|
|
207
|
+
}));
|
|
134
208
|
}
|
|
135
209
|
}, [isOpen]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
136
210
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
skipOnChangeCall: true
|
|
143
|
-
});
|
|
211
|
+
if (inValue !== undefined && (dateState.lastControlledValue === undefined || !valueManager.areValuesEqual(utils, dateState.lastControlledValue, inValue))) {
|
|
212
|
+
setDateState(prev => _extends({}, prev, {
|
|
213
|
+
lastControlledValue: inValue,
|
|
214
|
+
draft: inValue
|
|
215
|
+
}));
|
|
144
216
|
}
|
|
145
217
|
const handleClear = useEventCallback(() => {
|
|
146
|
-
|
|
147
|
-
setDate({
|
|
218
|
+
updateDate({
|
|
148
219
|
value: valueManager.emptyValue,
|
|
149
|
-
|
|
220
|
+
name: 'setValueFromAction',
|
|
221
|
+
pickerAction: 'clear'
|
|
150
222
|
});
|
|
151
223
|
});
|
|
152
224
|
const handleAccept = useEventCallback(() => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
225
|
+
updateDate({
|
|
226
|
+
value: dateState.lastPublishedValue,
|
|
227
|
+
name: 'setValueFromAction',
|
|
228
|
+
pickerAction: 'accept'
|
|
157
229
|
});
|
|
158
230
|
});
|
|
159
231
|
const handleDismiss = useEventCallback(() => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
action: 'acceptAndClose'
|
|
232
|
+
updateDate({
|
|
233
|
+
value: dateState.lastPublishedValue,
|
|
234
|
+
name: 'setValueFromAction',
|
|
235
|
+
pickerAction: 'dismiss'
|
|
165
236
|
});
|
|
166
237
|
});
|
|
167
238
|
const handleCancel = useEventCallback(() => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
action: 'acceptAndClose'
|
|
239
|
+
updateDate({
|
|
240
|
+
value: dateState.lastCommittedValue,
|
|
241
|
+
name: 'setValueFromAction',
|
|
242
|
+
pickerAction: 'cancel'
|
|
173
243
|
});
|
|
174
244
|
});
|
|
175
245
|
const handleSetToday = useEventCallback(() => {
|
|
176
|
-
|
|
177
|
-
setDate({
|
|
246
|
+
updateDate({
|
|
178
247
|
value: valueManager.getTodayValue(utils),
|
|
179
|
-
|
|
248
|
+
name: 'setValueFromAction',
|
|
249
|
+
pickerAction: 'today'
|
|
180
250
|
});
|
|
181
251
|
});
|
|
182
252
|
const handleOpen = useEventCallback(() => setIsOpen(true));
|
|
183
253
|
const handleClose = useEventCallback(() => setIsOpen(false));
|
|
184
|
-
const handleChange = useEventCallback((
|
|
185
|
-
|
|
186
|
-
case 'shallow':
|
|
187
|
-
{
|
|
188
|
-
// Update the `draft` state but do not fire `onChange`
|
|
189
|
-
return setDate({
|
|
190
|
-
action: 'setDraft',
|
|
191
|
-
value: newDate,
|
|
192
|
-
skipOnChangeCall: true
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
case 'partial':
|
|
196
|
-
{
|
|
197
|
-
// Update the `draft` state and fire `onChange`
|
|
198
|
-
return setDate({
|
|
199
|
-
action: 'setDraft',
|
|
200
|
-
value: newDate
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
case 'finish':
|
|
204
|
-
{
|
|
205
|
-
if (closeOnSelect) {
|
|
206
|
-
// Set all dates in state to equal the new date and close picker.
|
|
207
|
-
return setDate({
|
|
208
|
-
value: newDate,
|
|
209
|
-
action: 'acceptAndClose'
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Updates the `committed` state and fire `onChange`
|
|
214
|
-
return setDate({
|
|
215
|
-
value: newDate,
|
|
216
|
-
action: 'setCommitted'
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
default:
|
|
220
|
-
{
|
|
221
|
-
throw new Error('MUI: Invalid selectionState passed to `onDateChange`');
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
const handleChangeAndCommit = useEventCallback((newValue, contextFromField) => setDate({
|
|
226
|
-
action: 'setCommitted',
|
|
254
|
+
const handleChange = useEventCallback((newValue, selectionState = 'partial') => updateDate({
|
|
255
|
+
name: 'setValueFromView',
|
|
227
256
|
value: newValue,
|
|
228
|
-
|
|
257
|
+
selectionState
|
|
258
|
+
}));
|
|
259
|
+
const handleChangeField = useEventCallback((newValue, context) => updateDate({
|
|
260
|
+
name: 'setValueFromField',
|
|
261
|
+
value: newValue,
|
|
262
|
+
context
|
|
229
263
|
}));
|
|
230
264
|
const handleFieldSelectedSectionsChange = useEventCallback(newSelectedSections => {
|
|
231
265
|
setSelectedSections(newSelectedSections);
|
|
@@ -242,7 +276,7 @@ export const usePickerValue = ({
|
|
|
242
276
|
};
|
|
243
277
|
const fieldResponse = {
|
|
244
278
|
value: dateState.draft,
|
|
245
|
-
onChange:
|
|
279
|
+
onChange: handleChangeField,
|
|
246
280
|
selectedSections,
|
|
247
281
|
onSelectedSectionsChange: handleFieldSelectedSectionsChange
|
|
248
282
|
};
|
|
@@ -266,7 +300,7 @@ export const usePickerValue = ({
|
|
|
266
300
|
};
|
|
267
301
|
const layoutResponse = _extends({}, actions, {
|
|
268
302
|
value: viewValue,
|
|
269
|
-
onChange:
|
|
303
|
+
onChange: handleChange,
|
|
270
304
|
isValid
|
|
271
305
|
});
|
|
272
306
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import createDescribe from '@mui/monorepo/test/utils/createDescribe';
|
|
3
|
+
import { testCalculations } from './testCalculations';
|
|
4
|
+
import { testLocalization } from './testLocalization';
|
|
5
|
+
import { testFormat } from './testFormat';
|
|
6
|
+
export const TEST_DATE_ISO = '2018-10-30T11:44:00.000Z';
|
|
7
|
+
function innerGregorianDescribeAdapter(Adapter, params) {
|
|
8
|
+
const adapter = new Adapter({});
|
|
9
|
+
describe(adapter.lib, () => {
|
|
10
|
+
const testSuitParams = _extends({}, params, {
|
|
11
|
+
adapter,
|
|
12
|
+
testDateISO: TEST_DATE_ISO,
|
|
13
|
+
testDate: adapter.date(TEST_DATE_ISO)
|
|
14
|
+
});
|
|
15
|
+
testCalculations(testSuitParams);
|
|
16
|
+
testLocalization(testSuitParams);
|
|
17
|
+
testFormat(testSuitParams);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export const describeGregorianAdapter = createDescribe('Adapter methods', innerGregorianDescribeAdapter);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { describeGregorianAdapter, TEST_DATE_ISO } from './describeGregorianAdapter';
|