@mui/x-date-pickers 6.1.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/AdapterDayjs/AdapterDayjs.d.ts +114 -0
  2. package/AdapterDayjs/AdapterDayjs.js +387 -0
  3. package/AdapterDayjs/index.d.ts +1 -28
  4. package/AdapterDayjs/index.js +1 -102
  5. package/CHANGELOG.md +53 -1
  6. package/DateCalendar/DateCalendar.types.d.ts +1 -1
  7. package/DateCalendar/DayCalendar.d.ts +1 -1
  8. package/DateField/DateField.js +6 -0
  9. package/DateField/useDateField.js +3 -1
  10. package/DatePicker/DatePicker.js +6 -0
  11. package/DateTimeField/DateTimeField.js +6 -0
  12. package/DateTimeField/useDateTimeField.js +3 -1
  13. package/DateTimePicker/DateTimePicker.js +6 -0
  14. package/DateTimePicker/shared.js +3 -1
  15. package/DesktopDatePicker/DesktopDatePicker.js +6 -0
  16. package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  17. package/DesktopTimePicker/DesktopTimePicker.js +6 -0
  18. package/MobileDatePicker/MobileDatePicker.js +6 -0
  19. package/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  20. package/MobileTimePicker/MobileTimePicker.js +6 -0
  21. package/README.md +1 -0
  22. package/TimeClock/TimeClock.types.d.ts +1 -1
  23. package/TimeField/TimeField.js +6 -0
  24. package/TimeField/useTimeField.js +3 -1
  25. package/TimePicker/TimePicker.js +6 -0
  26. package/index.js +1 -1
  27. package/internals/components/PickersModalDialog.d.ts +1 -1
  28. package/internals/components/PickersPopper.d.ts +1 -1
  29. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  30. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +1 -1
  31. package/internals/hooks/useField/useField.types.d.ts +6 -0
  32. package/internals/hooks/useField/useField.utils.d.ts +1 -1
  33. package/internals/hooks/useField/useField.utils.js +16 -4
  34. package/internals/hooks/useField/useFieldState.js +3 -2
  35. package/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  36. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +1 -1
  37. package/internals/hooks/usePicker/index.d.ts +1 -1
  38. package/internals/hooks/usePicker/usePicker.types.d.ts +1 -1
  39. package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -1
  40. package/internals/hooks/usePicker/usePickerValue.d.ts +3 -179
  41. package/internals/hooks/usePicker/usePickerValue.js +187 -153
  42. package/internals/hooks/usePicker/usePickerValue.types.d.ts +233 -0
  43. package/internals/hooks/usePicker/usePickerValue.types.js +1 -0
  44. package/internals/hooks/usePicker/usePickerViews.d.ts +1 -1
  45. package/internals/index.d.ts +1 -1
  46. package/internals/models/props/basePickerProps.d.ts +6 -0
  47. package/legacy/AdapterDayjs/AdapterDayjs.js +403 -0
  48. package/legacy/AdapterDayjs/index.js +1 -119
  49. package/legacy/DateField/DateField.js +6 -0
  50. package/legacy/DateField/useDateField.js +3 -1
  51. package/legacy/DatePicker/DatePicker.js +6 -0
  52. package/legacy/DateTimeField/DateTimeField.js +6 -0
  53. package/legacy/DateTimeField/useDateTimeField.js +3 -1
  54. package/legacy/DateTimePicker/DateTimePicker.js +6 -0
  55. package/legacy/DateTimePicker/shared.js +3 -1
  56. package/legacy/DesktopDatePicker/DesktopDatePicker.js +6 -0
  57. package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  58. package/legacy/DesktopTimePicker/DesktopTimePicker.js +6 -0
  59. package/legacy/MobileDatePicker/MobileDatePicker.js +6 -0
  60. package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  61. package/legacy/MobileTimePicker/MobileTimePicker.js +6 -0
  62. package/legacy/TimeField/TimeField.js +6 -0
  63. package/legacy/TimeField/useTimeField.js +3 -1
  64. package/legacy/TimePicker/TimePicker.js +6 -0
  65. package/legacy/index.js +1 -1
  66. package/legacy/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  67. package/legacy/internals/hooks/useField/useField.utils.js +24 -9
  68. package/legacy/internals/hooks/useField/useFieldState.js +5 -3
  69. package/legacy/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  70. package/legacy/internals/hooks/usePicker/usePickerValue.js +184 -153
  71. package/legacy/internals/hooks/usePicker/usePickerValue.types.js +1 -0
  72. package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
  73. package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
  74. package/legacy/tests/describeGregorianAdapter/index.js +1 -0
  75. package/legacy/tests/describeGregorianAdapter/testCalculations.js +273 -0
  76. package/legacy/tests/describeGregorianAdapter/testFormat.js +26 -0
  77. package/legacy/tests/describeGregorianAdapter/testLocalization.js +15 -0
  78. package/legacy/tests/describeValidation/describeValidation.js +2 -1
  79. package/legacy/tests/describeValidation/testMinutesViewValidation.js +201 -0
  80. package/legacy/tests/describeValue/testPickerActionBar.js +52 -3
  81. package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
  82. package/models/adapters.d.ts +21 -20
  83. package/modern/AdapterDayjs/AdapterDayjs.js +386 -0
  84. package/modern/AdapterDayjs/index.js +1 -101
  85. package/modern/DateField/DateField.js +6 -0
  86. package/modern/DateField/useDateField.js +3 -1
  87. package/modern/DatePicker/DatePicker.js +6 -0
  88. package/modern/DateTimeField/DateTimeField.js +6 -0
  89. package/modern/DateTimeField/useDateTimeField.js +3 -1
  90. package/modern/DateTimePicker/DateTimePicker.js +6 -0
  91. package/modern/DateTimePicker/shared.js +3 -1
  92. package/modern/DesktopDatePicker/DesktopDatePicker.js +6 -0
  93. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  94. package/modern/DesktopTimePicker/DesktopTimePicker.js +6 -0
  95. package/modern/MobileDatePicker/MobileDatePicker.js +6 -0
  96. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  97. package/modern/MobileTimePicker/MobileTimePicker.js +6 -0
  98. package/modern/TimeField/TimeField.js +6 -0
  99. package/modern/TimeField/useTimeField.js +3 -1
  100. package/modern/TimePicker/TimePicker.js +6 -0
  101. package/modern/index.js +1 -1
  102. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  103. package/modern/internals/hooks/useField/useField.utils.js +16 -4
  104. package/modern/internals/hooks/useField/useFieldState.js +3 -2
  105. package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  106. package/modern/internals/hooks/usePicker/usePickerValue.js +187 -153
  107. package/modern/internals/hooks/usePicker/usePickerValue.types.js +1 -0
  108. package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
  109. package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
  110. package/modern/tests/describeGregorianAdapter/index.js +1 -0
  111. package/modern/tests/describeGregorianAdapter/testCalculations.js +272 -0
  112. package/modern/tests/describeGregorianAdapter/testFormat.js +27 -0
  113. package/modern/tests/describeGregorianAdapter/testLocalization.js +16 -0
  114. package/modern/tests/describeValidation/describeValidation.js +2 -1
  115. package/modern/tests/describeValidation/testMinutesViewValidation.js +200 -0
  116. package/modern/tests/describeValue/testPickerActionBar.js +52 -3
  117. package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
  118. package/node/AdapterDayjs/AdapterDayjs.js +395 -0
  119. package/node/AdapterDayjs/index.js +6 -104
  120. package/node/DateField/DateField.js +6 -0
  121. package/node/DateField/useDateField.js +3 -1
  122. package/node/DatePicker/DatePicker.js +6 -0
  123. package/node/DateTimeField/DateTimeField.js +6 -0
  124. package/node/DateTimeField/useDateTimeField.js +3 -1
  125. package/node/DateTimePicker/DateTimePicker.js +6 -0
  126. package/node/DateTimePicker/shared.js +3 -1
  127. package/node/DesktopDatePicker/DesktopDatePicker.js +6 -0
  128. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  129. package/node/DesktopTimePicker/DesktopTimePicker.js +6 -0
  130. package/node/MobileDatePicker/MobileDatePicker.js +6 -0
  131. package/node/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  132. package/node/MobileTimePicker/MobileTimePicker.js +6 -0
  133. package/node/TimeField/TimeField.js +6 -0
  134. package/node/TimeField/useTimeField.js +3 -1
  135. package/node/TimePicker/TimePicker.js +6 -0
  136. package/node/index.js +1 -1
  137. package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  138. package/node/internals/hooks/useField/useField.utils.js +16 -4
  139. package/node/internals/hooks/useField/useFieldState.js +3 -2
  140. package/node/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  141. package/node/internals/hooks/usePicker/usePickerValue.js +187 -152
  142. package/node/internals/hooks/usePicker/usePickerValue.types.js +5 -0
  143. package/node/tests/describeGregorianAdapter/describeGregorianAdapter.js +29 -0
  144. package/node/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +5 -0
  145. package/node/tests/describeGregorianAdapter/index.js +18 -0
  146. package/node/tests/describeGregorianAdapter/testCalculations.js +279 -0
  147. package/node/tests/describeGregorianAdapter/testFormat.js +34 -0
  148. package/node/tests/describeGregorianAdapter/testLocalization.js +23 -0
  149. package/node/tests/describeValidation/describeValidation.js +2 -1
  150. package/node/tests/describeValidation/testMinutesViewValidation.js +210 -0
  151. package/node/tests/describeValue/testPickerActionBar.js +52 -3
  152. package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
  153. package/package.json +9 -9
  154. package/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
  155. package/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
  156. package/tests/describeGregorianAdapter/index.js +1 -0
  157. package/tests/describeGregorianAdapter/testCalculations.js +272 -0
  158. package/tests/describeGregorianAdapter/testFormat.js +27 -0
  159. package/tests/describeGregorianAdapter/testLocalization.js +16 -0
  160. package/tests/describeValidation/describeValidation.js +2 -1
  161. package/tests/describeValidation/testMinutesViewValidation.js +200 -0
  162. package/tests/describeValue/testPickerActionBar.js +52 -3
  163. package/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
@@ -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 = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "minTime", "maxTime", "minDateTime", "maxDateTime", "minutesStep", "disableIgnoringDatePartForTimeValidation", "shouldDisableClock", "shouldDisableTime", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
3
+ const _excluded = ["value", "defaultValue", "format", "formatDensity", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "minTime", "maxTime", "minDateTime", "maxDateTime", "minutesStep", "disableIgnoringDatePartForTimeValidation", "shouldDisableClock", "shouldDisableTime", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
4
4
  import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
5
5
  import { useField } from '../internals/hooks/useField';
6
6
  import { validateDateTime } from '../internals/hooks/validation/useDateTimeValidation';
@@ -31,6 +31,7 @@ export const useDateTimeField = ({
31
31
  value,
32
32
  defaultValue,
33
33
  format,
34
+ formatDensity,
34
35
  onChange,
35
36
  readOnly,
36
37
  onError,
@@ -60,6 +61,7 @@ export const useDateTimeField = ({
60
61
  value,
61
62
  defaultValue,
62
63
  format,
64
+ formatDensity,
63
65
  onChange,
64
66
  readOnly,
65
67
  onError,
@@ -142,6 +142,12 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
142
142
  * Defaults to localized format based on the used `views`.
143
143
  */
144
144
  format: PropTypes.string,
145
+ /**
146
+ * Density of the format when rendered in the input.
147
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
148
+ * @default "dense"
149
+ */
150
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
145
151
  /**
146
152
  * Pass a ref to the `input` element.
147
153
  */
@@ -35,7 +35,9 @@ export function useDateTimePickerDefaultizedProps(props, name) {
35
35
  localeText,
36
36
  orientation: themeProps.orientation ?? 'portrait',
37
37
  // TODO: Remove from public API
38
- disableIgnoringDatePartForTimeValidation: themeProps.disableIgnoringDatePartForTimeValidation ?? Boolean(themeProps.minDateTime || themeProps.maxDateTime),
38
+ disableIgnoringDatePartForTimeValidation: themeProps.disableIgnoringDatePartForTimeValidation ?? Boolean(themeProps.minDateTime || themeProps.maxDateTime ||
39
+ // allow time clock to correctly check time validity: https://github.com/mui/mui-x/issues/8520
40
+ themeProps.disablePast || themeProps.disableFuture),
39
41
  disableFuture: themeProps.disableFuture ?? false,
40
42
  disablePast: themeProps.disablePast ?? false,
41
43
  minDate: applyDefaultDate(utils, themeProps.minDateTime ?? themeProps.minDate, defaultDates.minDate),
@@ -139,6 +139,12 @@ DesktopDatePicker.propTypes = {
139
139
  * Defaults to localized format based on the used `views`.
140
140
  */
141
141
  format: PropTypes.string,
142
+ /**
143
+ * Density of the format when rendered in the input.
144
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
145
+ * @default "dense"
146
+ */
147
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
142
148
  /**
143
149
  * Pass a ref to the `input` element.
144
150
  */
@@ -162,6 +162,12 @@ DesktopDateTimePicker.propTypes = {
162
162
  * Defaults to localized format based on the used `views`.
163
163
  */
164
164
  format: PropTypes.string,
165
+ /**
166
+ * Density of the format when rendered in the input.
167
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
168
+ * @default "dense"
169
+ */
170
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
165
171
  /**
166
172
  * Pass a ref to the `input` element.
167
173
  */
@@ -128,6 +128,12 @@ DesktopTimePicker.propTypes = {
128
128
  * Defaults to localized format based on the used `views`.
129
129
  */
130
130
  format: PropTypes.string,
131
+ /**
132
+ * Density of the format when rendered in the input.
133
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
134
+ * @default "dense"
135
+ */
136
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
131
137
  /**
132
138
  * Pass a ref to the `input` element.
133
139
  */
@@ -136,6 +136,12 @@ MobileDatePicker.propTypes = {
136
136
  * Defaults to localized format based on the used `views`.
137
137
  */
138
138
  format: PropTypes.string,
139
+ /**
140
+ * Density of the format when rendered in the input.
141
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
142
+ * @default "dense"
143
+ */
144
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
139
145
  /**
140
146
  * Pass a ref to the `input` element.
141
147
  */
@@ -160,6 +160,12 @@ MobileDateTimePicker.propTypes = {
160
160
  * Defaults to localized format based on the used `views`.
161
161
  */
162
162
  format: PropTypes.string,
163
+ /**
164
+ * Density of the format when rendered in the input.
165
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
166
+ * @default "dense"
167
+ */
168
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
163
169
  /**
164
170
  * Pass a ref to the `input` element.
165
171
  */
@@ -127,6 +127,12 @@ MobileTimePicker.propTypes = {
127
127
  * Defaults to localized format based on the used `views`.
128
128
  */
129
129
  format: PropTypes.string,
130
+ /**
131
+ * Density of the format when rendered in the input.
132
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
133
+ * @default "dense"
134
+ */
135
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
130
136
  /**
131
137
  * Pass a ref to the `input` element.
132
138
  */
@@ -129,6 +129,12 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
129
129
  * Format of the date when rendered in the input(s).
130
130
  */
131
131
  format: PropTypes.string,
132
+ /**
133
+ * Density of the format when rendered in the input.
134
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
135
+ * @default "dense"
136
+ */
137
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
132
138
  /**
133
139
  * Props applied to the [`FormHelperText`](/material-ui/api/form-helper-text/) element.
134
140
  */
@@ -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 = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
3
+ const _excluded = ["value", "defaultValue", "format", "formatDensity", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
4
4
  import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
5
5
  import { useField } from '../internals/hooks/useField';
6
6
  import { validateTime } from '../internals/hooks/validation/useTimeValidation';
@@ -24,6 +24,7 @@ export const useTimeField = ({
24
24
  value,
25
25
  defaultValue,
26
26
  format,
27
+ formatDensity,
27
28
  onChange,
28
29
  readOnly,
29
30
  onError,
@@ -48,6 +49,7 @@ export const useTimeField = ({
48
49
  value,
49
50
  defaultValue,
50
51
  format,
52
+ formatDensity,
51
53
  onChange,
52
54
  readOnly,
53
55
  onError,
@@ -116,6 +116,12 @@ process.env.NODE_ENV !== "production" ? TimePicker.propTypes = {
116
116
  * Defaults to localized format based on the used `views`.
117
117
  */
118
118
  format: PropTypes.string,
119
+ /**
120
+ * Density of the format when rendered in the input.
121
+ * Setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character.
122
+ * @default "dense"
123
+ */
124
+ formatDensity: PropTypes.oneOf(['dense', 'spacious']),
119
125
  /**
120
126
  * Pass a ref to the `input` element.
121
127
  */
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v6.1.0
2
+ * @mui/x-date-pickers v6.2.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -33,6 +33,7 @@ export const useDesktopPicker = ({
33
33
  className,
34
34
  sx,
35
35
  format,
36
+ formatDensity,
36
37
  label,
37
38
  inputRef,
38
39
  readOnly,
@@ -98,6 +99,7 @@ export const useDesktopPicker = ({
98
99
  className,
99
100
  sx,
100
101
  format,
102
+ formatDensity,
101
103
  label,
102
104
  autoFocus: autoFocus && !props.open
103
105
  }),
@@ -309,7 +309,7 @@ const getEscapedPartsFromFormat = (utils, format) => {
309
309
  }
310
310
  return escapedParts;
311
311
  };
312
- export const splitFormatIntoSections = (utils, localeText, format, date) => {
312
+ export const splitFormatIntoSections = (utils, localeText, format, date, formatDensity) => {
313
313
  let startSeparator = '';
314
314
  const sections = [];
315
315
  const commitToken = token => {
@@ -380,8 +380,8 @@ export const splitFormatIntoSections = (utils, localeText, format, date) => {
380
380
  if (cleanedSeparator !== null && cleanedSeparator.includes(' ')) {
381
381
  cleanedSeparator = `\u2069${cleanedSeparator}\u2066`;
382
382
  }
383
- if (cleanedSeparator === '/') {
384
- cleanedSeparator = ' / ';
383
+ if (formatDensity === 'spacious' && ['/', '.', '-'].includes(cleanedSeparator)) {
384
+ cleanedSeparator = ` ${cleanedSeparator} `;
385
385
  }
386
386
  return cleanedSeparator;
387
387
  };
@@ -586,7 +586,19 @@ const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTran
586
586
  }
587
587
  }
588
588
  };
589
- export const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections, referenceDate, shouldLimitToEditedSections) => sections.reduce((mergedDate, section) => {
589
+ const reliableSectionModificationOrder = {
590
+ year: 1,
591
+ month: 2,
592
+ day: 3,
593
+ weekDay: 4,
594
+ hours: 5,
595
+ minutes: 6,
596
+ seconds: 7,
597
+ meridiem: 8
598
+ };
599
+ export const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections, referenceDate, shouldLimitToEditedSections) =>
600
+ // cloning sections before sort to avoid mutating it
601
+ [...sections].sort((a, b) => reliableSectionModificationOrder[a.type] - reliableSectionModificationOrder[b.type]).reduce((mergedDate, section) => {
590
602
  if (!shouldLimitToEditedSections || section.modified) {
591
603
  return transferDateSectionValue(utils, section, dateToTransferFrom, mergedDate);
592
604
  }
@@ -21,6 +21,7 @@ export const useFieldState = params => {
21
21
  defaultValue,
22
22
  onChange,
23
23
  format,
24
+ formatDensity = 'dense',
24
25
  selectedSections: selectedSectionsProp,
25
26
  onSelectedSectionsChange
26
27
  }
@@ -28,7 +29,7 @@ export const useFieldState = params => {
28
29
  const firstDefaultValue = React.useRef(defaultValue);
29
30
  const valueFromTheOutside = valueProp ?? firstDefaultValue.current ?? valueManager.emptyValue;
30
31
  const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(utils), [utils]);
31
- const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, isRTL, date => splitFormatIntoSections(utils, localeText, format, date)), [fieldValueManager, format, localeText, isRTL, utils]);
32
+ const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, isRTL, date => splitFormatIntoSections(utils, localeText, format, date, formatDensity)), [fieldValueManager, format, localeText, isRTL, utils, formatDensity]);
32
33
  const placeholder = React.useMemo(() => fieldValueManager.getValueStrFromSections(getSectionsFromValue(valueManager.emptyValue), isRTL), [fieldValueManager, getSectionsFromValue, valueManager.emptyValue, isRTL]);
33
34
  const [state, setState] = React.useState(() => {
34
35
  const sections = getSectionsFromValue(valueFromTheOutside);
@@ -152,7 +153,7 @@ export const useFieldState = params => {
152
153
  if (date == null || !utils.isValid(date)) {
153
154
  return null;
154
155
  }
155
- const sections = splitFormatIntoSections(utils, localeText, format, date);
156
+ const sections = splitFormatIntoSections(utils, localeText, format, date, formatDensity);
156
157
  return mergeDateIntoReferenceDate(utils, date, sections, referenceDate, false);
157
158
  };
158
159
  const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
@@ -29,6 +29,7 @@ export const useMobilePicker = ({
29
29
  className,
30
30
  sx,
31
31
  format,
32
+ formatDensity,
32
33
  label,
33
34
  inputRef,
34
35
  readOnly,
@@ -69,6 +70,7 @@ export const useMobilePicker = ({
69
70
  className,
70
71
  sx,
71
72
  format,
73
+ formatDensity,
72
74
  label
73
75
  }),
74
76
  ownerState: props