@mui/x-date-pickers 6.11.0 → 6.11.1
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 +62 -0
- package/DateField/DateField.js +1 -0
- package/DateTimeField/DateTimeField.js +1 -0
- package/DateTimePicker/DateTimePickerToolbar.js +4 -3
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -2
- package/PickersDay/PickersDay.js +1 -0
- package/PickersShortcuts/PickersShortcuts.js +1 -0
- package/TimeField/TimeField.js +1 -0
- package/TimePicker/TimePickerToolbar.js +3 -2
- package/index.js +1 -1
- package/internals/hooks/useField/useField.js +1 -1
- package/internals/hooks/usePicker/usePickerValue.js +1 -1
- package/internals/utils/date-utils.d.ts +1 -0
- package/internals/utils/date-utils.js +4 -0
- package/legacy/DateField/DateField.js +1 -0
- package/legacy/DateTimeField/DateTimeField.js +1 -0
- package/legacy/DateTimePicker/DateTimePickerToolbar.js +4 -3
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -2
- package/legacy/PickersDay/PickersDay.js +1 -0
- package/legacy/PickersShortcuts/PickersShortcuts.js +1 -0
- package/legacy/TimeField/TimeField.js +1 -0
- package/legacy/TimePicker/TimePickerToolbar.js +3 -2
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useField/useField.js +1 -1
- package/legacy/internals/hooks/usePicker/usePickerValue.js +1 -1
- package/legacy/internals/utils/date-utils.js +4 -0
- package/legacy/locales/fiFI.js +8 -5
- package/legacy/locales/isIS.js +33 -16
- package/legacy/tests/describeValue/describeValue.js +2 -1
- package/legacy/tests/describeValue/testPickerActionBar.js +12 -28
- package/legacy/tests/describeValue/testShortcuts.js +119 -0
- package/locales/fiFI.js +4 -5
- package/locales/isIS.js +13 -16
- package/models/adapters.d.ts +1 -0
- package/modern/DateField/DateField.js +1 -0
- package/modern/DateTimeField/DateTimeField.js +1 -0
- package/modern/DateTimePicker/DateTimePickerToolbar.js +4 -3
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -2
- package/modern/PickersDay/PickersDay.js +1 -0
- package/modern/PickersShortcuts/PickersShortcuts.js +1 -0
- package/modern/TimeField/TimeField.js +1 -0
- package/modern/TimePicker/TimePickerToolbar.js +3 -2
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useField/useField.js +1 -1
- package/modern/internals/hooks/usePicker/usePickerValue.js +1 -1
- package/modern/internals/utils/date-utils.js +4 -0
- package/modern/locales/fiFI.js +4 -5
- package/modern/locales/isIS.js +13 -16
- package/modern/tests/describeValue/describeValue.js +2 -1
- package/modern/tests/describeValue/testPickerActionBar.js +12 -28
- package/modern/tests/describeValue/testShortcuts.js +112 -0
- package/node/DateField/DateField.js +1 -0
- package/node/DateTimeField/DateTimeField.js +1 -0
- package/node/DateTimePicker/DateTimePickerToolbar.js +4 -3
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +3 -2
- package/node/PickersDay/PickersDay.js +1 -0
- package/node/PickersShortcuts/PickersShortcuts.js +1 -0
- package/node/TimeField/TimeField.js +1 -0
- package/node/TimePicker/TimePickerToolbar.js +3 -2
- package/node/index.js +1 -1
- package/node/internals/hooks/useField/useField.js +1 -1
- package/node/internals/hooks/usePicker/usePickerValue.js +1 -1
- package/node/internals/utils/date-utils.js +6 -1
- package/node/locales/fiFI.js +4 -5
- package/node/locales/isIS.js +13 -16
- package/node/tests/describeValue/describeValue.js +2 -1
- package/node/tests/describeValue/testPickerActionBar.js +12 -28
- package/node/tests/describeValue/testShortcuts.js +122 -0
- package/package.json +3 -3
- package/tests/describeValue/describeValue.js +2 -1
- package/tests/describeValue/testPickerActionBar.js +12 -28
- package/tests/describeValue/testShortcuts.js +112 -0
- package/themeAugmentation/components.d.ts +6 -14
- package/themeAugmentation/overrides.d.ts +0 -20
- package/themeAugmentation/props.d.ts +4 -0
|
@@ -18,6 +18,7 @@ var _useUtils = require("../internals/hooks/useUtils");
|
|
|
18
18
|
var _dateTimePickerToolbarClasses = require("./dateTimePickerToolbarClasses");
|
|
19
19
|
var _dateHelpersHooks = require("../internals/hooks/date-helpers-hooks");
|
|
20
20
|
var _dimensions = require("../internals/constants/dimensions");
|
|
21
|
+
var _dateUtils = require("../internals/utils/date-utils");
|
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
23
|
const _excluded = ["ampm", "ampmInClock", "value", "onChange", "view", "isLandscape", "onViewChange", "toolbarFormat", "toolbarPlaceholder", "views", "disabled", "readOnly", "toolbarVariant"];
|
|
23
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -272,14 +273,14 @@ function DateTimePickerToolbar(inProps) {
|
|
|
272
273
|
variant: "subtitle2",
|
|
273
274
|
selected: meridiemMode === 'am',
|
|
274
275
|
typographyClassName: classes.ampmLabel,
|
|
275
|
-
value:
|
|
276
|
+
value: (0, _dateUtils.formatMeridiem)(utils, 'am'),
|
|
276
277
|
onClick: readOnly ? undefined : () => handleMeridiemChange('am'),
|
|
277
278
|
disabled: disabled
|
|
278
279
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
|
|
279
280
|
variant: "subtitle2",
|
|
280
281
|
selected: meridiemMode === 'pm',
|
|
281
282
|
typographyClassName: classes.ampmLabel,
|
|
282
|
-
value:
|
|
283
|
+
value: (0, _dateUtils.formatMeridiem)(utils, 'pm'),
|
|
283
284
|
onClick: readOnly ? undefined : () => handleMeridiemChange('pm'),
|
|
284
285
|
disabled: disabled
|
|
285
286
|
})]
|
|
@@ -287,7 +288,7 @@ function DateTimePickerToolbar(inProps) {
|
|
|
287
288
|
variant: "h5",
|
|
288
289
|
onClick: () => onViewChange('meridiem'),
|
|
289
290
|
selected: view === 'meridiem',
|
|
290
|
-
value: value && meridiemMode ?
|
|
291
|
+
value: value && meridiemMode ? (0, _dateUtils.formatMeridiem)(utils, meridiemMode) : '--',
|
|
291
292
|
width: _dimensions.MULTI_SECTION_CLOCK_SECTION_WIDTH
|
|
292
293
|
})]
|
|
293
294
|
})]
|
|
@@ -24,6 +24,7 @@ var _MultiSectionDigitalClock = require("./MultiSectionDigitalClock.utils");
|
|
|
24
24
|
var _useValueWithTimezone = require("../internals/hooks/useValueWithTimezone");
|
|
25
25
|
var _valueManagers = require("../internals/utils/valueManagers");
|
|
26
26
|
var _useClockReferenceDate = require("../internals/hooks/useClockReferenceDate");
|
|
27
|
+
var _dateUtils = require("../internals/utils/date-utils");
|
|
27
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
28
29
|
const _excluded = ["ampm", "timeSteps", "autoFocus", "components", "componentsProps", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableClock", "shouldDisableTime", "onChange", "view", "views", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "disabled", "readOnly", "skipDisabled", "timezone"];
|
|
29
30
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -278,8 +279,8 @@ const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function MultiSec
|
|
|
278
279
|
}
|
|
279
280
|
case 'meridiem':
|
|
280
281
|
{
|
|
281
|
-
const amLabel =
|
|
282
|
-
const pmLabel =
|
|
282
|
+
const amLabel = (0, _dateUtils.formatMeridiem)(utils, 'am');
|
|
283
|
+
const pmLabel = (0, _dateUtils.formatMeridiem)(utils, 'pm');
|
|
283
284
|
return {
|
|
284
285
|
onChange: handleMeridiemChange,
|
|
285
286
|
items: [{
|
|
@@ -68,6 +68,7 @@ process.env.NODE_ENV !== "production" ? PickersShortcuts.propTypes = {
|
|
|
68
68
|
*/
|
|
69
69
|
changeImportance: _propTypes.default.oneOf(['accept', 'set']),
|
|
70
70
|
className: _propTypes.default.string,
|
|
71
|
+
component: _propTypes.default.elementType,
|
|
71
72
|
/**
|
|
72
73
|
* If `true`, compact vertical padding designed for keyboard and mouse input is used for
|
|
73
74
|
* the list and list items.
|
|
@@ -99,6 +99,7 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
|
|
|
99
99
|
* @default 'primary'
|
|
100
100
|
*/
|
|
101
101
|
color: _propTypes.default.oneOf(['error', 'info', 'primary', 'secondary', 'success', 'warning']),
|
|
102
|
+
component: _propTypes.default.elementType,
|
|
102
103
|
/**
|
|
103
104
|
* Overridable components.
|
|
104
105
|
* @default {}
|
|
@@ -18,6 +18,7 @@ var _utils2 = require("../internals/utils/utils");
|
|
|
18
18
|
var _useUtils = require("../internals/hooks/useUtils");
|
|
19
19
|
var _dateHelpersHooks = require("../internals/hooks/date-helpers-hooks");
|
|
20
20
|
var _timePickerToolbarClasses = require("./timePickerToolbarClasses");
|
|
21
|
+
var _dateUtils = require("../internals/utils/date-utils");
|
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
23
|
const _excluded = ["ampm", "ampmInClock", "value", "isLandscape", "onChange", "view", "onViewChange", "views", "disabled", "readOnly"];
|
|
23
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -187,7 +188,7 @@ function TimePickerToolbar(inProps) {
|
|
|
187
188
|
variant: "subtitle2",
|
|
188
189
|
selected: meridiemMode === 'am',
|
|
189
190
|
typographyClassName: classes.ampmLabel,
|
|
190
|
-
value:
|
|
191
|
+
value: (0, _dateUtils.formatMeridiem)(utils, 'am'),
|
|
191
192
|
onClick: readOnly ? undefined : () => handleMeridiemChange('am'),
|
|
192
193
|
disabled: disabled
|
|
193
194
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersToolbarButton.PickersToolbarButton, {
|
|
@@ -195,7 +196,7 @@ function TimePickerToolbar(inProps) {
|
|
|
195
196
|
variant: "subtitle2",
|
|
196
197
|
selected: meridiemMode === 'pm',
|
|
197
198
|
typographyClassName: classes.ampmLabel,
|
|
198
|
-
value:
|
|
199
|
+
value: (0, _dateUtils.formatMeridiem)(utils, 'pm'),
|
|
199
200
|
onClick: readOnly ? undefined : () => handleMeridiemChange('pm'),
|
|
200
201
|
disabled: disabled
|
|
201
202
|
})]
|
package/node/index.js
CHANGED
|
@@ -375,7 +375,7 @@ const useField = params => {
|
|
|
375
375
|
if (state.sections[selectedSectionIndexes.startIndex].contentType === 'letter') {
|
|
376
376
|
return 'text';
|
|
377
377
|
}
|
|
378
|
-
return '
|
|
378
|
+
return 'numeric';
|
|
379
379
|
}, [selectedSectionIndexes, state.sections]);
|
|
380
380
|
const inputHasFocus = inputRef.current && inputRef.current === (0, _utils.getActiveElement)(document);
|
|
381
381
|
const shouldShowPlaceholder = !inputHasFocus && valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue);
|
|
@@ -48,7 +48,7 @@ const shouldPublishValue = params => {
|
|
|
48
48
|
}
|
|
49
49
|
return hasChanged(dateState.lastPublishedValue);
|
|
50
50
|
}
|
|
51
|
-
if (action.name === 'setValueFromShortcut'
|
|
51
|
+
if (action.name === 'setValueFromShortcut') {
|
|
52
52
|
// On the first view,
|
|
53
53
|
// If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
|
|
54
54
|
if (isCurrentValueTheDefaultValue) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.resolveDateFormat = exports.replaceInvalidDateByNull = exports.mergeDateAndTime = exports.isDatePickerView = exports.getTodayDate = exports.getMonthsInYear = exports.findClosestEnabledDate = exports.areDatesEqual = exports.applyDefaultDate = void 0;
|
|
6
|
+
exports.resolveDateFormat = exports.replaceInvalidDateByNull = exports.mergeDateAndTime = exports.isDatePickerView = exports.getTodayDate = exports.getMonthsInYear = exports.formatMeridiem = exports.findClosestEnabledDate = exports.areDatesEqual = exports.applyDefaultDate = void 0;
|
|
7
7
|
var _views = require("./views");
|
|
8
8
|
const findClosestEnabledDate = ({
|
|
9
9
|
date,
|
|
@@ -93,6 +93,11 @@ const mergeDateAndTime = (utils, dateParam, timeParam) => {
|
|
|
93
93
|
exports.mergeDateAndTime = mergeDateAndTime;
|
|
94
94
|
const getTodayDate = (utils, timezone, valueType) => valueType === 'date' ? utils.startOfDay(utils.dateWithTimezone(undefined, timezone)) : utils.dateWithTimezone(undefined, timezone);
|
|
95
95
|
exports.getTodayDate = getTodayDate;
|
|
96
|
+
const formatMeridiem = (utils, meridiem) => {
|
|
97
|
+
const date = utils.setHours(utils.date(), meridiem === 'am' ? 2 : 14);
|
|
98
|
+
return utils.format(date, 'meridiem');
|
|
99
|
+
};
|
|
100
|
+
exports.formatMeridiem = formatMeridiem;
|
|
96
101
|
const dateViews = ['year', 'month', 'day'];
|
|
97
102
|
const isDatePickerView = view => dateViews.includes(view);
|
|
98
103
|
exports.isDatePickerView = isDatePickerView;
|
package/node/locales/fiFI.js
CHANGED
|
@@ -40,11 +40,10 @@ const fiFIPickers = {
|
|
|
40
40
|
// Digital clock labels
|
|
41
41
|
selectViewText: view => `Valitse ${views[view]}`,
|
|
42
42
|
// Calendar labels
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
calendarWeekNumberHeaderLabel: 'Viikko',
|
|
44
|
+
calendarWeekNumberHeaderText: '#',
|
|
45
|
+
calendarWeekNumberAriaLabelText: weekNumber => `Viikko ${weekNumber}`,
|
|
46
|
+
calendarWeekNumberText: weekNumber => `${weekNumber}`,
|
|
48
47
|
// Open picker labels
|
|
49
48
|
openDatePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Valitse päivä, valittu päivä on ${utils.format(value, 'fullDate')}` : 'Valitse päivä',
|
|
50
49
|
openTimePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Valitse aika, valittu aika on ${utils.format(value, 'fullTime')}` : 'Valitse aika',
|
package/node/locales/isIS.js
CHANGED
|
@@ -40,28 +40,25 @@ const isISPickers = {
|
|
|
40
40
|
// Digital clock labels
|
|
41
41
|
selectViewText: view => `Velja ${timeViews[view]}`,
|
|
42
42
|
// Calendar labels
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
calendarWeekNumberHeaderLabel: 'Vikunúmer',
|
|
44
|
+
calendarWeekNumberHeaderText: '#',
|
|
45
|
+
calendarWeekNumberAriaLabelText: weekNumber => `Vika ${weekNumber}`,
|
|
46
|
+
calendarWeekNumberText: weekNumber => `${weekNumber}`,
|
|
48
47
|
// Open picker labels
|
|
49
48
|
openDatePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Velja dagsetningu, valin dagsetning er ${utils.format(value, 'fullDate')}` : 'Velja dagsetningu',
|
|
50
49
|
openTimePickerDialogue: (value, utils) => value !== null && utils.isValid(value) ? `Velja tíma, valinn tími er ${utils.format(value, 'fullTime')}` : 'Velja tíma',
|
|
51
50
|
// Table labels
|
|
52
51
|
timeTableLabel: 'velja tíma',
|
|
53
|
-
dateTableLabel: 'velja dagsetningu'
|
|
54
|
-
|
|
52
|
+
dateTableLabel: 'velja dagsetningu',
|
|
55
53
|
// Field section placeholders
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
fieldYearPlaceholder: params => 'Á'.repeat(params.digitAmount),
|
|
55
|
+
fieldMonthPlaceholder: params => params.contentType === 'letter' ? 'MMMM' : 'MM',
|
|
56
|
+
fieldDayPlaceholder: () => 'DD',
|
|
57
|
+
fieldWeekDayPlaceholder: params => params.contentType === 'letter' ? 'EEEE' : 'EE',
|
|
58
|
+
fieldHoursPlaceholder: () => 'kk',
|
|
59
|
+
fieldMinutesPlaceholder: () => 'mm',
|
|
60
|
+
fieldSecondsPlaceholder: () => 'ss',
|
|
61
|
+
fieldMeridiemPlaceholder: () => 'ee'
|
|
64
62
|
};
|
|
65
|
-
|
|
66
63
|
const isIS = (0, _getPickersLocalization.getPickersLocalization)(isISPickers);
|
|
67
64
|
exports.isIS = isIS;
|
|
@@ -13,11 +13,12 @@ var _pickersUtils = require("test/utils/pickers-utils");
|
|
|
13
13
|
var _testControlledUnControlled = require("./testControlledUnControlled");
|
|
14
14
|
var _testPickerOpenCloseLifeCycle = require("./testPickerOpenCloseLifeCycle");
|
|
15
15
|
var _testPickerActionBar = require("./testPickerActionBar");
|
|
16
|
+
var _testShortcuts = require("./testShortcuts");
|
|
16
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
18
|
const _excluded = ["hook"];
|
|
18
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
20
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
-
const TEST_SUITES = [_testControlledUnControlled.testControlledUnControlled, _testPickerOpenCloseLifeCycle.testPickerOpenCloseLifeCycle, _testPickerActionBar.testPickerActionBar];
|
|
21
|
+
const TEST_SUITES = [_testControlledUnControlled.testControlledUnControlled, _testPickerOpenCloseLifeCycle.testPickerOpenCloseLifeCycle, _testPickerActionBar.testPickerActionBar, _testShortcuts.testShortcuts];
|
|
21
22
|
function innerDescribeValue(ElementToTest, getOptions) {
|
|
22
23
|
const options = getOptions();
|
|
23
24
|
const {
|
|
@@ -11,6 +11,7 @@ var _chai = require("chai");
|
|
|
11
11
|
var _sinon = require("sinon");
|
|
12
12
|
var _utils = require("@mui/monorepo/test/utils");
|
|
13
13
|
var _pickersUtils = require("test/utils/pickers-utils");
|
|
14
|
+
var _assertions = require("test/utils/pickers/assertions");
|
|
14
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
16
|
const _excluded = ["componentFamily", "render", "renderWithProps", "values", "emptyValue", "setNewValue"];
|
|
16
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -50,21 +51,9 @@ const testPickerActionBar = (ElementToTest, options) => {
|
|
|
50
51
|
// Clear the date
|
|
51
52
|
_utils.userEvent.mousePress(_utils.screen.getByText(/clear/i));
|
|
52
53
|
(0, _chai.expect)(onChange.callCount).to.equal(1);
|
|
53
|
-
|
|
54
|
-
onChange.lastCall.args[0].forEach((value, index) => {
|
|
55
|
-
(0, _chai.expect)(value).to.deep.equal(emptyValue[index]);
|
|
56
|
-
});
|
|
57
|
-
} else {
|
|
58
|
-
(0, _chai.expect)(onChange.lastCall.args[0]).to.deep.equal(emptyValue);
|
|
59
|
-
}
|
|
54
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onChange, emptyValue);
|
|
60
55
|
(0, _chai.expect)(onAccept.callCount).to.equal(1);
|
|
61
|
-
|
|
62
|
-
onAccept.lastCall.args[0].forEach((value, index) => {
|
|
63
|
-
(0, _chai.expect)(value).to.deep.equal(emptyValue[index]);
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
(0, _chai.expect)(onAccept.lastCall.args[0]).to.deep.equal(emptyValue);
|
|
67
|
-
}
|
|
56
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onAccept, emptyValue);
|
|
68
57
|
(0, _chai.expect)(onClose.callCount).to.equal(1);
|
|
69
58
|
});
|
|
70
59
|
it('should not call onChange or onAccept if the value is already empty value', () => {
|
|
@@ -256,23 +245,18 @@ const testPickerActionBar = (ElementToTest, options) => {
|
|
|
256
245
|
}
|
|
257
246
|
}));
|
|
258
247
|
_utils.userEvent.mousePress(_utils.screen.getByText(/today/i));
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
248
|
+
let startOfToday;
|
|
249
|
+
if (pickerParams.type === 'date') {
|
|
250
|
+
startOfToday = _pickersUtils.adapterToUse.startOfDay(_pickersUtils.adapterToUse.date());
|
|
251
|
+
} else if (pickerParams.type === 'date-range') {
|
|
252
|
+
startOfToday = [_pickersUtils.adapterToUse.date(), _pickersUtils.adapterToUse.date()];
|
|
265
253
|
} else {
|
|
266
|
-
|
|
254
|
+
startOfToday = _pickersUtils.adapterToUse.date();
|
|
267
255
|
}
|
|
256
|
+
(0, _chai.expect)(onChange.callCount).to.equal(1);
|
|
257
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onChange, startOfToday);
|
|
268
258
|
(0, _chai.expect)(onAccept.callCount).to.equal(1);
|
|
269
|
-
|
|
270
|
-
onAccept.lastCall.args[0].forEach(value => {
|
|
271
|
-
(0, _chai.expect)(value).toEqualDateTime(startOfToday);
|
|
272
|
-
});
|
|
273
|
-
} else {
|
|
274
|
-
(0, _chai.expect)(onAccept.lastCall.args[0]).toEqualDateTime(startOfToday);
|
|
275
|
-
}
|
|
259
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onAccept, startOfToday);
|
|
276
260
|
(0, _chai.expect)(onClose.callCount).to.equal(1);
|
|
277
261
|
});
|
|
278
262
|
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.testShortcuts = void 0;
|
|
8
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _chai = require("chai");
|
|
11
|
+
var _sinon = require("sinon");
|
|
12
|
+
var _assertions = require("test/utils/pickers/assertions");
|
|
13
|
+
var _utils = require("@mui/monorepo/test/utils");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
const _excluded = ["componentFamily", "render", "renderWithProps", "values", "emptyValue", "setNewValue"];
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
const testShortcuts = (ElementToTest, options) => {
|
|
19
|
+
const {
|
|
20
|
+
componentFamily,
|
|
21
|
+
render,
|
|
22
|
+
values
|
|
23
|
+
} = options,
|
|
24
|
+
pickerParams = (0, _objectWithoutPropertiesLoose2.default)(options, _excluded);
|
|
25
|
+
if (componentFamily !== 'picker') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
describe('Picker shortcuts', () => {
|
|
29
|
+
it('should call onClose, onChange and onAccept when picking a shortcut without explicit changeImportance', () => {
|
|
30
|
+
const onChange = (0, _sinon.spy)();
|
|
31
|
+
const onAccept = (0, _sinon.spy)();
|
|
32
|
+
const onClose = (0, _sinon.spy)();
|
|
33
|
+
render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
|
|
34
|
+
onChange: onChange,
|
|
35
|
+
onAccept: onAccept,
|
|
36
|
+
onClose: onClose,
|
|
37
|
+
defaultValue: values[0],
|
|
38
|
+
open: true,
|
|
39
|
+
closeOnSelect: true,
|
|
40
|
+
slotProps: {
|
|
41
|
+
shortcuts: {
|
|
42
|
+
items: [{
|
|
43
|
+
label: 'Test shortcut',
|
|
44
|
+
getValue: () => values[1]
|
|
45
|
+
}]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
const shortcut = _utils.screen.getByRole('button', {
|
|
50
|
+
name: 'Test shortcut'
|
|
51
|
+
});
|
|
52
|
+
_utils.userEvent.mousePress(shortcut);
|
|
53
|
+
(0, _chai.expect)(onChange.callCount).to.equal(1);
|
|
54
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onChange, values[1]);
|
|
55
|
+
(0, _chai.expect)(onAccept.callCount).to.equal(1);
|
|
56
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onAccept, values[1]);
|
|
57
|
+
(0, _chai.expect)(onClose.callCount).to.equal(1);
|
|
58
|
+
});
|
|
59
|
+
it('should call onClose and onChange when picking a shortcut with changeImportance="accept"', () => {
|
|
60
|
+
const onChange = (0, _sinon.spy)();
|
|
61
|
+
const onAccept = (0, _sinon.spy)();
|
|
62
|
+
const onClose = (0, _sinon.spy)();
|
|
63
|
+
render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
|
|
64
|
+
onChange: onChange,
|
|
65
|
+
onAccept: onAccept,
|
|
66
|
+
onClose: onClose,
|
|
67
|
+
defaultValue: values[0],
|
|
68
|
+
open: true,
|
|
69
|
+
closeOnSelect: true,
|
|
70
|
+
slotProps: {
|
|
71
|
+
shortcuts: {
|
|
72
|
+
items: [{
|
|
73
|
+
label: 'Test shortcut',
|
|
74
|
+
getValue: () => values[1]
|
|
75
|
+
}],
|
|
76
|
+
changeImportance: 'accept'
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
const shortcut = _utils.screen.getByRole('button', {
|
|
81
|
+
name: 'Test shortcut'
|
|
82
|
+
});
|
|
83
|
+
_utils.userEvent.mousePress(shortcut);
|
|
84
|
+
(0, _chai.expect)(onChange.callCount).to.equal(1);
|
|
85
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onChange, values[1]);
|
|
86
|
+
(0, _chai.expect)(onAccept.callCount).to.equal(1);
|
|
87
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onAccept, values[1]);
|
|
88
|
+
(0, _chai.expect)(onClose.callCount).to.equal(1);
|
|
89
|
+
});
|
|
90
|
+
it('should call onClose and onChange when picking a shortcut with changeImportance="set"', () => {
|
|
91
|
+
const onChange = (0, _sinon.spy)();
|
|
92
|
+
const onAccept = (0, _sinon.spy)();
|
|
93
|
+
const onClose = (0, _sinon.spy)();
|
|
94
|
+
render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
|
|
95
|
+
onChange: onChange,
|
|
96
|
+
onAccept: onAccept,
|
|
97
|
+
onClose: onClose,
|
|
98
|
+
defaultValue: values[0],
|
|
99
|
+
open: true,
|
|
100
|
+
closeOnSelect: true,
|
|
101
|
+
slotProps: {
|
|
102
|
+
shortcuts: {
|
|
103
|
+
items: [{
|
|
104
|
+
label: 'Test shortcut',
|
|
105
|
+
getValue: () => values[1]
|
|
106
|
+
}],
|
|
107
|
+
changeImportance: 'set'
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
const shortcut = _utils.screen.getByRole('button', {
|
|
112
|
+
name: 'Test shortcut'
|
|
113
|
+
});
|
|
114
|
+
_utils.userEvent.mousePress(shortcut);
|
|
115
|
+
(0, _chai.expect)(onChange.callCount).to.equal(1);
|
|
116
|
+
(0, _assertions.expectPickerChangeHandlerValue)(pickerParams.type, onChange, values[1]);
|
|
117
|
+
(0, _chai.expect)(onAccept.callCount).to.equal(0);
|
|
118
|
+
(0, _chai.expect)(onClose.callCount).to.equal(0);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
exports.testShortcuts = testShortcuts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-date-pickers",
|
|
3
|
-
"version": "6.11.
|
|
3
|
+
"version": "6.11.1",
|
|
4
4
|
"description": "The community edition of the date picker components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.22.6",
|
|
37
|
-
"@mui/utils": "^5.14.
|
|
37
|
+
"@mui/utils": "^5.14.3",
|
|
38
38
|
"@types/react-transition-group": "^4.4.6",
|
|
39
|
-
"clsx": "^
|
|
39
|
+
"clsx": "^2.0.0",
|
|
40
40
|
"prop-types": "^15.8.1",
|
|
41
41
|
"react-transition-group": "^4.4.5"
|
|
42
42
|
},
|
|
@@ -7,8 +7,9 @@ import { buildFieldInteractions } from 'test/utils/pickers-utils';
|
|
|
7
7
|
import { testControlledUnControlled } from './testControlledUnControlled';
|
|
8
8
|
import { testPickerOpenCloseLifeCycle } from './testPickerOpenCloseLifeCycle';
|
|
9
9
|
import { testPickerActionBar } from './testPickerActionBar';
|
|
10
|
+
import { testShortcuts } from './testShortcuts';
|
|
10
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
const TEST_SUITES = [testControlledUnControlled, testPickerOpenCloseLifeCycle, testPickerActionBar];
|
|
12
|
+
const TEST_SUITES = [testControlledUnControlled, testPickerOpenCloseLifeCycle, testPickerActionBar, testShortcuts];
|
|
12
13
|
function innerDescribeValue(ElementToTest, getOptions) {
|
|
13
14
|
const options = getOptions();
|
|
14
15
|
const {
|
|
@@ -5,6 +5,7 @@ import { expect } from 'chai';
|
|
|
5
5
|
import { spy } from 'sinon';
|
|
6
6
|
import { screen, userEvent } from '@mui/monorepo/test/utils';
|
|
7
7
|
import { adapterToUse, getExpectedOnChangeCount } from 'test/utils/pickers-utils';
|
|
8
|
+
import { expectPickerChangeHandlerValue } from 'test/utils/pickers/assertions';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
10
|
export const testPickerActionBar = (ElementToTest, options) => {
|
|
10
11
|
const {
|
|
@@ -41,21 +42,9 @@ export const testPickerActionBar = (ElementToTest, options) => {
|
|
|
41
42
|
// Clear the date
|
|
42
43
|
userEvent.mousePress(screen.getByText(/clear/i));
|
|
43
44
|
expect(onChange.callCount).to.equal(1);
|
|
44
|
-
|
|
45
|
-
onChange.lastCall.args[0].forEach((value, index) => {
|
|
46
|
-
expect(value).to.deep.equal(emptyValue[index]);
|
|
47
|
-
});
|
|
48
|
-
} else {
|
|
49
|
-
expect(onChange.lastCall.args[0]).to.deep.equal(emptyValue);
|
|
50
|
-
}
|
|
45
|
+
expectPickerChangeHandlerValue(pickerParams.type, onChange, emptyValue);
|
|
51
46
|
expect(onAccept.callCount).to.equal(1);
|
|
52
|
-
|
|
53
|
-
onAccept.lastCall.args[0].forEach((value, index) => {
|
|
54
|
-
expect(value).to.deep.equal(emptyValue[index]);
|
|
55
|
-
});
|
|
56
|
-
} else {
|
|
57
|
-
expect(onAccept.lastCall.args[0]).to.deep.equal(emptyValue);
|
|
58
|
-
}
|
|
47
|
+
expectPickerChangeHandlerValue(pickerParams.type, onAccept, emptyValue);
|
|
59
48
|
expect(onClose.callCount).to.equal(1);
|
|
60
49
|
});
|
|
61
50
|
it('should not call onChange or onAccept if the value is already empty value', () => {
|
|
@@ -247,23 +236,18 @@ export const testPickerActionBar = (ElementToTest, options) => {
|
|
|
247
236
|
}
|
|
248
237
|
}));
|
|
249
238
|
userEvent.mousePress(screen.getByText(/today/i));
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
});
|
|
239
|
+
let startOfToday;
|
|
240
|
+
if (pickerParams.type === 'date') {
|
|
241
|
+
startOfToday = adapterToUse.startOfDay(adapterToUse.date());
|
|
242
|
+
} else if (pickerParams.type === 'date-range') {
|
|
243
|
+
startOfToday = [adapterToUse.date(), adapterToUse.date()];
|
|
256
244
|
} else {
|
|
257
|
-
|
|
245
|
+
startOfToday = adapterToUse.date();
|
|
258
246
|
}
|
|
247
|
+
expect(onChange.callCount).to.equal(1);
|
|
248
|
+
expectPickerChangeHandlerValue(pickerParams.type, onChange, startOfToday);
|
|
259
249
|
expect(onAccept.callCount).to.equal(1);
|
|
260
|
-
|
|
261
|
-
onAccept.lastCall.args[0].forEach(value => {
|
|
262
|
-
expect(value).toEqualDateTime(startOfToday);
|
|
263
|
-
});
|
|
264
|
-
} else {
|
|
265
|
-
expect(onAccept.lastCall.args[0]).toEqualDateTime(startOfToday);
|
|
266
|
-
}
|
|
250
|
+
expectPickerChangeHandlerValue(pickerParams.type, onAccept, startOfToday);
|
|
267
251
|
expect(onClose.callCount).to.equal(1);
|
|
268
252
|
});
|
|
269
253
|
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
const _excluded = ["componentFamily", "render", "renderWithProps", "values", "emptyValue", "setNewValue"];
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { expect } from 'chai';
|
|
5
|
+
import { spy } from 'sinon';
|
|
6
|
+
import { expectPickerChangeHandlerValue } from 'test/utils/pickers/assertions';
|
|
7
|
+
import { userEvent, screen } from '@mui/monorepo/test/utils';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
export const testShortcuts = (ElementToTest, options) => {
|
|
10
|
+
const {
|
|
11
|
+
componentFamily,
|
|
12
|
+
render,
|
|
13
|
+
values
|
|
14
|
+
} = options,
|
|
15
|
+
pickerParams = _objectWithoutPropertiesLoose(options, _excluded);
|
|
16
|
+
if (componentFamily !== 'picker') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
describe('Picker shortcuts', () => {
|
|
20
|
+
it('should call onClose, onChange and onAccept when picking a shortcut without explicit changeImportance', () => {
|
|
21
|
+
const onChange = spy();
|
|
22
|
+
const onAccept = spy();
|
|
23
|
+
const onClose = spy();
|
|
24
|
+
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
25
|
+
onChange: onChange,
|
|
26
|
+
onAccept: onAccept,
|
|
27
|
+
onClose: onClose,
|
|
28
|
+
defaultValue: values[0],
|
|
29
|
+
open: true,
|
|
30
|
+
closeOnSelect: true,
|
|
31
|
+
slotProps: {
|
|
32
|
+
shortcuts: {
|
|
33
|
+
items: [{
|
|
34
|
+
label: 'Test shortcut',
|
|
35
|
+
getValue: () => values[1]
|
|
36
|
+
}]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
const shortcut = screen.getByRole('button', {
|
|
41
|
+
name: 'Test shortcut'
|
|
42
|
+
});
|
|
43
|
+
userEvent.mousePress(shortcut);
|
|
44
|
+
expect(onChange.callCount).to.equal(1);
|
|
45
|
+
expectPickerChangeHandlerValue(pickerParams.type, onChange, values[1]);
|
|
46
|
+
expect(onAccept.callCount).to.equal(1);
|
|
47
|
+
expectPickerChangeHandlerValue(pickerParams.type, onAccept, values[1]);
|
|
48
|
+
expect(onClose.callCount).to.equal(1);
|
|
49
|
+
});
|
|
50
|
+
it('should call onClose and onChange when picking a shortcut with changeImportance="accept"', () => {
|
|
51
|
+
const onChange = spy();
|
|
52
|
+
const onAccept = spy();
|
|
53
|
+
const onClose = spy();
|
|
54
|
+
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
55
|
+
onChange: onChange,
|
|
56
|
+
onAccept: onAccept,
|
|
57
|
+
onClose: onClose,
|
|
58
|
+
defaultValue: values[0],
|
|
59
|
+
open: true,
|
|
60
|
+
closeOnSelect: true,
|
|
61
|
+
slotProps: {
|
|
62
|
+
shortcuts: {
|
|
63
|
+
items: [{
|
|
64
|
+
label: 'Test shortcut',
|
|
65
|
+
getValue: () => values[1]
|
|
66
|
+
}],
|
|
67
|
+
changeImportance: 'accept'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
const shortcut = screen.getByRole('button', {
|
|
72
|
+
name: 'Test shortcut'
|
|
73
|
+
});
|
|
74
|
+
userEvent.mousePress(shortcut);
|
|
75
|
+
expect(onChange.callCount).to.equal(1);
|
|
76
|
+
expectPickerChangeHandlerValue(pickerParams.type, onChange, values[1]);
|
|
77
|
+
expect(onAccept.callCount).to.equal(1);
|
|
78
|
+
expectPickerChangeHandlerValue(pickerParams.type, onAccept, values[1]);
|
|
79
|
+
expect(onClose.callCount).to.equal(1);
|
|
80
|
+
});
|
|
81
|
+
it('should call onClose and onChange when picking a shortcut with changeImportance="set"', () => {
|
|
82
|
+
const onChange = spy();
|
|
83
|
+
const onAccept = spy();
|
|
84
|
+
const onClose = spy();
|
|
85
|
+
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
86
|
+
onChange: onChange,
|
|
87
|
+
onAccept: onAccept,
|
|
88
|
+
onClose: onClose,
|
|
89
|
+
defaultValue: values[0],
|
|
90
|
+
open: true,
|
|
91
|
+
closeOnSelect: true,
|
|
92
|
+
slotProps: {
|
|
93
|
+
shortcuts: {
|
|
94
|
+
items: [{
|
|
95
|
+
label: 'Test shortcut',
|
|
96
|
+
getValue: () => values[1]
|
|
97
|
+
}],
|
|
98
|
+
changeImportance: 'set'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
const shortcut = screen.getByRole('button', {
|
|
103
|
+
name: 'Test shortcut'
|
|
104
|
+
});
|
|
105
|
+
userEvent.mousePress(shortcut);
|
|
106
|
+
expect(onChange.callCount).to.equal(1);
|
|
107
|
+
expectPickerChangeHandlerValue(pickerParams.type, onChange, values[1]);
|
|
108
|
+
expect(onAccept.callCount).to.equal(0);
|
|
109
|
+
expect(onClose.callCount).to.equal(0);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|