@mui/x-date-pickers 6.7.0 → 6.8.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +77 -15
  2. package/DateCalendar/DateCalendar.js +16 -6
  3. package/DateCalendar/DateCalendar.types.d.ts +6 -1
  4. package/DateCalendar/useCalendarState.d.ts +3 -2
  5. package/DateCalendar/useCalendarState.js +36 -15
  6. package/DateField/DateField.js +1 -1
  7. package/DatePicker/DatePicker.js +1 -1
  8. package/DateTimeField/DateTimeField.js +1 -1
  9. package/DateTimePicker/DateTimePicker.js +1 -1
  10. package/DesktopDatePicker/DesktopDatePicker.js +1 -1
  11. package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  12. package/MobileDatePicker/MobileDatePicker.js +1 -1
  13. package/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  14. package/MonthCalendar/MonthCalendar.js +28 -11
  15. package/MonthCalendar/MonthCalendar.types.d.ts +5 -0
  16. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  17. package/PickersLayout/PickersLayout.js +1 -0
  18. package/PickersLayout/usePickerLayout.js +4 -3
  19. package/PickersShortcuts/PickersShortcuts.d.ts +12 -2
  20. package/PickersShortcuts/PickersShortcuts.js +10 -2
  21. package/PickersShortcuts/index.d.ts +1 -1
  22. package/StaticDatePicker/StaticDatePicker.js +1 -1
  23. package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  24. package/TimeField/TimeField.js +1 -1
  25. package/YearCalendar/YearCalendar.js +26 -9
  26. package/YearCalendar/YearCalendar.types.d.ts +5 -0
  27. package/index.js +1 -1
  28. package/internals/hooks/useField/useField.types.d.ts +1 -1
  29. package/internals/hooks/useField/useFieldState.js +0 -1
  30. package/internals/hooks/usePicker/usePickerValue.js +22 -2
  31. package/internals/hooks/usePicker/usePickerValue.types.d.ts +6 -2
  32. package/internals/utils/date-utils.d.ts +1 -2
  33. package/internals/utils/date-utils.js +0 -9
  34. package/internals/utils/getDefaultReferenceDate.d.ts +11 -3
  35. package/internals/utils/getDefaultReferenceDate.js +2 -3
  36. package/legacy/DateCalendar/DateCalendar.js +16 -6
  37. package/legacy/DateCalendar/useCalendarState.js +35 -15
  38. package/legacy/DateField/DateField.js +1 -1
  39. package/legacy/DatePicker/DatePicker.js +1 -1
  40. package/legacy/DateTimeField/DateTimeField.js +1 -1
  41. package/legacy/DateTimePicker/DateTimePicker.js +1 -1
  42. package/legacy/DesktopDatePicker/DesktopDatePicker.js +1 -1
  43. package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  44. package/legacy/MobileDatePicker/MobileDatePicker.js +1 -1
  45. package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  46. package/legacy/MonthCalendar/MonthCalendar.js +30 -13
  47. package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  48. package/legacy/PickersLayout/PickersLayout.js +1 -0
  49. package/legacy/PickersLayout/usePickerLayout.js +3 -2
  50. package/legacy/PickersShortcuts/PickersShortcuts.js +10 -2
  51. package/legacy/StaticDatePicker/StaticDatePicker.js +1 -1
  52. package/legacy/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  53. package/legacy/TimeField/TimeField.js +1 -1
  54. package/legacy/YearCalendar/YearCalendar.js +28 -11
  55. package/legacy/index.js +1 -1
  56. package/legacy/internals/hooks/useField/useFieldState.js +0 -1
  57. package/legacy/internals/hooks/usePicker/usePickerValue.js +24 -2
  58. package/legacy/internals/utils/date-utils.js +0 -9
  59. package/legacy/internals/utils/getDefaultReferenceDate.js +2 -3
  60. package/legacy/locales/elGR.js +93 -0
  61. package/legacy/locales/index.js +1 -0
  62. package/locales/elGR.d.ts +53 -0
  63. package/locales/elGR.js +57 -0
  64. package/locales/index.d.ts +1 -0
  65. package/locales/index.js +1 -0
  66. package/modern/DateCalendar/DateCalendar.js +16 -6
  67. package/modern/DateCalendar/useCalendarState.js +36 -14
  68. package/modern/DateField/DateField.js +1 -1
  69. package/modern/DatePicker/DatePicker.js +1 -1
  70. package/modern/DateTimeField/DateTimeField.js +1 -1
  71. package/modern/DateTimePicker/DateTimePicker.js +1 -1
  72. package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -1
  73. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  74. package/modern/MobileDatePicker/MobileDatePicker.js +1 -1
  75. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  76. package/modern/MonthCalendar/MonthCalendar.js +28 -11
  77. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  78. package/modern/PickersLayout/PickersLayout.js +1 -0
  79. package/modern/PickersLayout/usePickerLayout.js +4 -3
  80. package/modern/PickersShortcuts/PickersShortcuts.js +10 -2
  81. package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
  82. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  83. package/modern/TimeField/TimeField.js +1 -1
  84. package/modern/YearCalendar/YearCalendar.js +26 -9
  85. package/modern/index.js +1 -1
  86. package/modern/internals/hooks/useField/useFieldState.js +0 -1
  87. package/modern/internals/hooks/usePicker/usePickerValue.js +22 -2
  88. package/modern/internals/utils/date-utils.js +0 -9
  89. package/modern/internals/utils/getDefaultReferenceDate.js +2 -3
  90. package/modern/locales/elGR.js +57 -0
  91. package/modern/locales/index.js +1 -0
  92. package/node/DateCalendar/DateCalendar.js +16 -6
  93. package/node/DateCalendar/useCalendarState.js +36 -14
  94. package/node/DateField/DateField.js +1 -1
  95. package/node/DatePicker/DatePicker.js +1 -1
  96. package/node/DateTimeField/DateTimeField.js +1 -1
  97. package/node/DateTimePicker/DateTimePicker.js +1 -1
  98. package/node/DesktopDatePicker/DesktopDatePicker.js +1 -1
  99. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  100. package/node/MobileDatePicker/MobileDatePicker.js +1 -1
  101. package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  102. package/node/MonthCalendar/MonthCalendar.js +28 -11
  103. package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  104. package/node/PickersLayout/PickersLayout.js +1 -0
  105. package/node/PickersLayout/usePickerLayout.js +4 -3
  106. package/node/PickersShortcuts/PickersShortcuts.js +10 -2
  107. package/node/StaticDatePicker/StaticDatePicker.js +1 -1
  108. package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  109. package/node/TimeField/TimeField.js +1 -1
  110. package/node/YearCalendar/YearCalendar.js +26 -9
  111. package/node/index.js +1 -1
  112. package/node/internals/hooks/useField/useFieldState.js +0 -1
  113. package/node/internals/hooks/usePicker/usePickerValue.js +22 -2
  114. package/node/internals/utils/date-utils.js +1 -11
  115. package/node/internals/utils/getDefaultReferenceDate.js +3 -3
  116. package/node/locales/elGR.js +64 -0
  117. package/node/locales/index.js +11 -0
  118. package/package.json +1 -1
@@ -7,15 +7,25 @@ export interface PickersShortcutsItem<TValue> {
7
7
  label: string;
8
8
  getValue: (params: PickersShortcutsItemGetValueParams<TValue>) => TValue;
9
9
  }
10
- export interface PickersShortcutsProps<TValue> extends Omit<ListProps, 'onChange'> {
10
+ export type PickerShortcutChangeImportance = 'set' | 'accept';
11
+ export interface ExportedPickersShortcutProps<TValue> extends Omit<ListProps, 'onChange'> {
11
12
  /**
12
13
  * Ordered array of shortcuts to display.
13
14
  * If empty, does not display the shortcuts.
14
15
  * @default `[]`
15
16
  */
16
17
  items?: PickersShortcutsItem<TValue>[];
18
+ /**
19
+ * Importance of the change when picking a shortcut:
20
+ * - "accept": fires `onChange`, fires `onAccept` and closes the picker.
21
+ * - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
22
+ * @default "accept"
23
+ */
24
+ changeImportance?: PickerShortcutChangeImportance;
25
+ }
26
+ export interface PickersShortcutsProps<TValue> extends ExportedPickersShortcutProps<TValue> {
17
27
  isLandscape: boolean;
18
- onChange: (newValue: TValue) => void;
28
+ onChange: (newValue: TValue, changeImportance?: PickerShortcutChangeImportance) => void;
19
29
  isValid: (value: TValue) => boolean;
20
30
  }
21
31
  declare function PickersShortcuts<TValue>(props: PickersShortcutsProps<TValue>): React.JSX.Element | null;
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["items", "isLandscape", "onChange", "isValid"];
3
+ const _excluded = ["items", "changeImportance", "isLandscape", "onChange", "isValid"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import List from '@mui/material/List';
@@ -11,6 +11,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
11
  function PickersShortcuts(props) {
12
12
  const {
13
13
  items,
14
+ changeImportance,
14
15
  onChange,
15
16
  isValid
16
17
  } = props,
@@ -25,7 +26,7 @@ function PickersShortcuts(props) {
25
26
  return {
26
27
  label: item.label,
27
28
  onClick: () => {
28
- onChange(newValue);
29
+ onChange(newValue, changeImportance);
29
30
  },
30
31
  disabled: !isValid(newValue)
31
32
  };
@@ -50,6 +51,13 @@ process.env.NODE_ENV !== "production" ? PickersShortcuts.propTypes = {
50
51
  // | These PropTypes are generated from the TypeScript type definitions |
51
52
  // | To update them edit the TypeScript types and run "yarn proptypes" |
52
53
  // ----------------------------------------------------------------------
54
+ /**
55
+ * Importance of the change when picking a shortcut:
56
+ * - "accept": fires `onChange`, fires `onAccept` and closes the picker.
57
+ * - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
58
+ * @default "accept"
59
+ */
60
+ changeImportance: PropTypes.oneOf(['accept', 'set']),
53
61
  className: PropTypes.string,
54
62
  /**
55
63
  * If `true`, compact vertical padding designed for keyboard and mouse input is used for
@@ -1,2 +1,2 @@
1
1
  export { PickersShortcuts } from './PickersShortcuts';
2
- export type { PickersShortcutsProps, PickersShortcutsItem } from './PickersShortcuts';
2
+ export type { PickersShortcutsProps, PickersShortcutsItem, PickerShortcutChangeImportance, } from './PickersShortcuts';
@@ -74,7 +74,7 @@ StaticDatePicker.propTypes = {
74
74
  */
75
75
  dayOfWeekFormatter: PropTypes.func,
76
76
  /**
77
- * Default calendar month displayed when `value={null}`.
77
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
78
78
  */
79
79
  defaultCalendarMonth: PropTypes.any,
80
80
  /**
@@ -94,7 +94,7 @@ StaticDateTimePicker.propTypes = {
94
94
  */
95
95
  dayOfWeekFormatter: PropTypes.func,
96
96
  /**
97
- * Default calendar month displayed when `value={null}`.
97
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
98
98
  */
99
99
  defaultCalendarMonth: PropTypes.any,
100
100
  /**
@@ -247,7 +247,7 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
247
247
  */
248
248
  readOnly: PropTypes.bool,
249
249
  /**
250
- * The date used to generate a part of the date-time that is not present in the format when both `value` and `defaultValue` are not present.
250
+ * The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty.
251
251
  * For example, on time fields it will be used to determine the date to set.
252
252
  * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
253
253
  */
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["autoFocus", "className", "value", "defaultValue", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "readOnly", "shouldDisableYear", "disableHighlightToday", "onYearFocus", "hasFocus", "onFocusedViewChange", "yearsPerRow"];
3
+ const _excluded = ["autoFocus", "className", "value", "defaultValue", "referenceDate", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "readOnly", "shouldDisableYear", "disableHighlightToday", "onYearFocus", "hasFocus", "onFocusedViewChange", "yearsPerRow"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
@@ -11,6 +11,8 @@ import { PickersYear } from './PickersYear';
11
11
  import { useUtils, useNow, useDefaultDates } from '../internals/hooks/useUtils';
12
12
  import { getYearCalendarUtilityClass } from './yearCalendarClasses';
13
13
  import { applyDefaultDate } from '../internals/utils/date-utils';
14
+ import { singleItemValueManager } from '../internals/utils/valueManagers';
15
+ import { SECTION_TYPE_GRANULARITY } from '../internals/utils/getDefaultReferenceDate';
14
16
  import { jsx as _jsx } from "react/jsx-runtime";
15
17
  const useUtilityClasses = ownerState => {
16
18
  const {
@@ -60,6 +62,7 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
60
62
  className,
61
63
  value: valueProp,
62
64
  defaultValue,
65
+ referenceDate: referenceDateProp,
63
66
  disabled,
64
67
  disableFuture,
65
68
  disablePast,
@@ -83,7 +86,15 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
83
86
  controlled: valueProp,
84
87
  default: defaultValue != null ? defaultValue : null
85
88
  });
86
- const selectedDateOrStartOfYear = React.useMemo(() => value != null ? value : utils.startOfYear(now), [now, utils, value]);
89
+ const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
90
+ value,
91
+ utils,
92
+ props,
93
+ referenceDate: referenceDateProp,
94
+ granularity: SECTION_TYPE_GRANULARITY.year
95
+ }), [] // eslint-disable-line react-hooks/exhaustive-deps
96
+ );
97
+
87
98
  const todayYear = React.useMemo(() => utils.getYear(now), [utils, now]);
88
99
  const selectedYear = React.useMemo(() => {
89
100
  if (value != null) {
@@ -92,8 +103,8 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
92
103
  if (disableHighlightToday) {
93
104
  return null;
94
105
  }
95
- return utils.getYear(now);
96
- }, [now, value, utils, disableHighlightToday]);
106
+ return utils.getYear(referenceDate);
107
+ }, [value, utils, disableHighlightToday, referenceDate]);
97
108
  const [focusedYear, setFocusedYear] = React.useState(() => selectedYear || todayYear);
98
109
  const [internalHasFocus, setInternalHasFocus] = useControlled({
99
110
  name: 'YearCalendar',
@@ -120,21 +131,22 @@ export const YearCalendar = /*#__PURE__*/React.forwardRef(function YearCalendar(
120
131
  if (maxDate && utils.isAfterYear(dateToValidate, maxDate)) {
121
132
  return true;
122
133
  }
123
- if (shouldDisableYear && shouldDisableYear(dateToValidate)) {
124
- return true;
134
+ if (!shouldDisableYear) {
135
+ return false;
125
136
  }
126
- return false;
137
+ const yearToValidate = utils.startOfYear(dateToValidate);
138
+ return shouldDisableYear(yearToValidate);
127
139
  }, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableYear, utils]);
128
140
  const handleYearSelection = useEventCallback((event, year) => {
129
141
  if (readOnly) {
130
142
  return;
131
143
  }
132
- const newDate = utils.setYear(selectedDateOrStartOfYear, year);
144
+ const newDate = utils.setYear(value != null ? value : referenceDate, year);
133
145
  setValue(newDate);
134
146
  onChange == null ? void 0 : onChange(newDate);
135
147
  });
136
148
  const focusYear = useEventCallback(year => {
137
- if (!isYearDisabled(utils.setYear(selectedDateOrStartOfYear, year))) {
149
+ if (!isYearDisabled(utils.setYear(value != null ? value : referenceDate, year))) {
138
150
  setFocusedYear(year);
139
151
  changeHasFocus(true);
140
152
  onYearFocus == null ? void 0 : onYearFocus(year);
@@ -281,6 +293,11 @@ process.env.NODE_ENV !== "production" ? YearCalendar.propTypes = {
281
293
  * If `true` picker is readonly
282
294
  */
283
295
  readOnly: PropTypes.bool,
296
+ /**
297
+ * The date used to generate the new value when both `value` and `defaultValue` are empty.
298
+ * @default The closest valid year using the validation props, except callbacks such as `shouldDisableDate`.
299
+ */
300
+ referenceDate: PropTypes.any,
284
301
  /**
285
302
  * Disable specific year.
286
303
  * @template TDate
@@ -35,6 +35,11 @@ export interface YearCalendarProps<TDate> extends ExportedYearCalendarProps, Yea
35
35
  * Used when the component is not controlled.
36
36
  */
37
37
  defaultValue?: TDate | null;
38
+ /**
39
+ * The date used to generate the new value when both `value` and `defaultValue` are empty.
40
+ * @default The closest valid year using the validation props, except callbacks such as `shouldDisableDate`.
41
+ */
42
+ referenceDate?: TDate;
38
43
  /**
39
44
  * Callback fired when the value changes.
40
45
  * @template TDate
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v6.7.0
2
+ * @mui/x-date-pickers v6.8.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -22,7 +22,7 @@ export interface UseFieldInternalProps<TValue, TDate, TSection extends FieldSect
22
22
  */
23
23
  defaultValue?: TValue;
24
24
  /**
25
- * The date used to generate a part of the date-time that is not present in the format when both `value` and `defaultValue` are not present.
25
+ * The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty.
26
26
  * For example, on time fields it will be used to determine the date to set.
27
27
  * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
28
28
  */
@@ -48,7 +48,6 @@ export const useFieldState = params => {
48
48
  const referenceValue = valueManager.getInitialReferenceValue({
49
49
  referenceDate: referenceDateProp,
50
50
  value: valueFromTheOutside,
51
- valueType,
52
51
  utils,
53
52
  props: internalProps,
54
53
  granularity
@@ -38,6 +38,14 @@ const shouldPublishValue = params => {
38
38
  }
39
39
  return hasChanged(dateState.lastPublishedValue);
40
40
  }
41
+ if (action.name === 'setValueFromShortcut' && action.changeImportance === 'accept') {
42
+ // On the first view,
43
+ // If the value is not controlled, then clicking on any value (including the one equal to `defaultValue`) should call `onChange`
44
+ if (isCurrentValueTheDefaultValue) {
45
+ return true;
46
+ }
47
+ return hasChanged(dateState.lastPublishedValue);
48
+ }
41
49
  return false;
42
50
  };
43
51
 
@@ -71,6 +79,9 @@ const shouldCommitValue = params => {
71
79
  }
72
80
  return hasChanged(dateState.lastCommittedValue);
73
81
  }
82
+ if (action.name === 'setValueFromShortcut') {
83
+ return action.changeImportance === 'accept' && hasChanged(dateState.lastCommittedValue);
84
+ }
74
85
  return false;
75
86
  };
76
87
 
@@ -88,6 +99,9 @@ const shouldClosePicker = params => {
88
99
  if (action.name === 'setValueFromView') {
89
100
  return action.selectionState === 'finish' && closeOnSelect;
90
101
  }
102
+ if (action.name === 'setValueFromShortcut') {
103
+ return action.changeImportance === 'accept';
104
+ }
91
105
  return false;
92
106
  };
93
107
 
@@ -254,7 +268,12 @@ export const usePickerValue = ({
254
268
  value: newValue,
255
269
  selectionState
256
270
  }));
257
- const handleChangeField = useEventCallback((newValue, context) => updateDate({
271
+ const handleSelectShortcut = useEventCallback((newValue, changeImportance) => updateDate({
272
+ name: 'setValueFromShortcut',
273
+ value: newValue,
274
+ changeImportance: changeImportance != null ? changeImportance : 'accept'
275
+ }));
276
+ const handleChangeFromField = useEventCallback((newValue, context) => updateDate({
258
277
  name: 'setValueFromField',
259
278
  value: newValue,
260
279
  context
@@ -274,7 +293,7 @@ export const usePickerValue = ({
274
293
  };
275
294
  const fieldResponse = {
276
295
  value: dateState.draft,
277
- onChange: handleChangeField,
296
+ onChange: handleChangeFromField,
278
297
  selectedSections,
279
298
  onSelectedSectionsChange: handleFieldSelectedSectionsChange
280
299
  };
@@ -299,6 +318,7 @@ export const usePickerValue = ({
299
318
  const layoutResponse = _extends({}, actions, {
300
319
  value: viewValue,
301
320
  onChange: handleChange,
321
+ onSelectShortcut: handleSelectShortcut,
302
322
  isValid
303
323
  });
304
324
  return {
@@ -4,6 +4,7 @@ import { UseFieldValidationProps } from '../useField/useField.types';
4
4
  import { WrapperVariant } from '../../models/common';
5
5
  import { FieldSection, FieldSelectedSections, FieldValueType, MuiPickersAdapter } from '../../../models';
6
6
  import { GetDefaultReferenceDateProps } from '../../utils/getDefaultReferenceDate';
7
+ import { PickerShortcutChangeImportance } from '../../../PickersShortcuts';
7
8
  export interface PickerValueManager<TValue, TDate, TError> {
8
9
  /**
9
10
  * Determines if two values are equal.
@@ -34,7 +35,6 @@ export interface PickerValueManager<TValue, TDate, TError> {
34
35
  * @param {TValue} params.value The value provided by the user.
35
36
  * @param {GetDefaultReferenceDateProps<TDate>} params.props The validation props needed to compute the reference value.
36
37
  * @param {MuiPickersAdapter<TDate>} params.utils The adapter.
37
- * @param {FieldValueType} params.valueType The type of the value being edited.
38
38
  * @param {granularity} params.granularity The granularity of the selection possible on this component.
39
39
  * @returns {TValue} The reference value to use for non-provided dates.
40
40
  */
@@ -43,7 +43,6 @@ export interface PickerValueManager<TValue, TDate, TError> {
43
43
  value: TValue;
44
44
  props: GetDefaultReferenceDateProps<TDate>;
45
45
  utils: MuiPickersAdapter<TDate>;
46
- valueType: FieldValueType;
47
46
  granularity: number;
48
47
  }) => TValue;
49
48
  /**
@@ -151,6 +150,10 @@ export type PickerValueUpdateAction<TValue, TError> = {
151
150
  name: 'setValueFromAction';
152
151
  value: TValue;
153
152
  pickerAction: 'accept' | 'today' | 'cancel' | 'dismiss' | 'clear';
153
+ } | {
154
+ name: 'setValueFromShortcut';
155
+ value: TValue;
156
+ changeImportance: PickerShortcutChangeImportance;
154
157
  };
155
158
  /**
156
159
  * Props used to handle the value that are common to all pickers.
@@ -254,6 +257,7 @@ export interface UsePickerValueViewsResponse<TValue> {
254
257
  export interface UsePickerValueLayoutResponse<TValue> extends UsePickerValueActions {
255
258
  value: TValue;
256
259
  onChange: (newValue: TValue) => void;
260
+ onSelectShortcut: (newValue: TValue, changeImportance?: PickerShortcutChangeImportance) => void;
257
261
  isValid: (value: TValue) => boolean;
258
262
  }
259
263
  export interface UsePickerValueResponse<TValue, TSection extends FieldSection, TError> {
@@ -10,13 +10,12 @@ interface FindClosestDateParams<TDate> {
10
10
  utils: MuiPickersAdapter<TDate>;
11
11
  }
12
12
  export declare const findClosestEnabledDate: <TDate>({ date, disableFuture, disablePast, maxDate, minDate, isDateDisabled, utils, }: FindClosestDateParams<TDate>) => NonNullable<TDate> | null;
13
- export declare const clamp: <TDate>(utils: MuiPickersAdapter<TDate, any>, value: TDate, minDate: TDate, maxDate: TDate) => TDate;
14
13
  export declare const replaceInvalidDateByNull: <TDate>(utils: MuiPickersAdapter<TDate, any>, value: TDate | null) => NonNullable<TDate> | null;
15
14
  export declare const applyDefaultDate: <TDate>(utils: MuiPickersAdapter<TDate, any>, value: TDate | null | undefined, defaultValue: TDate) => TDate;
16
15
  export declare const areDatesEqual: <TDate>(utils: MuiPickersAdapter<TDate, any>, a: TDate, b: TDate) => boolean;
17
16
  export declare const getMonthsInYear: <TDate>(utils: MuiPickersAdapter<TDate, any>, year: TDate) => TDate[];
18
17
  export declare const mergeDateAndTime: <TDate>(utils: MuiPickersAdapter<TDate, any>, dateParam: TDate, timeParam: TDate) => TDate;
19
- export declare const getTodayDate: <TDate>(utils: MuiPickersAdapter<TDate, any>, valueType: FieldValueType) => TDate;
18
+ export declare const getTodayDate: <TDate>(utils: MuiPickersAdapter<TDate, any>, valueType?: FieldValueType) => TDate;
20
19
  export declare const isDatePickerView: (view: DateOrTimeViewWithMeridiem) => view is DateView;
21
20
  export declare const resolveDateFormat: (utils: MuiPickersAdapter<any>, { format, views }: {
22
21
  format?: string | undefined;
@@ -49,15 +49,6 @@ export const findClosestEnabledDate = ({
49
49
  }
50
50
  return null;
51
51
  };
52
- export const clamp = (utils, value, minDate, maxDate) => {
53
- if (utils.isBefore(value, minDate)) {
54
- return minDate;
55
- }
56
- if (utils.isAfter(value, maxDate)) {
57
- return maxDate;
58
- }
59
- return value;
60
- };
61
52
  export const replaceInvalidDateByNull = (utils, value) => value == null || !utils.isValid(value) ? null : value;
62
53
  export const applyDefaultDate = (utils, value, defaultValue) => {
63
54
  if (value == null || !utils.isValid(value)) {
@@ -1,4 +1,4 @@
1
- import { FieldSection, FieldValueType, MuiPickersAdapter } from '../../models';
1
+ import { FieldSection, MuiPickersAdapter } from '../../models';
2
2
  export interface GetDefaultReferenceDateProps<TDate> {
3
3
  maxDate?: TDate;
4
4
  minDate?: TDate;
@@ -6,10 +6,18 @@ export interface GetDefaultReferenceDateProps<TDate> {
6
6
  maxTime?: TDate;
7
7
  disableIgnoringDatePartForTimeValidation?: boolean;
8
8
  }
9
+ export declare const SECTION_TYPE_GRANULARITY: {
10
+ year: number;
11
+ month: number;
12
+ day: number;
13
+ hours: number;
14
+ minutes: number;
15
+ seconds: number;
16
+ milliseconds: number;
17
+ };
9
18
  export declare const getSectionTypeGranularity: (sections: FieldSection[]) => number;
10
- export declare const getDefaultReferenceDate: <TDate>({ props, utils, valueType, granularity, }: {
19
+ export declare const getDefaultReferenceDate: <TDate>({ props, utils, granularity, }: {
11
20
  props: GetDefaultReferenceDateProps<TDate>;
12
21
  utils: MuiPickersAdapter<TDate, any>;
13
- valueType: FieldValueType;
14
22
  granularity: number;
15
23
  }) => TDate;
@@ -1,6 +1,6 @@
1
1
  import { createIsAfterIgnoreDatePart } from './time-utils';
2
2
  import { mergeDateAndTime, getTodayDate } from './date-utils';
3
- const SECTION_TYPE_GRANULARITY = {
3
+ export const SECTION_TYPE_GRANULARITY = {
4
4
  year: 1,
5
5
  month: 2,
6
6
  day: 3,
@@ -40,11 +40,10 @@ const roundDate = (utils, granularity, date) => {
40
40
  export const getDefaultReferenceDate = ({
41
41
  props,
42
42
  utils,
43
- valueType,
44
43
  granularity
45
44
  }) => {
46
45
  var _props$disableIgnorin;
47
- let referenceDate = roundDate(utils, granularity, getTodayDate(utils, valueType));
46
+ let referenceDate = roundDate(utils, granularity, getTodayDate(utils));
48
47
  if (props.minDate != null && utils.isAfterDay(props.minDate, referenceDate)) {
49
48
  referenceDate = roundDate(utils, granularity, props.minDate);
50
49
  }
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
- var _excluded = ["autoFocus", "onViewChange", "value", "defaultValue", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday", "focusedView", "onFocusedViewChange", "showDaysOutsideCurrentMonth", "fixedWeekNumber", "dayOfWeekFormatter", "components", "componentsProps", "slots", "slotProps", "loading", "renderLoading", "displayWeekNumber", "yearsPerRow", "monthsPerRow"];
4
+ var _excluded = ["autoFocus", "onViewChange", "value", "defaultValue", "referenceDate", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday", "focusedView", "onFocusedViewChange", "showDaysOutsideCurrentMonth", "fixedWeekNumber", "dayOfWeekFormatter", "components", "componentsProps", "slots", "slotProps", "loading", "renderLoading", "displayWeekNumber", "yearsPerRow", "monthsPerRow"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import clsx from 'clsx';
@@ -88,6 +88,7 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
88
88
  onViewChange = props.onViewChange,
89
89
  valueProp = props.value,
90
90
  defaultValue = props.defaultValue,
91
+ referenceDateProp = props.referenceDate,
91
92
  disableFuture = props.disableFuture,
92
93
  disablePast = props.disablePast,
93
94
  defaultCalendarMonth = props.defaultCalendarMonth,
@@ -154,6 +155,7 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
154
155
  var _useCalendarState = useCalendarState({
155
156
  value: value,
156
157
  defaultCalendarMonth: defaultCalendarMonth,
158
+ referenceDate: referenceDateProp,
157
159
  reduceAnimations: reduceAnimations,
158
160
  onMonthChange: onMonthChange,
159
161
  minDate: minDate,
@@ -162,6 +164,7 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
162
164
  disablePast: disablePast,
163
165
  disableFuture: disableFuture
164
166
  }),
167
+ referenceDate = _useCalendarState.referenceDate,
165
168
  calendarState = _useCalendarState.calendarState,
166
169
  changeFocusedDay = _useCalendarState.changeFocusedDay,
167
170
  changeMonth = _useCalendarState.changeMonth,
@@ -211,9 +214,9 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
211
214
  changeFocusedDay(closestEnabledDate, true);
212
215
  });
213
216
  var handleSelectedDayChange = useEventCallback(function (day) {
214
- if (value && day) {
217
+ if (day) {
215
218
  // If there is a date already selected, then we want to keep its time
216
- return handleValueChange(mergeDateAndTime(utils, day, value), 'finish');
219
+ return handleValueChange(mergeDateAndTime(utils, day, value != null ? value : referenceDate), 'finish');
217
220
  }
218
221
  return handleValueChange(day, 'finish');
219
222
  });
@@ -296,7 +299,8 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
296
299
  onFocusedViewChange: function onFocusedViewChange(isViewFocused) {
297
300
  return setFocusedView('year', isViewFocused);
298
301
  },
299
- yearsPerRow: yearsPerRow
302
+ yearsPerRow: yearsPerRow,
303
+ referenceDate: referenceDate
300
304
  })), view === 'month' && /*#__PURE__*/_jsx(MonthCalendar, _extends({}, baseDateValidationProps, commonViewProps, {
301
305
  hasFocus: hasFocus,
302
306
  className: className,
@@ -306,7 +310,8 @@ export var DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(in
306
310
  onFocusedViewChange: function onFocusedViewChange(isViewFocused) {
307
311
  return setFocusedView('month', isViewFocused);
308
312
  },
309
- monthsPerRow: monthsPerRow
313
+ monthsPerRow: monthsPerRow,
314
+ referenceDate: referenceDate
310
315
  })), view === 'day' && /*#__PURE__*/_jsx(DayCalendar, _extends({}, calendarState, baseDateValidationProps, commonViewProps, {
311
316
  onMonthSwitchingAnimationEnd: onMonthSwitchingAnimationEnd,
312
317
  onFocusedDayChange: changeFocusedDay,
@@ -370,7 +375,7 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
370
375
  */
371
376
  dayOfWeekFormatter: PropTypes.func,
372
377
  /**
373
- * Default calendar month displayed when `value={null}`.
378
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
374
379
  */
375
380
  defaultCalendarMonth: PropTypes.any,
376
381
  /**
@@ -479,6 +484,11 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
479
484
  * @default typeof navigator !== 'undefined' && /(android)/i.test(navigator.userAgent)
480
485
  */
481
486
  reduceAnimations: PropTypes.bool,
487
+ /**
488
+ * The date used to generate the new value when both `value` and `defaultValue` are empty.
489
+ * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`.
490
+ */
491
+ referenceDate: PropTypes.any,
482
492
  /**
483
493
  * Component displaying when passed `loading` true.
484
494
  * @returns {React.ReactNode} The node to render when loading.
@@ -4,7 +4,8 @@ import * as React from 'react';
4
4
  import useEventCallback from '@mui/utils/useEventCallback';
5
5
  import { useIsDateDisabled } from './useIsDateDisabled';
6
6
  import { useUtils, useNow } from '../internals/hooks/useUtils';
7
- import { clamp } from '../internals/utils/date-utils';
7
+ import { singleItemValueManager } from '../internals/utils/valueManagers';
8
+ import { SECTION_TYPE_GRANULARITY } from '../internals/utils/getDefaultReferenceDate';
8
9
  export var createCalendarStateReducer = function createCalendarStateReducer(reduceAnimations, disableSwitchToMonthOnDayFocus, utils) {
9
10
  return function (state, action) {
10
11
  switch (action.type) {
@@ -36,26 +37,44 @@ export var createCalendarStateReducer = function createCalendarStateReducer(redu
36
37
  }
37
38
  };
38
39
  };
39
- export var useCalendarState = function useCalendarState(_ref) {
40
- var _ref2;
41
- var value = _ref.value,
42
- defaultCalendarMonth = _ref.defaultCalendarMonth,
43
- disableFuture = _ref.disableFuture,
44
- disablePast = _ref.disablePast,
45
- _ref$disableSwitchToM = _ref.disableSwitchToMonthOnDayFocus,
46
- disableSwitchToMonthOnDayFocus = _ref$disableSwitchToM === void 0 ? false : _ref$disableSwitchToM,
47
- maxDate = _ref.maxDate,
48
- minDate = _ref.minDate,
49
- onMonthChange = _ref.onMonthChange,
50
- reduceAnimations = _ref.reduceAnimations,
51
- shouldDisableDate = _ref.shouldDisableDate;
40
+ export var useCalendarState = function useCalendarState(params) {
41
+ var value = params.value,
42
+ referenceDateProp = params.referenceDate,
43
+ defaultCalendarMonth = params.defaultCalendarMonth,
44
+ disableFuture = params.disableFuture,
45
+ disablePast = params.disablePast,
46
+ _params$disableSwitch = params.disableSwitchToMonthOnDayFocus,
47
+ disableSwitchToMonthOnDayFocus = _params$disableSwitch === void 0 ? false : _params$disableSwitch,
48
+ maxDate = params.maxDate,
49
+ minDate = params.minDate,
50
+ onMonthChange = params.onMonthChange,
51
+ reduceAnimations = params.reduceAnimations,
52
+ shouldDisableDate = params.shouldDisableDate;
52
53
  var now = useNow();
53
54
  var utils = useUtils();
54
55
  var reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations), disableSwitchToMonthOnDayFocus, utils)).current;
56
+ var referenceDate = React.useMemo(function () {
57
+ var externalReferenceDate = null;
58
+ if (referenceDateProp) {
59
+ externalReferenceDate = referenceDateProp;
60
+ } else if (defaultCalendarMonth) {
61
+ // For `defaultCalendarMonth`, we just want to keep the month and the year to avoid a behavior change.
62
+ externalReferenceDate = utils.startOfMonth(defaultCalendarMonth);
63
+ }
64
+ return singleItemValueManager.getInitialReferenceValue({
65
+ value: value,
66
+ utils: utils,
67
+ props: params,
68
+ referenceDate: externalReferenceDate,
69
+ granularity: SECTION_TYPE_GRANULARITY.day
70
+ });
71
+ }, [] // eslint-disable-line react-hooks/exhaustive-deps
72
+ );
73
+
55
74
  var _React$useReducer = React.useReducer(reducerFn, {
56
75
  isMonthSwitchingAnimating: false,
57
76
  focusedDay: value || now,
58
- currentMonth: utils.startOfMonth((_ref2 = value != null ? value : defaultCalendarMonth) != null ? _ref2 : clamp(utils, now, minDate, maxDate)),
77
+ currentMonth: utils.startOfMonth(referenceDate),
59
78
  slideDirection: 'left'
60
79
  }),
61
80
  _React$useReducer2 = _slicedToArray(_React$useReducer, 2),
@@ -101,6 +120,7 @@ export var useCalendarState = function useCalendarState(_ref) {
101
120
  }
102
121
  });
103
122
  return {
123
+ referenceDate: referenceDate,
104
124
  calendarState: calendarState,
105
125
  changeMonth: changeMonth,
106
126
  changeFocusedDay: changeFocusedDay,
@@ -224,7 +224,7 @@ process.env.NODE_ENV !== "production" ? DateField.propTypes = {
224
224
  */
225
225
  readOnly: PropTypes.bool,
226
226
  /**
227
- * The date used to generate a part of the date-time that is not present in the format when both `value` and `defaultValue` are not present.
227
+ * The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty.
228
228
  * For example, on time fields it will be used to determine the date to set.
229
229
  * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
230
230
  */
@@ -72,7 +72,7 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
72
72
  */
73
73
  dayOfWeekFormatter: PropTypes.func,
74
74
  /**
75
- * Default calendar month displayed when `value={null}`.
75
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
76
76
  */
77
77
  defaultCalendarMonth: PropTypes.any,
78
78
  /**
@@ -257,7 +257,7 @@ process.env.NODE_ENV !== "production" ? DateTimeField.propTypes = {
257
257
  */
258
258
  readOnly: PropTypes.bool,
259
259
  /**
260
- * The date used to generate a part of the date-time that is not present in the format when both `value` and `defaultValue` are not present.
260
+ * The date used to generate a part of the new value that is not present in the format when both `value` and `defaultValue` are empty.
261
261
  * For example, on time fields it will be used to determine the date to set.
262
262
  * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
263
263
  */
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
82
82
  */
83
83
  dayOfWeekFormatter: PropTypes.func,
84
84
  /**
85
- * Default calendar month displayed when `value={null}`.
85
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
86
86
  */
87
87
  defaultCalendarMonth: PropTypes.any,
88
88
  /**
@@ -96,7 +96,7 @@ DesktopDatePicker.propTypes = {
96
96
  */
97
97
  dayOfWeekFormatter: PropTypes.func,
98
98
  /**
99
- * Default calendar month displayed when `value={null}`.
99
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
100
100
  */
101
101
  defaultCalendarMonth: PropTypes.any,
102
102
  /**