@mui/x-date-pickers 6.0.2 → 6.0.3

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 (129) hide show
  1. package/AdapterDateFns/index.js +1 -0
  2. package/AdapterDateFnsJalali/index.js +1 -0
  3. package/AdapterDayjs/index.js +5 -0
  4. package/AdapterLuxon/index.js +1 -0
  5. package/AdapterMoment/index.js +5 -0
  6. package/AdapterMomentHijri/index.js +5 -0
  7. package/AdapterMomentJalaali/index.js +5 -0
  8. package/CHANGELOG.md +58 -5
  9. package/DateField/DateField.js +4 -0
  10. package/DateField/DateField.types.d.ts +2 -2
  11. package/DateField/useDateField.js +5 -3
  12. package/DateTimeField/DateTimeField.js +4 -0
  13. package/DateTimeField/DateTimeField.types.d.ts +2 -2
  14. package/DateTimeField/useDateTimeField.js +5 -3
  15. package/PickersDay/PickersDay.js +4 -4
  16. package/TimeField/TimeField.js +4 -0
  17. package/TimeField/TimeField.types.d.ts +2 -2
  18. package/TimeField/useTimeField.js +5 -3
  19. package/index.d.ts +1 -6
  20. package/index.js +4 -2
  21. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +5 -4
  22. package/internals/hooks/useField/index.d.ts +2 -2
  23. package/internals/hooks/useField/index.js +1 -1
  24. package/internals/hooks/useField/useField.d.ts +1 -1
  25. package/internals/hooks/useField/useField.js +54 -25
  26. package/internals/hooks/useField/useField.types.d.ts +24 -12
  27. package/internals/hooks/useField/useFieldState.d.ts +1 -2
  28. package/internals/hooks/useField/useFieldState.js +1 -6
  29. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +5 -4
  30. package/internals/hooks/usePicker/usePicker.d.ts +2 -1
  31. package/internals/hooks/usePicker/usePicker.types.d.ts +4 -3
  32. package/internals/hooks/usePicker/usePickerValue.d.ts +8 -8
  33. package/internals/hooks/usePicker/usePickerValue.js +7 -11
  34. package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +2 -1
  35. package/internals/index.d.ts +2 -2
  36. package/internals/index.js +2 -2
  37. package/internals/models/fields.d.ts +3 -3
  38. package/internals/utils/date-utils.d.ts +1 -0
  39. package/internals/utils/date-utils.js +6 -0
  40. package/internals/utils/valueManagers.js +4 -5
  41. package/legacy/AdapterDateFns/index.js +1 -0
  42. package/legacy/AdapterDateFnsJalali/index.js +1 -0
  43. package/legacy/AdapterDayjs/index.js +5 -0
  44. package/legacy/AdapterLuxon/index.js +1 -0
  45. package/legacy/AdapterMoment/index.js +5 -0
  46. package/legacy/AdapterMomentHijri/index.js +5 -0
  47. package/legacy/AdapterMomentJalaali/index.js +5 -0
  48. package/legacy/DateField/DateField.js +4 -0
  49. package/legacy/DateField/useDateField.js +4 -2
  50. package/legacy/DateTimeField/DateTimeField.js +4 -0
  51. package/legacy/DateTimeField/useDateTimeField.js +4 -2
  52. package/legacy/PickersDay/PickersDay.js +4 -4
  53. package/legacy/TimeField/TimeField.js +4 -0
  54. package/legacy/TimeField/useTimeField.js +4 -2
  55. package/legacy/index.js +4 -2
  56. package/legacy/internals/hooks/useField/index.js +1 -1
  57. package/legacy/internals/hooks/useField/useField.js +79 -39
  58. package/legacy/internals/hooks/useField/useFieldState.js +1 -8
  59. package/legacy/internals/hooks/usePicker/usePickerValue.js +9 -13
  60. package/legacy/internals/index.js +2 -2
  61. package/legacy/internals/utils/date-utils.js +6 -0
  62. package/legacy/internals/utils/valueManagers.js +3 -8
  63. package/legacy/locales/faIR.js +33 -16
  64. package/legacy/locales/nlNL.js +12 -10
  65. package/legacy/locales/plPL.js +12 -10
  66. package/legacy/models/index.js +1 -0
  67. package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  68. package/locales/faIR.js +13 -16
  69. package/locales/nlNL.js +8 -10
  70. package/locales/plPL.js +8 -10
  71. package/models/index.d.ts +6 -0
  72. package/models/index.js +1 -0
  73. package/models/package.json +6 -0
  74. package/modern/AdapterDateFns/index.js +1 -0
  75. package/modern/AdapterDateFnsJalali/index.js +1 -0
  76. package/modern/AdapterDayjs/index.js +5 -0
  77. package/modern/AdapterLuxon/index.js +1 -0
  78. package/modern/AdapterMoment/index.js +5 -0
  79. package/modern/AdapterMomentHijri/index.js +5 -0
  80. package/modern/AdapterMomentJalaali/index.js +5 -0
  81. package/modern/DateField/DateField.js +4 -0
  82. package/modern/DateField/useDateField.js +5 -3
  83. package/modern/DateTimeField/DateTimeField.js +4 -0
  84. package/modern/DateTimeField/useDateTimeField.js +5 -3
  85. package/modern/PickersDay/PickersDay.js +4 -4
  86. package/modern/TimeField/TimeField.js +4 -0
  87. package/modern/TimeField/useTimeField.js +5 -3
  88. package/modern/index.js +4 -2
  89. package/modern/internals/hooks/useField/index.js +1 -1
  90. package/modern/internals/hooks/useField/useField.js +53 -25
  91. package/modern/internals/hooks/useField/useFieldState.js +1 -6
  92. package/modern/internals/hooks/usePicker/usePickerValue.js +7 -11
  93. package/modern/internals/index.js +2 -2
  94. package/modern/internals/utils/date-utils.js +6 -0
  95. package/modern/internals/utils/valueManagers.js +4 -5
  96. package/modern/locales/faIR.js +13 -16
  97. package/modern/locales/nlNL.js +8 -10
  98. package/modern/locales/plPL.js +8 -10
  99. package/modern/models/index.js +1 -0
  100. package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  101. package/node/AdapterDateFns/index.js +1 -0
  102. package/node/AdapterDateFnsJalali/index.js +1 -0
  103. package/node/AdapterDayjs/index.js +5 -0
  104. package/node/AdapterLuxon/index.js +1 -0
  105. package/node/AdapterMoment/index.js +5 -0
  106. package/node/AdapterMomentHijri/index.js +5 -0
  107. package/node/AdapterMomentJalaali/index.js +5 -0
  108. package/node/DateField/DateField.js +4 -0
  109. package/node/DateField/useDateField.js +5 -3
  110. package/node/DateTimeField/DateTimeField.js +4 -0
  111. package/node/DateTimeField/useDateTimeField.js +5 -3
  112. package/node/PickersDay/PickersDay.js +4 -4
  113. package/node/TimeField/TimeField.js +4 -0
  114. package/node/TimeField/useTimeField.js +5 -3
  115. package/node/index.js +14 -2
  116. package/node/internals/hooks/useField/index.js +0 -6
  117. package/node/internals/hooks/useField/useField.js +52 -24
  118. package/node/internals/hooks/useField/useFieldState.js +1 -6
  119. package/node/internals/hooks/usePicker/usePickerValue.js +7 -11
  120. package/node/internals/index.js +6 -6
  121. package/node/internals/utils/date-utils.js +9 -2
  122. package/node/internals/utils/valueManagers.js +2 -3
  123. package/node/locales/faIR.js +13 -16
  124. package/node/locales/nlNL.js +8 -10
  125. package/node/locales/plPL.js +8 -10
  126. package/node/models/index.js +5 -0
  127. package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  128. package/package.json +2 -2
  129. package/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
@@ -78,6 +78,10 @@ export var AdapterMoment = /*#__PURE__*/function (_BaseAdapterMoment) {
78
78
  start: '[',
79
79
  end: ']'
80
80
  };
81
+ /**
82
+ * The current getFormatHelperText method uses an outdated format parsing logic.
83
+ * We should use this one in the future to support all localized formats.
84
+ */
81
85
  _this.expandFormat = function (format) {
82
86
  // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
83
87
  var localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
@@ -92,6 +96,7 @@ export var AdapterMoment = /*#__PURE__*/function (_BaseAdapterMoment) {
92
96
  _this.getCurrentLocaleCode = function () {
93
97
  return _this.locale || defaultMoment.locale();
94
98
  };
99
+ // Redefined here just to show how it can be written using expandFormat
95
100
  _this.getFormatHelperText = function (format) {
96
101
  return _this.expandFormat(format).replace(/a/gi, '(a|p)m').toLocaleLowerCase();
97
102
  };
@@ -62,6 +62,10 @@ export var AdapterMomentHijri = /*#__PURE__*/function (_BaseAdapterMomentHij) {
62
62
  start: '[',
63
63
  end: ']'
64
64
  };
65
+ /**
66
+ * The current getFormatHelperText method uses an outdated format parsing logic.
67
+ * We should use this one in the future to support all localized formats.
68
+ */
65
69
  _this.expandFormat = function (format) {
66
70
  // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
67
71
  var localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
@@ -73,6 +77,7 @@ export var AdapterMomentHijri = /*#__PURE__*/function (_BaseAdapterMomentHij) {
73
77
  return token;
74
78
  }).join('').replace('dd', 'iDD'); // Fix for https://github.com/dmtrKovalenko/date-io/pull/632
75
79
  };
80
+ // Redefined here just to show how it can be written using expandFormat
76
81
  _this.getFormatHelperText = function (format) {
77
82
  return _this.expandFormat(format).replace(/a/gi, '(a|p)m').replace('iY', 'Y').replace('iM', 'M').replace('iD', 'D').toLocaleLowerCase();
78
83
  };
@@ -59,6 +59,10 @@ export var AdapterMomentJalaali = /*#__PURE__*/function (_BaseAdapterMomentJal)
59
59
  start: '[',
60
60
  end: ']'
61
61
  };
62
+ /**
63
+ * The current getFormatHelperText method uses an outdated format parsing logic.
64
+ * We should use this one in the future to support all localized formats.
65
+ */
62
66
  _this.expandFormat = function (format) {
63
67
  // @see https://github.com/moment/moment/blob/develop/src/lib/format/format.js#L6
64
68
  var localFormattingTokens = /(\[[^[]*\])|(\\)?(LTS|LT|LL?L?L?|l{1,4})|./g;
@@ -70,6 +74,7 @@ export var AdapterMomentJalaali = /*#__PURE__*/function (_BaseAdapterMomentJal)
70
74
  return token;
71
75
  }).join('').replace('dd', 'jDD'); // Fix for https://github.com/dmtrKovalenko/date-io/pull/632;
72
76
  };
77
+ // Redefined here just to show how it can be written using expandFormat
73
78
  _this.getFormatHelperText = function (format) {
74
79
  return _this.expandFormat(format).replace(/a/gi, '(a|p)m').replace('jY', 'Y').replace('jM', 'M').replace('jD', 'D').toLocaleLowerCase();
75
80
  };
@@ -263,6 +263,10 @@ process.env.NODE_ENV !== "production" ? DateField.propTypes = {
263
263
  * The system prop that allows defining system overrides as well as additional CSS styles.
264
264
  */
265
265
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
266
+ /**
267
+ * The ref object used to imperatively interact with the field.
268
+ */
269
+ unstableFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
266
270
  /**
267
271
  * The selected value.
268
272
  * Used when the component is controlled.
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- var _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "selectedSections", "onSelectedSectionsChange"];
3
+ var _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "minDate", "maxDate", "disableFuture", "disablePast", "selectedSections", "onSelectedSectionsChange", "unstableFieldRef"];
4
4
  import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
5
5
  import { useField } from '../internals/hooks/useField';
6
6
  import { validateDate } from '../internals/hooks/validation/useDateValidation';
@@ -37,6 +37,7 @@ export var useDateField = function useDateField(_ref) {
37
37
  disablePast = _useDefaultizedDateFi.disablePast,
38
38
  selectedSections = _useDefaultizedDateFi.selectedSections,
39
39
  onSelectedSectionsChange = _useDefaultizedDateFi.onSelectedSectionsChange,
40
+ unstableFieldRef = _useDefaultizedDateFi.unstableFieldRef,
40
41
  other = _objectWithoutProperties(_useDefaultizedDateFi, _excluded);
41
42
  return useField({
42
43
  inputRef: inputRef,
@@ -56,7 +57,8 @@ export var useDateField = function useDateField(_ref) {
56
57
  disableFuture: disableFuture,
57
58
  disablePast: disablePast,
58
59
  selectedSections: selectedSections,
59
- onSelectedSectionsChange: onSelectedSectionsChange
60
+ onSelectedSectionsChange: onSelectedSectionsChange,
61
+ unstableFieldRef: unstableFieldRef
60
62
  },
61
63
  valueManager: singleItemValueManager,
62
64
  fieldValueManager: singleItemFieldValueManager,
@@ -311,6 +311,10 @@ process.env.NODE_ENV !== "production" ? DateTimeField.propTypes = {
311
311
  * The system prop that allows defining system overrides as well as additional CSS styles.
312
312
  */
313
313
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
314
+ /**
315
+ * The ref object used to imperatively interact with the field.
316
+ */
317
+ unstableFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
314
318
  /**
315
319
  * The selected value.
316
320
  * Used when the component is controlled.
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- var _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"];
3
+ var _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"];
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';
@@ -51,6 +51,7 @@ export var useDateTimeField = function useDateTimeField(_ref) {
51
51
  selectedSections = _useDefaultizedDateTi.selectedSections,
52
52
  onSelectedSectionsChange = _useDefaultizedDateTi.onSelectedSectionsChange,
53
53
  ampm = _useDefaultizedDateTi.ampm,
54
+ unstableFieldRef = _useDefaultizedDateTi.unstableFieldRef,
54
55
  other = _objectWithoutProperties(_useDefaultizedDateTi, _excluded);
55
56
  return useField({
56
57
  inputRef: inputRef,
@@ -77,7 +78,8 @@ export var useDateTimeField = function useDateTimeField(_ref) {
77
78
  disableIgnoringDatePartForTimeValidation: disableIgnoringDatePartForTimeValidation,
78
79
  selectedSections: selectedSections,
79
80
  onSelectedSectionsChange: onSelectedSectionsChange,
80
- ampm: ampm
81
+ ampm: ampm,
82
+ unstableFieldRef: unstableFieldRef
81
83
  },
82
84
  valueManager: singleItemValueManager,
83
85
  fieldValueManager: singleItemFieldValueManager,
@@ -36,16 +36,16 @@ var styleArg = function styleArg(_ref) {
36
36
  height: DAY_SIZE,
37
37
  borderRadius: '50%',
38
38
  padding: 0,
39
- // background required here to prevent collides with the other days when animating with transition group
40
- backgroundColor: (theme.vars || theme).palette.background.paper,
39
+ // explicitly setting to `transparent` to avoid potentially getting impacted by change from the overridden component
40
+ backgroundColor: 'transparent',
41
41
  color: (theme.vars || theme).palette.text.primary,
42
42
  '@media (pointer: fine)': {
43
43
  '&:hover': {
44
- backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.action.activeChannel, " / ").concat(theme.vars.palette.action.hoverOpacity, ")") : alpha(theme.palette.action.active, theme.palette.action.hoverOpacity)
44
+ backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / ").concat(theme.vars.palette.action.hoverOpacity, ")") : alpha(theme.palette.primary.main, theme.palette.action.hoverOpacity)
45
45
  }
46
46
  },
47
47
  '&:focus': _defineProperty({
48
- backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.action.activeChannel, " / ").concat(theme.vars.palette.action.hoverOpacity, ")") : alpha(theme.palette.action.active, theme.palette.action.hoverOpacity)
48
+ backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / ").concat(theme.vars.palette.action.focusOpacity, ")") : alpha(theme.palette.primary.main, theme.palette.action.focusOpacity)
49
49
  }, "&.".concat(pickersDayClasses.selected), {
50
50
  willChange: 'background-color',
51
51
  backgroundColor: (theme.vars || theme).palette.primary.dark
@@ -274,6 +274,10 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
274
274
  * The system prop that allows defining system overrides as well as additional CSS styles.
275
275
  */
276
276
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
277
+ /**
278
+ * The ref object used to imperatively interact with the field.
279
+ */
280
+ unstableFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
277
281
  /**
278
282
  * The selected value.
279
283
  * Used when the component is controlled.
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- var _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm"];
3
+ var _excluded = ["value", "defaultValue", "format", "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';
@@ -37,6 +37,7 @@ export var useTimeField = function useTimeField(_ref) {
37
37
  selectedSections = _useDefaultizedTimeFi.selectedSections,
38
38
  onSelectedSectionsChange = _useDefaultizedTimeFi.onSelectedSectionsChange,
39
39
  ampm = _useDefaultizedTimeFi.ampm,
40
+ unstableFieldRef = _useDefaultizedTimeFi.unstableFieldRef,
40
41
  other = _objectWithoutProperties(_useDefaultizedTimeFi, _excluded);
41
42
  return useField({
42
43
  inputRef: inputRef,
@@ -58,7 +59,8 @@ export var useTimeField = function useTimeField(_ref) {
58
59
  disableIgnoringDatePartForTimeValidation: disableIgnoringDatePartForTimeValidation,
59
60
  selectedSections: selectedSections,
60
61
  onSelectedSectionsChange: onSelectedSectionsChange,
61
- ampm: ampm
62
+ ampm: ampm,
63
+ unstableFieldRef: unstableFieldRef
62
64
  },
63
65
  valueManager: singleItemValueManager,
64
66
  fieldValueManager: singleItemFieldValueManager,
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v6.0.2
2
+ * @mui/x-date-pickers v6.0.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -14,6 +14,7 @@ export * from './locales';
14
14
  export * from './DateField';
15
15
  export * from './TimeField';
16
16
  export * from './DateTimeField';
17
+
17
18
  // Calendars
18
19
  export * from './DateCalendar';
19
20
  export * from './MonthCalendar';
@@ -42,4 +43,5 @@ export * from './timeViewRenderers';
42
43
  export * from './PickersLayout';
43
44
  export * from './PickersActionBar';
44
45
  export * from './PickersShortcuts';
45
- export { DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './internals/utils/utils';
46
+ export { DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './internals/utils/utils';
47
+ export * from './models';
@@ -1,2 +1,2 @@
1
1
  export { useField } from './useField';
2
- export { splitFormatIntoSections, addPositionPropertiesToSections, createDateStrForInputFromSections, getSectionOrder } from './useField.utils';
2
+ export { splitFormatIntoSections, addPositionPropertiesToSections, createDateStrForInputFromSections } from './useField.utils';
@@ -6,9 +6,10 @@ import * as React from 'react';
6
6
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
7
  import useEventCallback from '@mui/utils/useEventCallback';
8
8
  import useForkRef from '@mui/utils/useForkRef';
9
+ import { useTheme } from '@mui/material/styles';
9
10
  import { useValidation } from '../validation/useValidation';
10
11
  import { useUtils } from '../useUtils';
11
- import { adjustSectionValue, isAndroid, cleanString } from './useField.utils';
12
+ import { adjustSectionValue, isAndroid, cleanString, getSectionOrder } from './useField.utils';
12
13
  import { useFieldState } from './useFieldState';
13
14
  import { useFieldCharacterEditing } from './useFieldCharacterEditing';
14
15
  import { getActiveElement } from '../../utils/utils';
@@ -17,13 +18,12 @@ export var useField = function useField(params) {
17
18
  var _useFieldState = useFieldState(params),
18
19
  state = _useFieldState.state,
19
20
  selectedSectionIndexes = _useFieldState.selectedSectionIndexes,
20
- setSelectedSections = _useFieldState.setSelectedSections,
21
+ _setSelectedSections = _useFieldState.setSelectedSections,
21
22
  clearValue = _useFieldState.clearValue,
22
23
  clearActiveSection = _useFieldState.clearActiveSection,
23
24
  updateSectionValue = _useFieldState.updateSectionValue,
24
25
  updateValueFromValueStr = _useFieldState.updateValueFromValueStr,
25
26
  setTempAndroidValueStr = _useFieldState.setTempAndroidValueStr,
26
- sectionOrder = _useFieldState.sectionOrder,
27
27
  sectionsValueBoundaries = _useFieldState.sectionsValueBoundaries;
28
28
  var _useFieldCharacterEdi = useFieldCharacterEditing({
29
29
  sections: state.sections,
@@ -35,8 +35,10 @@ export var useField = function useField(params) {
35
35
  resetCharacterQuery = _useFieldCharacterEdi.resetCharacterQuery;
36
36
  var inputRefProp = params.inputRef,
37
37
  internalProps = params.internalProps,
38
- _params$internalProps = params.internalProps.readOnly,
39
- readOnly = _params$internalProps === void 0 ? false : _params$internalProps,
38
+ _params$internalProps = params.internalProps,
39
+ _params$internalProps2 = _params$internalProps.readOnly,
40
+ readOnly = _params$internalProps2 === void 0 ? false : _params$internalProps2,
41
+ unstableFieldRef = _params$internalProps.unstableFieldRef,
40
42
  _params$forwardedProp = params.forwardedProps,
41
43
  onClick = _params$forwardedProp.onClick,
42
44
  onKeyDown = _params$forwardedProp.onKeyDown,
@@ -52,10 +54,14 @@ export var useField = function useField(params) {
52
54
  var inputRef = React.useRef(null);
53
55
  var handleRef = useForkRef(inputRefProp, inputRef);
54
56
  var focusTimeoutRef = React.useRef(undefined);
57
+ var theme = useTheme();
58
+ var sectionOrder = React.useMemo(function () {
59
+ return getSectionOrder(state.sections, theme.direction === 'rtl');
60
+ }, [theme.direction, state.sections]);
55
61
  var syncSelectionFromDOM = function syncSelectionFromDOM() {
56
62
  var _selectionStart;
57
63
  if (readOnly) {
58
- setSelectedSections(null);
64
+ _setSelectedSections(null);
59
65
  return;
60
66
  }
61
67
  var browserStartIndex = (_selectionStart = inputRef.current.selectionStart) != null ? _selectionStart : 0;
@@ -64,7 +70,7 @@ export var useField = function useField(params) {
64
70
  return section.startInInput - section.startSeparator.length > browserStartIndex;
65
71
  });
66
72
  var sectionIndex = nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
67
- setSelectedSections(sectionIndex);
73
+ _setSelectedSections(sectionIndex);
68
74
  };
69
75
  var handleInputClick = useEventCallback(function () {
70
76
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -98,7 +104,7 @@ export var useField = function useField(params) {
98
104
  if (
99
105
  // avoid selecting all sections when focusing empty field without value
100
106
  input.value.length && Number(input.selectionEnd) - Number(input.selectionStart) === input.value.length) {
101
- setSelectedSections('all');
107
+ _setSelectedSections('all');
102
108
  } else {
103
109
  syncSelectionFromDOM();
104
110
  }
@@ -109,7 +115,7 @@ export var useField = function useField(params) {
109
115
  args[_key3] = arguments[_key3];
110
116
  }
111
117
  onBlur == null ? void 0 : onBlur.apply(void 0, _toConsumableArray(args));
112
- setSelectedSections(null);
118
+ _setSelectedSections(null);
113
119
  });
114
120
  var handleInputPaste = useEventCallback(function (event) {
115
121
  onPaste == null ? void 0 : onPaste(event);
@@ -150,27 +156,32 @@ export var useField = function useField(params) {
150
156
  updateValueFromValueStr(cleanValueStr);
151
157
  return;
152
158
  }
153
- var prevValueStr = cleanString(fieldValueManager.getValueStrFromSections(state.sections));
154
- var startOfDiffIndex = -1;
155
- var endOfDiffIndex = -1;
156
- for (var i = 0; i < prevValueStr.length; i += 1) {
157
- if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
158
- startOfDiffIndex = i;
159
+ var keyPressed;
160
+ if (selectedSectionIndexes.startIndex === 0 && selectedSectionIndexes.endIndex === state.sections.length - 1) {
161
+ keyPressed = cleanValueStr;
162
+ } else {
163
+ var prevValueStr = cleanString(fieldValueManager.getValueStrFromSections(state.sections));
164
+ var startOfDiffIndex = -1;
165
+ var endOfDiffIndex = -1;
166
+ for (var i = 0; i < prevValueStr.length; i += 1) {
167
+ if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
168
+ startOfDiffIndex = i;
169
+ }
170
+ if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
171
+ endOfDiffIndex = i;
172
+ }
159
173
  }
160
- if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
161
- endOfDiffIndex = i;
174
+ var activeSection = state.sections[selectedSectionIndexes.startIndex];
175
+ var hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
176
+ if (hasDiffOutsideOfActiveSection) {
177
+ // TODO: Support if the new date is valid
178
+ return;
162
179
  }
163
- }
164
- var activeSection = state.sections[selectedSectionIndexes.startIndex];
165
- var hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
166
- if (hasDiffOutsideOfActiveSection) {
167
- // TODO: Support if the new date is valid
168
- return;
169
- }
170
180
 
171
- // The active section being selected, the browser has replaced its value with the key pressed by the user.
172
- var activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
173
- var keyPressed = cleanValueStr.slice(activeSection.start, activeSectionEndRelativeToNewValue);
181
+ // The active section being selected, the browser has replaced its value with the key pressed by the user.
182
+ var activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
183
+ keyPressed = cleanValueStr.slice(activeSection.start, activeSectionEndRelativeToNewValue);
184
+ }
174
185
  if (isAndroid() && keyPressed.length === 0) {
175
186
  setTempAndroidValueStr(valueStr);
176
187
  return;
@@ -191,7 +202,7 @@ export var useField = function useField(params) {
191
202
  // prevent default to make sure that the next line "select all" while updating
192
203
  // the internal state at the same time.
193
204
  event.preventDefault();
194
- setSelectedSections('all');
205
+ _setSelectedSections('all');
195
206
  break;
196
207
  }
197
208
 
@@ -200,13 +211,13 @@ export var useField = function useField(params) {
200
211
  {
201
212
  event.preventDefault();
202
213
  if (selectedSectionIndexes == null) {
203
- setSelectedSections(sectionOrder.startIndex);
214
+ _setSelectedSections(sectionOrder.startIndex);
204
215
  } else if (selectedSectionIndexes.startIndex !== selectedSectionIndexes.endIndex) {
205
- setSelectedSections(selectedSectionIndexes.endIndex);
216
+ _setSelectedSections(selectedSectionIndexes.endIndex);
206
217
  } else {
207
218
  var nextSectionIndex = sectionOrder.neighbors[selectedSectionIndexes.startIndex].rightIndex;
208
219
  if (nextSectionIndex !== null) {
209
- setSelectedSections(nextSectionIndex);
220
+ _setSelectedSections(nextSectionIndex);
210
221
  }
211
222
  }
212
223
  break;
@@ -217,13 +228,13 @@ export var useField = function useField(params) {
217
228
  {
218
229
  event.preventDefault();
219
230
  if (selectedSectionIndexes == null) {
220
- setSelectedSections(sectionOrder.endIndex);
231
+ _setSelectedSections(sectionOrder.endIndex);
221
232
  } else if (selectedSectionIndexes.startIndex !== selectedSectionIndexes.endIndex) {
222
- setSelectedSections(selectedSectionIndexes.startIndex);
233
+ _setSelectedSections(selectedSectionIndexes.startIndex);
223
234
  } else {
224
235
  var _nextSectionIndex = sectionOrder.neighbors[selectedSectionIndexes.startIndex].leftIndex;
225
236
  if (_nextSectionIndex !== null) {
226
- setSelectedSections(_nextSectionIndex);
237
+ _setSelectedSections(_nextSectionIndex);
227
238
  }
228
239
  }
229
240
  break;
@@ -266,9 +277,11 @@ export var useField = function useField(params) {
266
277
  });
267
278
  useEnhancedEffect(function () {
268
279
  if (selectedSectionIndexes == null) {
269
- if (inputRef.current.selectionStart !== 0 || inputRef.current.selectionEnd !== 0) {
270
- // Ensure input selection range is in sync with component selection indexes
271
- inputRef.current.setSelectionRange(0, 0);
280
+ if (inputRef.current.scrollLeft) {
281
+ // Ensure that input content is not marked as selected.
282
+ // setting selection range to 0 causes issues in Safari.
283
+ // https://bugs.webkit.org/show_bug.cgi?id=224425
284
+ inputRef.current.scrollLeft = 0;
272
285
  }
273
286
  return;
274
287
  }
@@ -281,7 +294,11 @@ export var useField = function useField(params) {
281
294
  selectionEnd += lastSelectedSection.endSeparator.length;
282
295
  }
283
296
  if (selectionStart !== inputRef.current.selectionStart || selectionEnd !== inputRef.current.selectionEnd) {
297
+ // Fix scroll jumping on iOS browser: https://github.com/mui/mui-x/issues/8321
298
+ var currentScrollTop = inputRef.current.scrollTop;
284
299
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
300
+ // Even reading this variable seems to do the trick, but also setting it just to make use of it
301
+ inputRef.current.scrollTop = currentScrollTop;
285
302
  }
286
303
  });
287
304
  var validationError = useValidation(_extends({}, internalProps, {
@@ -298,7 +315,7 @@ export var useField = function useField(params) {
298
315
  React.useEffect(function () {
299
316
  // Select the right section when focused on mount (`autoFocus = true` on the input)
300
317
  if (inputRef.current && inputRef.current === document.activeElement) {
301
- setSelectedSections('all');
318
+ _setSelectedSections('all');
302
319
  }
303
320
  return function () {
304
321
  return window.clearTimeout(focusTimeoutRef.current);
@@ -330,7 +347,30 @@ export var useField = function useField(params) {
330
347
  return 'tel';
331
348
  }, [selectedSectionIndexes, state.sections]);
332
349
  var inputHasFocus = inputRef.current && inputRef.current === getActiveElement(document);
333
- var shouldShowPlaceholder = !inputHasFocus && (!state.value || valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue));
350
+ var shouldShowPlaceholder = !inputHasFocus && valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue);
351
+ React.useImperativeHandle(unstableFieldRef, function () {
352
+ return {
353
+ getSections: function getSections() {
354
+ return state.sections;
355
+ },
356
+ getActiveSectionIndex: function getActiveSectionIndex() {
357
+ var _selectionStart2, _selectionEnd;
358
+ var browserStartIndex = (_selectionStart2 = inputRef.current.selectionStart) != null ? _selectionStart2 : 0;
359
+ var browserEndIndex = (_selectionEnd = inputRef.current.selectionEnd) != null ? _selectionEnd : 0;
360
+ if (browserStartIndex === 0 && browserEndIndex === 0) {
361
+ return null;
362
+ }
363
+ var nextSectionIndex = browserStartIndex <= state.sections[0].startInInput ? 1 // Special case if browser index is in invisible characters at the beginning.
364
+ : state.sections.findIndex(function (section) {
365
+ return section.startInInput - section.startSeparator.length > browserStartIndex;
366
+ });
367
+ return nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
368
+ },
369
+ setSelectedSections: function setSelectedSections(activeSectionIndex) {
370
+ return _setSelectedSections(activeSectionIndex);
371
+ }
372
+ };
373
+ });
334
374
  return _extends({
335
375
  placeholder: state.placeholder,
336
376
  autoComplete: 'off'
@@ -2,7 +2,6 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import * as React from 'react';
5
- import { useTheme } from '@mui/material/styles';
6
5
  import useControlled from '@mui/utils/useControlled';
7
6
  import { useUtils, useLocaleText, useLocalizationContext } from '../useUtils';
8
7
  import { addPositionPropertiesToSections, splitFormatIntoSections, clampDaySection, mergeDateIntoReferenceDate, getSectionsBoundaries, validateSections, getDateFromDateSections } from './useField.utils';
@@ -11,8 +10,6 @@ export var useFieldState = function useFieldState(params) {
11
10
  var utils = useUtils();
12
11
  var localeText = useLocaleText();
13
12
  var adapter = useLocalizationContext();
14
- var theme = useTheme();
15
- var isRTL = theme.direction === 'rtl';
16
13
  var valueManager = params.valueManager,
17
14
  fieldValueManager = params.fieldValueManager,
18
15
  valueType = params.valueType,
@@ -30,9 +27,6 @@ export var useFieldState = function useFieldState(params) {
30
27
  var sectionsValueBoundaries = React.useMemo(function () {
31
28
  return getSectionsBoundaries(utils);
32
29
  }, [utils]);
33
- var sectionOrder = React.useMemo(function () {
34
- return fieldValueManager.getSectionOrder(utils, localeText, format, isRTL);
35
- }, [fieldValueManager, format, isRTL, localeText, utils]);
36
30
  var placeholder = React.useMemo(function () {
37
31
  return fieldValueManager.getValueStrFromSections(fieldValueManager.getSectionsFromValue(utils, localeText, null, valueManager.emptyValue, format));
38
32
  }, [fieldValueManager, format, localeText, utils, valueManager.emptyValue]);
@@ -246,7 +240,7 @@ export var useFieldState = function useFieldState(params) {
246
240
  };
247
241
  React.useEffect(function () {
248
242
  if (!valueManager.areValuesEqual(utils, state.value, valueFromTheOutside)) {
249
- var sections = fieldValueManager.getSectionsFromValue(utils, localeText, state.sections, valueFromTheOutside, format);
243
+ var sections = fieldValueManager.getSectionsFromValue(utils, localeText, null, valueFromTheOutside, format);
250
244
  setState(function (prevState) {
251
245
  return _extends({}, prevState, {
252
246
  value: valueFromTheOutside,
@@ -277,7 +271,6 @@ export var useFieldState = function useFieldState(params) {
277
271
  updateSectionValue: updateSectionValue,
278
272
  updateValueFromValueStr: updateValueFromValueStr,
279
273
  setTempAndroidValueStr: setTempAndroidValueStr,
280
- sectionOrder: sectionOrder,
281
274
  sectionsValueBoundaries: sectionsValueBoundaries
282
275
  };
283
276
  };
@@ -31,11 +31,8 @@ export var usePickerValue = function usePickerValue(_ref) {
31
31
  state: 'value'
32
32
  }),
33
33
  _useControlled2 = _slicedToArray(_useControlled, 2),
34
- rawValue = _useControlled2[0],
34
+ value = _useControlled2[0],
35
35
  setValue = _useControlled2[1];
36
- var value = React.useMemo(function () {
37
- return valueManager.cleanValue(utils, rawValue);
38
- }, [valueManager, utils, rawValue]);
39
36
  var _useControlled3 = useControlled({
40
37
  controlled: selectedSectionsProp,
41
38
  default: null,
@@ -92,7 +89,7 @@ export var usePickerValue = function usePickerValue(_ref) {
92
89
  }
93
90
  }
94
91
  });
95
- if (params.forceOnChangeCall || !params.skipOnChangeCall && !valueManager.areValuesEqual(utils, dateState.committed, params.value)) {
92
+ if (!params.skipOnChangeCall && !valueManager.areValuesEqual(utils, dateState.committed, params.value)) {
96
93
  setValue(params.value);
97
94
  if (onChange) {
98
95
  var _context = {
@@ -137,18 +134,14 @@ export var usePickerValue = function usePickerValue(_ref) {
137
134
  // Reset all date in state to the empty value and close picker.
138
135
  setDate({
139
136
  value: valueManager.emptyValue,
140
- action: 'acceptAndClose',
141
- // force `onChange` in cases like input (value) === `Invalid date`
142
- forceOnChangeCall: !valueManager.areValuesEqual(utils, value, valueManager.emptyValue)
137
+ action: 'acceptAndClose'
143
138
  });
144
139
  });
145
140
  var handleAccept = useEventCallback(function () {
146
141
  // Set all date in state to equal the current draft value and close picker.
147
142
  setDate({
148
143
  value: dateState.draft,
149
- action: 'acceptAndClose',
150
- // force `onChange` in cases like input (value) === `Invalid date`
151
- forceOnChangeCall: !valueManager.areValuesEqual(utils, dateState.committed, dateState.draft)
144
+ action: 'acceptAndClose'
152
145
  });
153
146
  });
154
147
  var handleDismiss = useEventCallback(function () {
@@ -248,8 +241,11 @@ export var usePickerValue = function usePickerValue(_ref) {
248
241
  selectedSections: selectedSections,
249
242
  onSelectedSectionsChange: handleFieldSelectedSectionsChange
250
243
  };
244
+ var viewValue = React.useMemo(function () {
245
+ return valueManager.cleanValue(utils, dateState.draft);
246
+ }, [utils, valueManager, dateState.draft]);
251
247
  var viewResponse = {
252
- value: dateState.draft,
248
+ value: viewValue,
253
249
  onChange: handleChange,
254
250
  onClose: handleClose,
255
251
  open: isOpen,
@@ -268,7 +264,7 @@ export var usePickerValue = function usePickerValue(_ref) {
268
264
  }) : validationResponse === null;
269
265
  };
270
266
  var layoutResponse = _extends({}, actions, {
271
- value: dateState.draft,
267
+ value: viewValue,
272
268
  onChange: handleChangeAndCommit,
273
269
  isValid: isValid
274
270
  });
@@ -9,7 +9,7 @@ export { pickersArrowSwitcherClasses } from './components/PickersArrowSwitcher/p
9
9
  export { pickersPopperClasses } from './components/pickersPopperClasses';
10
10
  export { PickersToolbarButton } from './components/PickersToolbarButton';
11
11
  export { DAY_MARGIN, DIALOG_WIDTH } from './constants/dimensions';
12
- export { useField, createDateStrForInputFromSections, addPositionPropertiesToSections, splitFormatIntoSections, getSectionOrder } from './hooks/useField';
12
+ export { useField, createDateStrForInputFromSections, addPositionPropertiesToSections, splitFormatIntoSections } from './hooks/useField';
13
13
  export { usePicker } from './hooks/usePicker';
14
14
  export { useStaticPicker } from './hooks/useStaticPicker';
15
15
  export { useLocalizationContext, useDefaultDates, useUtils, useLocaleText, useNow } from './hooks/useUtils';
@@ -18,7 +18,7 @@ export { validateDate } from './hooks/validation/useDateValidation';
18
18
  export { validateTime } from './hooks/validation/useTimeValidation';
19
19
  export { validateDateTime } from './hooks/validation/useDateTimeValidation';
20
20
  export { usePreviousMonthDisabled, useNextMonthDisabled } from './hooks/date-helpers-hooks';
21
- export { applyDefaultDate, replaceInvalidDateByNull } from './utils/date-utils';
21
+ export { applyDefaultDate, replaceInvalidDateByNull, areDatesEqual } from './utils/date-utils';
22
22
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './utils/utils';
23
23
  export { defaultReduceAnimations } from './utils/defaultReduceAnimations';
24
24
  export { extractValidationProps } from './utils/validation';
@@ -64,4 +64,10 @@ export var applyDefaultDate = function applyDefaultDate(utils, value, defaultVal
64
64
  return defaultValue;
65
65
  }
66
66
  return value;
67
+ };
68
+ export var areDatesEqual = function areDatesEqual(utils, a, b) {
69
+ if (!utils.isValid(a) && a != null && !utils.isValid(b) && b != null) {
70
+ return true;
71
+ }
72
+ return utils.isEqual(a, b);
67
73
  };
@@ -1,14 +1,12 @@
1
- import { replaceInvalidDateByNull } from './date-utils';
2
- import { addPositionPropertiesToSections, createDateStrForInputFromSections, splitFormatIntoSections, getSectionOrder as _getSectionOrder } from '../hooks/useField/useField.utils';
1
+ import { areDatesEqual, replaceInvalidDateByNull } from './date-utils';
2
+ import { addPositionPropertiesToSections, createDateStrForInputFromSections, splitFormatIntoSections } from '../hooks/useField/useField.utils';
3
3
  export var singleItemValueManager = {
4
4
  emptyValue: null,
5
5
  getTodayValue: function getTodayValue(utils) {
6
6
  return utils.date();
7
7
  },
8
8
  cleanValue: replaceInvalidDateByNull,
9
- areValuesEqual: function areValuesEqual(utils, a, b) {
10
- return utils.isEqual(a, b);
11
- },
9
+ areValuesEqual: areDatesEqual,
12
10
  isSameError: function isSameError(a, b) {
13
11
  return a === b;
14
12
  },
@@ -48,8 +46,5 @@ export var singleItemFieldValueManager = {
48
46
  },
49
47
  hasError: function hasError(error) {
50
48
  return error != null;
51
- },
52
- getSectionOrder: function getSectionOrder(utils, localeText, format, isRTL) {
53
- return _getSectionOrder(splitFormatIntoSections(utils, localeText, format, null), isRTL);
54
49
  }
55
50
  };