@mui/x-date-pickers 6.6.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 (194) hide show
  1. package/AdapterDateFns/AdapterDateFns.js +20 -19
  2. package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
  3. package/AdapterDayjs/AdapterDayjs.js +12 -11
  4. package/AdapterLuxon/AdapterLuxon.js +20 -19
  5. package/AdapterMoment/AdapterMoment.js +12 -11
  6. package/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
  7. package/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
  8. package/CHANGELOG.md +147 -13
  9. package/DateCalendar/DateCalendar.js +16 -6
  10. package/DateCalendar/DateCalendar.types.d.ts +6 -1
  11. package/DateCalendar/useCalendarState.d.ts +3 -2
  12. package/DateCalendar/useCalendarState.js +36 -15
  13. package/DateField/DateField.js +1 -1
  14. package/DatePicker/DatePicker.js +1 -1
  15. package/DatePicker/DatePickerToolbar.js +6 -15
  16. package/DatePicker/shared.d.ts +1 -5
  17. package/DatePicker/shared.js +1 -16
  18. package/DateTimeField/DateTimeField.js +1 -1
  19. package/DateTimePicker/DateTimePicker.js +1 -1
  20. package/DesktopDatePicker/DesktopDatePicker.js +4 -3
  21. package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -2
  22. package/DesktopTimePicker/DesktopTimePicker.js +5 -1
  23. package/LocalizationProvider/LocalizationProvider.js +1 -0
  24. package/MobileDatePicker/MobileDatePicker.js +4 -3
  25. package/MobileDateTimePicker/MobileDateTimePicker.js +6 -2
  26. package/MobileTimePicker/MobileTimePicker.js +5 -1
  27. package/MonthCalendar/MonthCalendar.js +28 -11
  28. package/MonthCalendar/MonthCalendar.types.d.ts +5 -0
  29. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  30. package/PickersLayout/PickersLayout.js +1 -0
  31. package/PickersLayout/usePickerLayout.js +4 -3
  32. package/PickersShortcuts/PickersShortcuts.d.ts +12 -2
  33. package/PickersShortcuts/PickersShortcuts.js +10 -2
  34. package/PickersShortcuts/index.d.ts +1 -1
  35. package/StaticDatePicker/StaticDatePicker.js +1 -1
  36. package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  37. package/TimeField/TimeField.js +1 -1
  38. package/TimePicker/shared.d.ts +1 -1
  39. package/YearCalendar/YearCalendar.js +26 -9
  40. package/YearCalendar/YearCalendar.types.d.ts +5 -0
  41. package/index.js +1 -1
  42. package/internals/hooks/useField/useField.types.d.ts +1 -1
  43. package/internals/hooks/useField/useFieldState.js +0 -1
  44. package/internals/hooks/usePicker/usePickerValue.js +22 -2
  45. package/internals/hooks/usePicker/usePickerValue.types.d.ts +6 -2
  46. package/internals/utils/date-time-utils.d.ts +6 -0
  47. package/internals/utils/date-time-utils.js +41 -0
  48. package/internals/utils/date-utils.d.ts +5 -2
  49. package/internals/utils/date-utils.js +33 -10
  50. package/internals/utils/getDefaultReferenceDate.d.ts +11 -3
  51. package/internals/utils/getDefaultReferenceDate.js +2 -3
  52. package/internals/utils/time-utils.d.ts +6 -1
  53. package/internals/utils/time-utils.js +27 -0
  54. package/internals/utils/validation/extractValidationProps.d.ts +1 -1
  55. package/internals/utils/views.d.ts +2 -3
  56. package/internals/utils/views.js +6 -2
  57. package/legacy/AdapterDateFns/AdapterDateFns.js +20 -19
  58. package/legacy/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
  59. package/legacy/AdapterDayjs/AdapterDayjs.js +12 -11
  60. package/legacy/AdapterLuxon/AdapterLuxon.js +20 -19
  61. package/legacy/AdapterMoment/AdapterMoment.js +12 -11
  62. package/legacy/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
  63. package/legacy/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
  64. package/legacy/DateCalendar/DateCalendar.js +16 -6
  65. package/legacy/DateCalendar/useCalendarState.js +35 -15
  66. package/legacy/DateField/DateField.js +1 -1
  67. package/legacy/DatePicker/DatePicker.js +1 -1
  68. package/legacy/DatePicker/DatePickerToolbar.js +6 -15
  69. package/legacy/DatePicker/shared.js +1 -15
  70. package/legacy/DateTimeField/DateTimeField.js +1 -1
  71. package/legacy/DateTimePicker/DateTimePicker.js +1 -1
  72. package/legacy/DesktopDatePicker/DesktopDatePicker.js +4 -3
  73. package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -2
  74. package/legacy/DesktopTimePicker/DesktopTimePicker.js +5 -1
  75. package/legacy/LocalizationProvider/LocalizationProvider.js +1 -0
  76. package/legacy/MobileDatePicker/MobileDatePicker.js +4 -3
  77. package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -2
  78. package/legacy/MobileTimePicker/MobileTimePicker.js +5 -1
  79. package/legacy/MonthCalendar/MonthCalendar.js +30 -13
  80. package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  81. package/legacy/PickersLayout/PickersLayout.js +1 -0
  82. package/legacy/PickersLayout/usePickerLayout.js +3 -2
  83. package/legacy/PickersShortcuts/PickersShortcuts.js +10 -2
  84. package/legacy/StaticDatePicker/StaticDatePicker.js +1 -1
  85. package/legacy/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  86. package/legacy/TimeField/TimeField.js +1 -1
  87. package/legacy/YearCalendar/YearCalendar.js +28 -11
  88. package/legacy/index.js +1 -1
  89. package/legacy/internals/hooks/useField/useFieldState.js +0 -1
  90. package/legacy/internals/hooks/usePicker/usePickerValue.js +24 -2
  91. package/legacy/internals/utils/date-time-utils.js +39 -0
  92. package/legacy/internals/utils/date-utils.js +31 -9
  93. package/legacy/internals/utils/getDefaultReferenceDate.js +2 -3
  94. package/legacy/internals/utils/time-utils.js +26 -0
  95. package/legacy/internals/utils/views.js +7 -5
  96. package/legacy/locales/deDE.js +2 -2
  97. package/legacy/locales/elGR.js +93 -0
  98. package/legacy/locales/index.js +17 -15
  99. package/legacy/locales/roRO.js +81 -0
  100. package/locales/deDE.js +2 -2
  101. package/locales/elGR.d.ts +53 -0
  102. package/locales/elGR.js +57 -0
  103. package/locales/index.d.ts +17 -15
  104. package/locales/index.js +17 -15
  105. package/locales/roRO.d.ts +53 -0
  106. package/locales/roRO.js +63 -0
  107. package/models/adapters.d.ts +137 -37
  108. package/modern/AdapterDateFns/AdapterDateFns.js +20 -19
  109. package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
  110. package/modern/AdapterDayjs/AdapterDayjs.js +12 -11
  111. package/modern/AdapterLuxon/AdapterLuxon.js +20 -19
  112. package/modern/AdapterMoment/AdapterMoment.js +12 -11
  113. package/modern/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
  114. package/modern/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
  115. package/modern/DateCalendar/DateCalendar.js +16 -6
  116. package/modern/DateCalendar/useCalendarState.js +36 -14
  117. package/modern/DateField/DateField.js +1 -1
  118. package/modern/DatePicker/DatePicker.js +1 -1
  119. package/modern/DatePicker/DatePickerToolbar.js +6 -15
  120. package/modern/DatePicker/shared.js +1 -16
  121. package/modern/DateTimeField/DateTimeField.js +1 -1
  122. package/modern/DateTimePicker/DateTimePicker.js +1 -1
  123. package/modern/DesktopDatePicker/DesktopDatePicker.js +4 -3
  124. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -2
  125. package/modern/DesktopTimePicker/DesktopTimePicker.js +5 -1
  126. package/modern/LocalizationProvider/LocalizationProvider.js +1 -0
  127. package/modern/MobileDatePicker/MobileDatePicker.js +4 -3
  128. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -2
  129. package/modern/MobileTimePicker/MobileTimePicker.js +5 -1
  130. package/modern/MonthCalendar/MonthCalendar.js +28 -11
  131. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  132. package/modern/PickersLayout/PickersLayout.js +1 -0
  133. package/modern/PickersLayout/usePickerLayout.js +4 -3
  134. package/modern/PickersShortcuts/PickersShortcuts.js +10 -2
  135. package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
  136. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  137. package/modern/TimeField/TimeField.js +1 -1
  138. package/modern/YearCalendar/YearCalendar.js +26 -9
  139. package/modern/index.js +1 -1
  140. package/modern/internals/hooks/useField/useFieldState.js +0 -1
  141. package/modern/internals/hooks/usePicker/usePickerValue.js +22 -2
  142. package/modern/internals/utils/date-time-utils.js +41 -0
  143. package/modern/internals/utils/date-utils.js +33 -10
  144. package/modern/internals/utils/getDefaultReferenceDate.js +2 -3
  145. package/modern/internals/utils/time-utils.js +27 -0
  146. package/modern/internals/utils/views.js +6 -2
  147. package/modern/locales/deDE.js +2 -2
  148. package/modern/locales/elGR.js +57 -0
  149. package/modern/locales/index.js +17 -15
  150. package/modern/locales/roRO.js +60 -0
  151. package/node/AdapterDateFns/AdapterDateFns.js +20 -19
  152. package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +17 -16
  153. package/node/AdapterDayjs/AdapterDayjs.js +12 -11
  154. package/node/AdapterLuxon/AdapterLuxon.js +20 -19
  155. package/node/AdapterMoment/AdapterMoment.js +12 -11
  156. package/node/AdapterMomentHijri/AdapterMomentHijri.js +20 -19
  157. package/node/AdapterMomentJalaali/AdapterMomentJalaali.js +20 -19
  158. package/node/DateCalendar/DateCalendar.js +16 -6
  159. package/node/DateCalendar/useCalendarState.js +36 -14
  160. package/node/DateField/DateField.js +1 -1
  161. package/node/DatePicker/DatePicker.js +1 -1
  162. package/node/DatePicker/DatePickerToolbar.js +6 -15
  163. package/node/DatePicker/shared.js +0 -17
  164. package/node/DateTimeField/DateTimeField.js +1 -1
  165. package/node/DateTimePicker/DateTimePicker.js +1 -1
  166. package/node/DesktopDatePicker/DesktopDatePicker.js +3 -2
  167. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +8 -4
  168. package/node/DesktopTimePicker/DesktopTimePicker.js +7 -3
  169. package/node/LocalizationProvider/LocalizationProvider.js +1 -0
  170. package/node/MobileDatePicker/MobileDatePicker.js +3 -2
  171. package/node/MobileDateTimePicker/MobileDateTimePicker.js +8 -4
  172. package/node/MobileTimePicker/MobileTimePicker.js +7 -3
  173. package/node/MonthCalendar/MonthCalendar.js +28 -11
  174. package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +1 -1
  175. package/node/PickersLayout/PickersLayout.js +1 -0
  176. package/node/PickersLayout/usePickerLayout.js +4 -3
  177. package/node/PickersShortcuts/PickersShortcuts.js +10 -2
  178. package/node/StaticDatePicker/StaticDatePicker.js +1 -1
  179. package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  180. package/node/TimeField/TimeField.js +1 -1
  181. package/node/YearCalendar/YearCalendar.js +26 -9
  182. package/node/index.js +1 -1
  183. package/node/internals/hooks/useField/useFieldState.js +0 -1
  184. package/node/internals/hooks/usePicker/usePickerValue.js +22 -2
  185. package/node/internals/utils/date-time-utils.js +49 -0
  186. package/node/internals/utils/date-utils.js +35 -12
  187. package/node/internals/utils/getDefaultReferenceDate.js +3 -3
  188. package/node/internals/utils/time-utils.js +30 -2
  189. package/node/internals/utils/views.js +8 -5
  190. package/node/locales/deDE.js +2 -2
  191. package/node/locales/elGR.js +64 -0
  192. package/node/locales/index.js +112 -90
  193. package/node/locales/roRO.js +67 -0
  194. package/package.json +1 -1
@@ -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", "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"];
3
+ const _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"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
@@ -84,6 +84,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
84
84
  onViewChange,
85
85
  value: valueProp,
86
86
  defaultValue,
87
+ referenceDate: referenceDateProp,
87
88
  disableFuture,
88
89
  disablePast,
89
90
  defaultCalendarMonth,
@@ -147,6 +148,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
147
148
  onFocusedViewChange
148
149
  });
149
150
  const {
151
+ referenceDate,
150
152
  calendarState,
151
153
  changeFocusedDay,
152
154
  changeMonth,
@@ -156,6 +158,7 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
156
158
  } = useCalendarState({
157
159
  value,
158
160
  defaultCalendarMonth,
161
+ referenceDate: referenceDateProp,
159
162
  reduceAnimations,
160
163
  onMonthChange,
161
164
  minDate,
@@ -207,9 +210,9 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
207
210
  changeFocusedDay(closestEnabledDate, true);
208
211
  });
209
212
  const handleSelectedDayChange = useEventCallback(day => {
210
- if (value && day) {
213
+ if (day) {
211
214
  // If there is a date already selected, then we want to keep its time
212
- return handleValueChange(mergeDateAndTime(utils, day, value), 'finish');
215
+ return handleValueChange(mergeDateAndTime(utils, day, value != null ? value : referenceDate), 'finish');
213
216
  }
214
217
  return handleValueChange(day, 'finish');
215
218
  });
@@ -286,7 +289,8 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
286
289
  shouldDisableYear: shouldDisableYear,
287
290
  hasFocus: hasFocus,
288
291
  onFocusedViewChange: isViewFocused => setFocusedView('year', isViewFocused),
289
- yearsPerRow: yearsPerRow
292
+ yearsPerRow: yearsPerRow,
293
+ referenceDate: referenceDate
290
294
  })), view === 'month' && /*#__PURE__*/_jsx(MonthCalendar, _extends({}, baseDateValidationProps, commonViewProps, {
291
295
  hasFocus: hasFocus,
292
296
  className: className,
@@ -294,7 +298,8 @@ export const DateCalendar = /*#__PURE__*/React.forwardRef(function DateCalendar(
294
298
  onChange: handleDateMonthChange,
295
299
  shouldDisableMonth: shouldDisableMonth,
296
300
  onFocusedViewChange: isViewFocused => setFocusedView('month', isViewFocused),
297
- monthsPerRow: monthsPerRow
301
+ monthsPerRow: monthsPerRow,
302
+ referenceDate: referenceDate
298
303
  })), view === 'day' && /*#__PURE__*/_jsx(DayCalendar, _extends({}, calendarState, baseDateValidationProps, commonViewProps, {
299
304
  onMonthSwitchingAnimationEnd: onMonthSwitchingAnimationEnd,
300
305
  onFocusedDayChange: changeFocusedDay,
@@ -356,7 +361,7 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
356
361
  */
357
362
  dayOfWeekFormatter: PropTypes.func,
358
363
  /**
359
- * Default calendar month displayed when `value={null}`.
364
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
360
365
  */
361
366
  defaultCalendarMonth: PropTypes.any,
362
367
  /**
@@ -465,6 +470,11 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
465
470
  * @default typeof navigator !== 'undefined' && /(android)/i.test(navigator.userAgent)
466
471
  */
467
472
  reduceAnimations: PropTypes.bool,
473
+ /**
474
+ * The date used to generate the new value when both `value` and `defaultValue` are empty.
475
+ * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`.
476
+ */
477
+ referenceDate: PropTypes.any,
468
478
  /**
469
479
  * Component displaying when passed `loading` true.
470
480
  * @returns {React.ReactNode} The node to render when loading.
@@ -18,7 +18,7 @@ export interface DateCalendarSlotsComponentsProps<TDate> extends PickersCalendar
18
18
  }
19
19
  export interface ExportedDateCalendarProps<TDate> extends ExportedDayCalendarProps, ExportedMonthCalendarProps, ExportedYearCalendarProps, BaseDateValidationProps<TDate>, DayValidationProps<TDate>, YearValidationProps<TDate>, MonthValidationProps<TDate> {
20
20
  /**
21
- * Default calendar month displayed when `value={null}`.
21
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
22
22
  */
23
23
  defaultCalendarMonth?: TDate;
24
24
  /**
@@ -66,6 +66,11 @@ export interface DateCalendarProps<TDate> extends ExportedDateCalendarProps<TDat
66
66
  * Used when the component is not controlled.
67
67
  */
68
68
  defaultValue?: TDate | null;
69
+ /**
70
+ * The date used to generate the new value when both `value` and `defaultValue` are empty.
71
+ * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`.
72
+ */
73
+ referenceDate?: TDate;
69
74
  /**
70
75
  * Callback fired when the value changes.
71
76
  * @template TDate
@@ -25,10 +25,11 @@ interface ChangeFocusedDayPayload<TDate> {
25
25
  export declare const createCalendarStateReducer: <TDate extends unknown>(reduceAnimations: boolean, disableSwitchToMonthOnDayFocus: boolean, utils: MuiPickersAdapter<TDate, any>) => (state: CalendarState<TDate>, action: {
26
26
  type: "finishMonthSwitchingAnimation";
27
27
  } | ReducerAction<"changeMonth", ChangeMonthPayload<TDate>> | ReducerAction<"changeFocusedDay", ChangeFocusedDayPayload<TDate>>) => CalendarState<TDate>;
28
- interface CalendarStateInput<TDate> extends Pick<DateCalendarDefaultizedProps<TDate>, 'value' | 'defaultCalendarMonth' | 'disableFuture' | 'disablePast' | 'minDate' | 'maxDate' | 'onMonthChange' | 'reduceAnimations' | 'shouldDisableDate'> {
28
+ interface UseCalendarStateParams<TDate> extends Pick<DateCalendarDefaultizedProps<TDate>, 'value' | 'referenceDate' | 'defaultCalendarMonth' | 'disableFuture' | 'disablePast' | 'minDate' | 'maxDate' | 'onMonthChange' | 'reduceAnimations' | 'shouldDisableDate'> {
29
29
  disableSwitchToMonthOnDayFocus?: boolean;
30
30
  }
31
- export declare const useCalendarState: <TDate extends unknown>({ value, defaultCalendarMonth, disableFuture, disablePast, disableSwitchToMonthOnDayFocus, maxDate, minDate, onMonthChange, reduceAnimations, shouldDisableDate, }: CalendarStateInput<TDate>) => {
31
+ export declare const useCalendarState: <TDate extends unknown>(params: UseCalendarStateParams<TDate>) => {
32
+ referenceDate: any;
32
33
  calendarState: CalendarState<TDate>;
33
34
  changeMonth: (newDate: TDate) => void;
34
35
  changeFocusedDay: (newFocusedDate: TDate | null, withoutMonthSwitchingAnimation?: boolean | undefined) => void;
@@ -3,7 +3,8 @@ import * as React from 'react';
3
3
  import useEventCallback from '@mui/utils/useEventCallback';
4
4
  import { useIsDateDisabled } from './useIsDateDisabled';
5
5
  import { useUtils, useNow } from '../internals/hooks/useUtils';
6
- import { clamp } from '../internals/utils/date-utils';
6
+ import { singleItemValueManager } from '../internals/utils/valueManagers';
7
+ import { SECTION_TYPE_GRANULARITY } from '../internals/utils/getDefaultReferenceDate';
7
8
  export const createCalendarStateReducer = (reduceAnimations, disableSwitchToMonthOnDayFocus, utils) => (state, action) => {
8
9
  switch (action.type) {
9
10
  case 'changeMonth':
@@ -33,26 +34,45 @@ export const createCalendarStateReducer = (reduceAnimations, disableSwitchToMont
33
34
  throw new Error('missing support');
34
35
  }
35
36
  };
36
- export const useCalendarState = ({
37
- value,
38
- defaultCalendarMonth,
39
- disableFuture,
40
- disablePast,
41
- disableSwitchToMonthOnDayFocus = false,
42
- maxDate,
43
- minDate,
44
- onMonthChange,
45
- reduceAnimations,
46
- shouldDisableDate
47
- }) => {
48
- var _ref;
37
+ export const useCalendarState = params => {
38
+ const {
39
+ value,
40
+ referenceDate: referenceDateProp,
41
+ defaultCalendarMonth,
42
+ disableFuture,
43
+ disablePast,
44
+ disableSwitchToMonthOnDayFocus = false,
45
+ maxDate,
46
+ minDate,
47
+ onMonthChange,
48
+ reduceAnimations,
49
+ shouldDisableDate
50
+ } = params;
49
51
  const now = useNow();
50
52
  const utils = useUtils();
51
53
  const reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations), disableSwitchToMonthOnDayFocus, utils)).current;
54
+ const referenceDate = React.useMemo(() => {
55
+ let externalReferenceDate = null;
56
+ if (referenceDateProp) {
57
+ externalReferenceDate = referenceDateProp;
58
+ } else if (defaultCalendarMonth) {
59
+ // For `defaultCalendarMonth`, we just want to keep the month and the year to avoid a behavior change.
60
+ externalReferenceDate = utils.startOfMonth(defaultCalendarMonth);
61
+ }
62
+ return singleItemValueManager.getInitialReferenceValue({
63
+ value,
64
+ utils,
65
+ props: params,
66
+ referenceDate: externalReferenceDate,
67
+ granularity: SECTION_TYPE_GRANULARITY.day
68
+ });
69
+ }, [] // eslint-disable-line react-hooks/exhaustive-deps
70
+ );
71
+
52
72
  const [calendarState, dispatch] = React.useReducer(reducerFn, {
53
73
  isMonthSwitchingAnimating: false,
54
74
  focusedDay: value || now,
55
- currentMonth: utils.startOfMonth((_ref = value != null ? value : defaultCalendarMonth) != null ? _ref : clamp(utils, now, minDate, maxDate)),
75
+ currentMonth: utils.startOfMonth(referenceDate),
56
76
  slideDirection: 'left'
57
77
  });
58
78
  const handleChangeMonth = React.useCallback(payload => {
@@ -95,6 +115,7 @@ export const useCalendarState = ({
95
115
  }
96
116
  });
97
117
  return {
118
+ referenceDate,
98
119
  calendarState,
99
120
  changeMonth,
100
121
  changeFocusedDay,
@@ -230,7 +230,7 @@ process.env.NODE_ENV !== "production" ? DateField.propTypes = {
230
230
  */
231
231
  readOnly: PropTypes.bool,
232
232
  /**
233
- * 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.
233
+ * 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.
234
234
  * For example, on time fields it will be used to determine the date to set.
235
235
  * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
236
236
  */
@@ -73,7 +73,7 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
73
73
  */
74
74
  dayOfWeekFormatter: PropTypes.func,
75
75
  /**
76
- * Default calendar month displayed when `value={null}`.
76
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
77
77
  */
78
78
  defaultCalendarMonth: PropTypes.any,
79
79
  /**
@@ -8,8 +8,8 @@ import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
9
9
  import { PickersToolbar } from '../internals/components/PickersToolbar';
10
10
  import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
11
- import { isYearOnlyView, isYearAndMonthViews } from '../internals/utils/views';
12
11
  import { getDatePickerToolbarUtilityClass } from './datePickerToolbarClasses';
12
+ import { resolveDateFormat } from '../internals/utils/date-utils';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  const useUtilityClasses = ownerState => {
15
15
  const {
@@ -59,20 +59,11 @@ const DatePickerToolbar = /*#__PURE__*/React.forwardRef(function DatePickerToolb
59
59
  if (!value) {
60
60
  return toolbarPlaceholder;
61
61
  }
62
- if (toolbarFormat) {
63
- return utils.formatByString(value, toolbarFormat);
64
- }
65
- if (isYearOnlyView(views)) {
66
- return utils.format(value, 'year');
67
- }
68
- if (isYearAndMonthViews(views)) {
69
- return utils.format(value, 'month');
70
- }
71
-
72
- // Little localization hack (Google is doing the same for android native pickers):
73
- // For english localization it is convenient to include weekday into the date "Mon, Jun 1".
74
- // For other locales using strings like "June 1", without weekday.
75
- return /en/.test(utils.getCurrentLocaleCode()) ? utils.format(value, 'normalDateWithWeekday') : utils.format(value, 'normalDate');
62
+ const formatFromViews = resolveDateFormat(utils, {
63
+ format: toolbarFormat,
64
+ views
65
+ }, true);
66
+ return utils.formatByString(value, formatFromViews);
76
67
  }, [value, toolbarFormat, toolbarPlaceholder, utils, views]);
77
68
  const ownerState = props;
78
69
  return /*#__PURE__*/_jsx(DatePickerToolbarRoot, _extends({
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { DefaultizedProps } from '../internals/models/helpers';
3
3
  import { DateCalendarSlotsComponent, DateCalendarSlotsComponentsProps, ExportedDateCalendarProps } from '../DateCalendar/DateCalendar.types';
4
- import { DateValidationError, DateView, MuiPickersAdapter } from '../models';
4
+ import { DateValidationError, DateView } from '../models';
5
5
  import { BasePickerInputProps } from '../internals/models/props/basePickerProps';
6
6
  import { BaseDateValidationProps, UncapitalizeObjectKeys } from '../internals';
7
7
  import { LocalizedComponent } from '../locales/utils/pickersLocaleTextApi';
@@ -49,9 +49,5 @@ export interface BaseDatePickerProps<TDate> extends BasePickerInputProps<TDate |
49
49
  viewRenderers?: Partial<PickerViewRendererLookup<TDate | null, DateView, DateViewRendererProps<TDate, DateView>, {}>>;
50
50
  }
51
51
  type UseDatePickerDefaultizedProps<TDate, Props extends BaseDatePickerProps<TDate>> = LocalizedComponent<TDate, Omit<DefaultizedProps<Props, 'views' | 'openTo' | keyof BaseDateValidationProps<TDate>>, 'components' | 'componentsProps'>>;
52
- export declare const getDatePickerFieldFormat: (utils: MuiPickersAdapter<any>, { format, views }: {
53
- format?: string | undefined;
54
- views: readonly DateView[];
55
- }) => string | undefined;
56
52
  export declare function useDatePickerDefaultizedProps<TDate, Props extends BaseDatePickerProps<TDate>>(props: Props, name: string): UseDatePickerDefaultizedProps<TDate, Props>;
57
53
  export {};
@@ -2,25 +2,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { useThemeProps } from '@mui/material/styles';
4
4
  import { useDefaultDates, useUtils } from '../internals/hooks/useUtils';
5
- import { applyDefaultViewProps, isYearAndMonthViews, isYearOnlyView } from '../internals/utils/views';
5
+ import { applyDefaultViewProps } from '../internals/utils/views';
6
6
  import { applyDefaultDate } from '../internals/utils/date-utils';
7
7
  import { DatePickerToolbar } from './DatePickerToolbar';
8
8
  import { uncapitalizeObjectKeys } from '../internals/utils/slots-migration';
9
- export const getDatePickerFieldFormat = (utils, {
10
- format,
11
- views
12
- }) => {
13
- if (format != null) {
14
- return format;
15
- }
16
- if (isYearOnlyView(views)) {
17
- return utils.formats.year;
18
- }
19
- if (isYearAndMonthViews(views)) {
20
- return utils.formats.monthAndYear;
21
- }
22
- return undefined;
23
- };
24
9
  export function useDatePickerDefaultizedProps(props, name) {
25
10
  var _themeProps$slots, _themeProps$disableFu, _themeProps$disablePa, _themeProps$slotProps;
26
11
  const utils = useUtils();
@@ -263,7 +263,7 @@ process.env.NODE_ENV !== "production" ? DateTimeField.propTypes = {
263
263
  */
264
264
  readOnly: PropTypes.bool,
265
265
  /**
266
- * 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.
266
+ * 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.
267
267
  * For example, on time fields it will be used to determine the date to set.
268
268
  * @default The closest valid date using the validation props, except callbacks such as `shouldDisableDate`. Value is rounded to the most granular section used.
269
269
  */
@@ -83,7 +83,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
83
83
  */
84
84
  dayOfWeekFormatter: PropTypes.func,
85
85
  /**
86
- * Default calendar month displayed when `value={null}`.
86
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
87
87
  */
88
88
  defaultCalendarMonth: PropTypes.any,
89
89
  /**
@@ -3,13 +3,14 @@ import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { resolveComponentProps } from '@mui/base/utils';
5
5
  import { singleItemValueManager } from '../internals/utils/valueManagers';
6
- import { getDatePickerFieldFormat, useDatePickerDefaultizedProps } from '../DatePicker/shared';
6
+ import { useDatePickerDefaultizedProps } from '../DatePicker/shared';
7
7
  import { useLocaleText, useUtils, validateDate } from '../internals';
8
8
  import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
9
9
  import { CalendarIcon } from '../icons';
10
10
  import { DateField } from '../DateField';
11
11
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
12
12
  import { renderDateViewCalendar } from '../dateViewRenderers';
13
+ import { resolveDateFormat } from '../internals/utils/date-utils';
13
14
  const DesktopDatePicker = /*#__PURE__*/React.forwardRef(function DesktopDatePicker(inProps, ref) {
14
15
  var _defaultizedProps$yea, _defaultizedProps$slo2;
15
16
  const localeText = useLocaleText();
@@ -26,7 +27,7 @@ const DesktopDatePicker = /*#__PURE__*/React.forwardRef(function DesktopDatePick
26
27
  // Props with the default values specific to the desktop variant
27
28
  const props = _extends({}, defaultizedProps, {
28
29
  viewRenderers,
29
- format: getDatePickerFieldFormat(utils, defaultizedProps),
30
+ format: resolveDateFormat(utils, defaultizedProps, false),
30
31
  yearsPerRow: (_defaultizedProps$yea = defaultizedProps.yearsPerRow) != null ? _defaultizedProps$yea : 4,
31
32
  slots: _extends({
32
33
  openPickerIcon: CalendarIcon,
@@ -96,7 +97,7 @@ DesktopDatePicker.propTypes = {
96
97
  */
97
98
  dayOfWeekFormatter: PropTypes.func,
98
99
  /**
99
- * Default calendar month displayed when `value={null}`.
100
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
100
101
  */
101
102
  defaultCalendarMonth: PropTypes.any,
102
103
  /**
@@ -7,13 +7,16 @@ import { DateTimeField } from '../DateTimeField';
7
7
  import { useDateTimePickerDefaultizedProps } from '../DateTimePicker/shared';
8
8
  import { renderDateViewCalendar } from '../dateViewRenderers/dateViewRenderers';
9
9
  import { renderDesktopDateTimeView } from '../dateTimeViewRenderers';
10
- import { useLocaleText, validateDateTime } from '../internals';
10
+ import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
11
+ import { validateDateTime } from '../internals/utils/validation/validateDateTime';
11
12
  import { CalendarIcon } from '../icons';
12
13
  import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
13
14
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
15
+ import { resolveDateTimeFormat } from '../internals/utils/date-time-utils';
14
16
  const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDateTimePicker(inProps, ref) {
15
17
  var _defaultizedProps$amp, _defaultizedProps$yea, _defaultizedProps$slo2, _defaultizedProps$slo3, _defaultizedProps$slo4;
16
18
  const localeText = useLocaleText();
19
+ const utils = useUtils();
17
20
 
18
21
  // Props with the default values common to all date time pickers
19
22
  const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiDesktopDateTimePicker');
@@ -49,6 +52,7 @@ const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function DesktopDate
49
52
  // Props with the default values specific to the desktop variant
50
53
  const props = _extends({}, defaultizedProps, {
51
54
  viewRenderers,
55
+ format: resolveDateTimeFormat(utils, defaultizedProps),
52
56
  views: defaultizedProps.ampm ? [...defaultizedProps.views, 'meridiem'] : defaultizedProps.views,
53
57
  yearsPerRow: (_defaultizedProps$yea = defaultizedProps.yearsPerRow) != null ? _defaultizedProps$yea : 4,
54
58
  ampmInClock,
@@ -139,7 +143,7 @@ DesktopDateTimePicker.propTypes = {
139
143
  */
140
144
  dayOfWeekFormatter: PropTypes.func,
141
145
  /**
142
- * Default calendar month displayed when `value={null}`.
146
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
143
147
  */
144
148
  defaultCalendarMonth: PropTypes.any,
145
149
  /**
@@ -5,14 +5,17 @@ import { resolveComponentProps } from '@mui/base/utils';
5
5
  import { singleItemValueManager } from '../internals/utils/valueManagers';
6
6
  import { TimeField } from '../TimeField';
7
7
  import { useTimePickerDefaultizedProps } from '../TimePicker/shared';
8
- import { useLocaleText, validateTime } from '../internals';
8
+ import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
9
+ import { validateTime } from '../internals/utils/validation/validateTime';
9
10
  import { ClockIcon } from '../icons';
10
11
  import { useDesktopPicker } from '../internals/hooks/useDesktopPicker';
11
12
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
12
13
  import { renderDigitalClockTimeView, renderMultiSectionDigitalClockTimeView } from '../timeViewRenderers';
14
+ import { resolveTimeFormat } from '../internals/utils/time-utils';
13
15
  const DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePicker(inProps, ref) {
14
16
  var _defaultizedProps$thr, _defaultizedProps$amp, _viewRenderers$hours, _defaultizedProps$slo2, _defaultizedProps$slo3;
15
17
  const localeText = useLocaleText();
18
+ const utils = useUtils();
16
19
 
17
20
  // Props with the default values common to all time pickers
18
21
  const defaultizedProps = useTimePickerDefaultizedProps(inProps, 'MuiDesktopTimePicker');
@@ -41,6 +44,7 @@ const DesktopTimePicker = /*#__PURE__*/React.forwardRef(function DesktopTimePick
41
44
  ampmInClock,
42
45
  timeSteps,
43
46
  viewRenderers,
47
+ format: resolveTimeFormat(utils, defaultizedProps),
44
48
  // Setting only `hours` time view in case of single column time picker
45
49
  // Allows for easy view lifecycle management
46
50
  views: shouldRenderTimeInASingleColumn ? ['hours'] : views,
@@ -112,6 +112,7 @@ process.env.NODE_ENV !== "production" ? LocalizationProvider.propTypes = {
112
112
  keyboardDateTime: PropTypes.string,
113
113
  keyboardDateTime12h: PropTypes.string,
114
114
  keyboardDateTime24h: PropTypes.string,
115
+ meridiem: PropTypes.string,
115
116
  minutes: PropTypes.string,
116
117
  month: PropTypes.string,
117
118
  monthAndDate: PropTypes.string,
@@ -3,12 +3,13 @@ import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { resolveComponentProps } from '@mui/base/utils';
5
5
  import { useMobilePicker } from '../internals/hooks/useMobilePicker';
6
- import { getDatePickerFieldFormat, useDatePickerDefaultizedProps } from '../DatePicker/shared';
6
+ import { useDatePickerDefaultizedProps } from '../DatePicker/shared';
7
7
  import { useLocaleText, useUtils, validateDate } from '../internals';
8
8
  import { DateField } from '../DateField';
9
9
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
10
10
  import { singleItemValueManager } from '../internals/utils/valueManagers';
11
11
  import { renderDateViewCalendar } from '../dateViewRenderers';
12
+ import { resolveDateFormat } from '../internals/utils/date-utils';
12
13
  const MobileDatePicker = /*#__PURE__*/React.forwardRef(function MobileDatePicker(inProps, ref) {
13
14
  var _defaultizedProps$slo2;
14
15
  const localeText = useLocaleText();
@@ -25,7 +26,7 @@ const MobileDatePicker = /*#__PURE__*/React.forwardRef(function MobileDatePicker
25
26
  // Props with the default values specific to the mobile variant
26
27
  const props = _extends({}, defaultizedProps, {
27
28
  viewRenderers,
28
- format: getDatePickerFieldFormat(utils, defaultizedProps),
29
+ format: resolveDateFormat(utils, defaultizedProps, false),
29
30
  slots: _extends({
30
31
  field: DateField
31
32
  }, defaultizedProps.slots),
@@ -93,7 +94,7 @@ MobileDatePicker.propTypes = {
93
94
  */
94
95
  dayOfWeekFormatter: PropTypes.func,
95
96
  /**
96
- * Default calendar month displayed when `value={null}`.
97
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
97
98
  */
98
99
  defaultCalendarMonth: PropTypes.any,
99
100
  /**
@@ -5,14 +5,17 @@ import { resolveComponentProps } from '@mui/base/utils';
5
5
  import { singleItemValueManager } from '../internals/utils/valueManagers';
6
6
  import { DateTimeField } from '../DateTimeField';
7
7
  import { useDateTimePickerDefaultizedProps } from '../DateTimePicker/shared';
8
- import { useLocaleText, validateDateTime } from '../internals';
8
+ import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
9
+ import { validateDateTime } from '../internals/utils/validation/validateDateTime';
9
10
  import { useMobilePicker } from '../internals/hooks/useMobilePicker';
10
11
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
11
12
  import { renderDateViewCalendar } from '../dateViewRenderers';
12
13
  import { renderTimeViewClock } from '../timeViewRenderers';
14
+ import { resolveDateTimeFormat } from '../internals/utils/date-time-utils';
13
15
  const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTimePicker(inProps, ref) {
14
16
  var _defaultizedProps$amp, _defaultizedProps$slo2, _defaultizedProps$slo3;
15
17
  const localeText = useLocaleText();
18
+ const utils = useUtils();
16
19
 
17
20
  // Props with the default values common to all date time pickers
18
21
  const defaultizedProps = useDateTimePickerDefaultizedProps(inProps, 'MuiMobileDateTimePicker');
@@ -29,6 +32,7 @@ const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function MobileDateTi
29
32
  // Props with the default values specific to the mobile variant
30
33
  const props = _extends({}, defaultizedProps, {
31
34
  viewRenderers,
35
+ format: resolveDateTimeFormat(utils, defaultizedProps),
32
36
  ampmInClock,
33
37
  slots: _extends({
34
38
  field: DateTimeField
@@ -111,7 +115,7 @@ MobileDateTimePicker.propTypes = {
111
115
  */
112
116
  dayOfWeekFormatter: PropTypes.func,
113
117
  /**
114
- * Default calendar month displayed when `value={null}`.
118
+ * Default calendar month displayed when `value` and `defaultValue` are empty.
115
119
  */
116
120
  defaultCalendarMonth: PropTypes.any,
117
121
  /**
@@ -5,13 +5,16 @@ import { resolveComponentProps } from '@mui/base/utils';
5
5
  import { singleItemValueManager } from '../internals/utils/valueManagers';
6
6
  import { TimeField } from '../TimeField';
7
7
  import { useTimePickerDefaultizedProps } from '../TimePicker/shared';
8
- import { useLocaleText, validateTime } from '../internals';
8
+ import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
9
+ import { validateTime } from '../internals/utils/validation/validateTime';
9
10
  import { useMobilePicker } from '../internals/hooks/useMobilePicker';
10
11
  import { extractValidationProps } from '../internals/utils/validation/extractValidationProps';
11
12
  import { renderTimeViewClock } from '../timeViewRenderers';
13
+ import { resolveTimeFormat } from '../internals/utils/time-utils';
12
14
  const MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker(inProps, ref) {
13
15
  var _defaultizedProps$amp, _defaultizedProps$slo2;
14
16
  const localeText = useLocaleText();
17
+ const utils = useUtils();
15
18
 
16
19
  // Props with the default values common to all time pickers
17
20
  const defaultizedProps = useTimePickerDefaultizedProps(inProps, 'MuiMobileTimePicker');
@@ -26,6 +29,7 @@ const MobileTimePicker = /*#__PURE__*/React.forwardRef(function MobileTimePicker
26
29
  const props = _extends({}, defaultizedProps, {
27
30
  ampmInClock,
28
31
  viewRenderers,
32
+ format: resolveTimeFormat(utils, defaultizedProps),
29
33
  slots: _extends({
30
34
  field: TimeField
31
35
  }, defaultizedProps.slots),
@@ -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 = ["className", "value", "defaultValue", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange", "monthsPerRow"];
3
+ const _excluded = ["className", "value", "defaultValue", "referenceDate", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange", "monthsPerRow"];
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 { PickersMonth } from './PickersMonth';
11
11
  import { useUtils, useNow, useDefaultDates } from '../internals/hooks/useUtils';
12
12
  import { getMonthCalendarUtilityClass } from './monthCalendarClasses';
13
13
  import { applyDefaultDate, getMonthsInYear } 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 {
@@ -56,6 +58,7 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
56
58
  className,
57
59
  value: valueProp,
58
60
  defaultValue,
61
+ referenceDate: referenceDateProp,
59
62
  disabled,
60
63
  disableFuture,
61
64
  disablePast,
@@ -80,8 +83,16 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
80
83
  controlled: valueProp,
81
84
  default: defaultValue != null ? defaultValue : null
82
85
  });
86
+ const referenceDate = React.useMemo(() => singleItemValueManager.getInitialReferenceValue({
87
+ value,
88
+ utils,
89
+ props,
90
+ referenceDate: referenceDateProp,
91
+ granularity: SECTION_TYPE_GRANULARITY.month
92
+ }), [] // eslint-disable-line react-hooks/exhaustive-deps
93
+ );
94
+
83
95
  const todayMonth = React.useMemo(() => utils.getMonth(now), [utils, now]);
84
- const selectedDateOrStartOfMonth = React.useMemo(() => value != null ? value : utils.startOfMonth(now), [now, utils, value]);
85
96
  const selectedMonth = React.useMemo(() => {
86
97
  if (value != null) {
87
98
  return utils.getMonth(value);
@@ -89,8 +100,8 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
89
100
  if (disableHighlightToday) {
90
101
  return null;
91
102
  }
92
- return utils.getMonth(now);
93
- }, [now, value, utils, disableHighlightToday]);
103
+ return utils.getMonth(referenceDate);
104
+ }, [value, utils, disableHighlightToday, referenceDate]);
94
105
  const [focusedMonth, setFocusedMonth] = React.useState(() => selectedMonth || todayMonth);
95
106
  const [internalHasFocus, setInternalHasFocus] = useControlled({
96
107
  name: 'MonthCalendar',
@@ -104,30 +115,31 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
104
115
  onFocusedViewChange(newHasFocus);
105
116
  }
106
117
  });
107
- const isMonthDisabled = React.useCallback(month => {
118
+ const isMonthDisabled = React.useCallback(dateToValidate => {
108
119
  const firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : minDate);
109
120
  const lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : maxDate);
110
- if (utils.isBefore(month, firstEnabledMonth)) {
121
+ const monthToValidate = utils.startOfMonth(dateToValidate);
122
+ if (utils.isBefore(monthToValidate, firstEnabledMonth)) {
111
123
  return true;
112
124
  }
113
- if (utils.isAfter(month, lastEnabledMonth)) {
125
+ if (utils.isAfter(monthToValidate, lastEnabledMonth)) {
114
126
  return true;
115
127
  }
116
128
  if (!shouldDisableMonth) {
117
129
  return false;
118
130
  }
119
- return shouldDisableMonth(month);
131
+ return shouldDisableMonth(monthToValidate);
120
132
  }, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableMonth, utils]);
121
133
  const handleMonthSelection = useEventCallback((event, month) => {
122
134
  if (readOnly) {
123
135
  return;
124
136
  }
125
- const newDate = utils.setMonth(selectedDateOrStartOfMonth, month);
137
+ const newDate = utils.setMonth(value != null ? value : referenceDate, month);
126
138
  setValue(newDate);
127
139
  onChange == null ? void 0 : onChange(newDate);
128
140
  });
129
141
  const focusMonth = useEventCallback(month => {
130
- if (!isMonthDisabled(utils.setMonth(selectedDateOrStartOfMonth, month))) {
142
+ if (!isMonthDisabled(utils.setMonth(value != null ? value : referenceDate, month))) {
131
143
  setFocusedMonth(month);
132
144
  changeHasFocus(true);
133
145
  if (onMonthFocus) {
@@ -175,7 +187,7 @@ export const MonthCalendar = /*#__PURE__*/React.forwardRef(function MonthCalenda
175
187
  className: clsx(classes.root, className),
176
188
  ownerState: ownerState
177
189
  }, other, {
178
- children: getMonthsInYear(utils, selectedDateOrStartOfMonth).map(month => {
190
+ children: getMonthsInYear(utils, value != null ? value : referenceDate).map(month => {
179
191
  const monthNumber = utils.getMonth(month);
180
192
  const monthText = utils.format(month, 'monthShort');
181
193
  const isSelected = monthNumber === selectedMonth;
@@ -261,6 +273,11 @@ process.env.NODE_ENV !== "production" ? MonthCalendar.propTypes = {
261
273
  * If `true` picker is readonly
262
274
  */
263
275
  readOnly: PropTypes.bool,
276
+ /**
277
+ * The date used to generate the new value when both `value` and `defaultValue` are empty.
278
+ * @default The closest valid month using the validation props, except callbacks such as `shouldDisableDate`.
279
+ */
280
+ referenceDate: PropTypes.any,
264
281
  /**
265
282
  * Disable specific month.
266
283
  * @template TDate