@mui/x-date-pickers 7.8.0 → 7.10.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 (87) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/DateCalendar/DayCalendar.js +7 -6
  3. package/DatePicker/DatePickerToolbar.js +4 -3
  4. package/DateTimePicker/DateTimePickerTabs.d.ts +2 -1
  5. package/DateTimePicker/DateTimePickerTabs.js +4 -4
  6. package/DateTimePicker/DateTimePickerToolbar.js +4 -3
  7. package/DesktopDatePicker/DesktopDatePicker.js +4 -3
  8. package/DesktopDateTimePicker/DesktopDateTimePicker.js +4 -3
  9. package/DesktopTimePicker/DesktopTimePicker.js +4 -3
  10. package/DigitalClock/DigitalClock.js +4 -3
  11. package/MobileDatePicker/MobileDatePicker.js +4 -3
  12. package/MobileDateTimePicker/MobileDateTimePicker.js +4 -3
  13. package/MobileTimePicker/MobileTimePicker.js +4 -3
  14. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +8 -7
  15. package/PickersActionBar/PickersActionBar.js +6 -6
  16. package/PickersCalendarHeader/PickersCalendarHeader.js +6 -5
  17. package/TimeClock/Clock.js +4 -3
  18. package/TimeClock/TimeClock.js +9 -8
  19. package/TimePicker/TimePickerToolbar.js +4 -3
  20. package/hooks/index.d.ts +1 -0
  21. package/hooks/index.js +2 -1
  22. package/hooks/useClearableField.js +3 -3
  23. package/hooks/usePickersTranslations.d.ts +2 -0
  24. package/hooks/usePickersTranslations.js +2 -0
  25. package/index.js +1 -1
  26. package/internals/hooks/useField/useFieldState.js +6 -5
  27. package/internals/hooks/useField/useFieldV6TextField.js +10 -9
  28. package/internals/hooks/useField/useFieldV7TextField.js +7 -9
  29. package/internals/hooks/useUtils.d.ts +0 -1
  30. package/internals/hooks/useUtils.js +0 -1
  31. package/internals/index.d.ts +2 -2
  32. package/internals/index.js +2 -2
  33. package/internals/utils/date-time-utils.d.ts +1 -1
  34. package/internals/utils/validation/extractValidationProps.d.ts +1 -1
  35. package/modern/DateCalendar/DayCalendar.js +7 -6
  36. package/modern/DatePicker/DatePickerToolbar.js +4 -3
  37. package/modern/DateTimePicker/DateTimePickerTabs.js +4 -4
  38. package/modern/DateTimePicker/DateTimePickerToolbar.js +4 -3
  39. package/modern/DesktopDatePicker/DesktopDatePicker.js +4 -3
  40. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +4 -3
  41. package/modern/DesktopTimePicker/DesktopTimePicker.js +4 -3
  42. package/modern/DigitalClock/DigitalClock.js +4 -3
  43. package/modern/MobileDatePicker/MobileDatePicker.js +4 -3
  44. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +4 -3
  45. package/modern/MobileTimePicker/MobileTimePicker.js +4 -3
  46. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +8 -7
  47. package/modern/PickersActionBar/PickersActionBar.js +6 -6
  48. package/modern/PickersCalendarHeader/PickersCalendarHeader.js +6 -5
  49. package/modern/TimeClock/Clock.js +4 -3
  50. package/modern/TimeClock/TimeClock.js +9 -8
  51. package/modern/TimePicker/TimePickerToolbar.js +4 -3
  52. package/modern/hooks/index.js +2 -1
  53. package/modern/hooks/useClearableField.js +3 -3
  54. package/modern/hooks/usePickersTranslations.js +2 -0
  55. package/modern/index.js +1 -1
  56. package/modern/internals/hooks/useField/useFieldState.js +6 -5
  57. package/modern/internals/hooks/useField/useFieldV6TextField.js +10 -9
  58. package/modern/internals/hooks/useField/useFieldV7TextField.js +7 -9
  59. package/modern/internals/hooks/useUtils.js +0 -1
  60. package/modern/internals/index.js +2 -2
  61. package/node/DateCalendar/DayCalendar.js +6 -5
  62. package/node/DatePicker/DatePickerToolbar.js +3 -2
  63. package/node/DateTimePicker/DateTimePickerTabs.js +4 -4
  64. package/node/DateTimePicker/DateTimePickerToolbar.js +3 -2
  65. package/node/DesktopDatePicker/DesktopDatePicker.js +3 -2
  66. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -2
  67. package/node/DesktopTimePicker/DesktopTimePicker.js +3 -2
  68. package/node/DigitalClock/DigitalClock.js +3 -2
  69. package/node/MobileDatePicker/MobileDatePicker.js +3 -2
  70. package/node/MobileDateTimePicker/MobileDateTimePicker.js +3 -2
  71. package/node/MobileTimePicker/MobileTimePicker.js +3 -2
  72. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +7 -6
  73. package/node/PickersActionBar/PickersActionBar.js +6 -6
  74. package/node/PickersCalendarHeader/PickersCalendarHeader.js +5 -4
  75. package/node/TimeClock/Clock.js +3 -2
  76. package/node/TimeClock/TimeClock.js +8 -7
  77. package/node/TimePicker/TimePickerToolbar.js +3 -2
  78. package/node/hooks/index.js +8 -1
  79. package/node/hooks/useClearableField.js +3 -3
  80. package/node/hooks/usePickersTranslations.js +9 -0
  81. package/node/index.js +1 -1
  82. package/node/internals/hooks/useField/useFieldState.js +5 -4
  83. package/node/internals/hooks/useField/useFieldV6TextField.js +10 -9
  84. package/node/internals/hooks/useField/useFieldV7TextField.js +6 -8
  85. package/node/internals/hooks/useUtils.js +1 -3
  86. package/node/internals/index.js +6 -6
  87. package/package.json +3 -3
@@ -9,6 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  var React = _interopRequireWildcard(require("react"));
10
10
  var _useControlled = _interopRequireDefault(require("@mui/utils/useControlled"));
11
11
  var _RtlProvider = require("@mui/system/RtlProvider");
12
+ var _usePickersTranslations = require("../../../hooks/usePickersTranslations");
12
13
  var _useUtils = require("../useUtils");
13
14
  var _useField = require("./useField.utils");
14
15
  var _buildSectionsFromFormat = require("./buildSectionsFromFormat");
@@ -18,7 +19,7 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
18
19
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
20
  const useFieldState = params => {
20
21
  const utils = (0, _useUtils.useUtils)();
21
- const localeText = (0, _useUtils.useLocaleText)();
22
+ const translations = (0, _usePickersTranslations.usePickersTranslations)();
22
23
  const adapter = (0, _useUtils.useLocalizationContext)();
23
24
  const isRtl = (0, _RtlProvider.useRtl)();
24
25
  const {
@@ -57,7 +58,7 @@ const useFieldState = params => {
57
58
  const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, date => (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
58
59
  utils,
59
60
  timezone,
60
- localeText,
61
+ localeText: translations,
61
62
  localizedDigits,
62
63
  format,
63
64
  date,
@@ -65,7 +66,7 @@ const useFieldState = params => {
65
66
  shouldRespectLeadingZeros,
66
67
  enableAccessibleFieldDOMStructure,
67
68
  isRtl
68
- })), [fieldValueManager, format, localeText, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, timezone, enableAccessibleFieldDOMStructure]);
69
+ })), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, timezone, enableAccessibleFieldDOMStructure]);
69
70
  const [state, setState] = React.useState(() => {
70
71
  const sections = getSectionsFromValue(valueFromTheOutside);
71
72
  (0, _useField.validateSections)(sections, valueType);
@@ -165,7 +166,7 @@ const useFieldState = params => {
165
166
  const sections = (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
166
167
  utils,
167
168
  timezone,
168
- localeText,
169
+ localeText: translations,
169
170
  localizedDigits,
170
171
  format,
171
172
  date,
@@ -46,6 +46,7 @@ exports.addPositionPropertiesToSections = addPositionPropertiesToSections;
46
46
  const useFieldV6TextField = params => {
47
47
  const isRtl = (0, _RtlProvider.useRtl)();
48
48
  const focusTimeoutRef = React.useRef();
49
+ const selectionSyncTimeoutRef = React.useRef();
49
50
  const {
50
51
  forwardedProps: {
51
52
  onFocus,
@@ -113,10 +114,14 @@ const useFieldV6TextField = params => {
113
114
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
114
115
  }
115
116
  }
116
- setTimeout(() => {
117
+ clearTimeout(selectionSyncTimeoutRef.current);
118
+ selectionSyncTimeoutRef.current = setTimeout(() => {
117
119
  // handle case when the selection is not updated correctly
118
120
  // could happen on Android
119
- if (inputRef.current && inputRef.current === (0, _utils.getActiveElement)(document) && (inputRef.current.selectionStart !== selectionStart || inputRef.current.selectionEnd !== selectionEnd)) {
121
+ if (inputRef.current && inputRef.current === (0, _utils.getActiveElement)(document) &&
122
+ // The section might loose all selection, where `selectionStart === selectionEnd`
123
+ // https://github.com/mui/mui-x/pull/13652
124
+ inputRef.current.selectionStart === inputRef.current.selectionEnd && (inputRef.current.selectionStart !== selectionStart || inputRef.current.selectionEnd !== selectionEnd)) {
120
125
  interactions.syncSelectionToDOM();
121
126
  }
122
127
  });
@@ -128,8 +133,7 @@ const useFieldV6TextField = params => {
128
133
  getActiveSectionIndexFromDOM: () => {
129
134
  const browserStartIndex = inputRef.current.selectionStart ?? 0;
130
135
  const browserEndIndex = inputRef.current.selectionEnd ?? 0;
131
- const isInputReadOnly = !!inputRef.current?.readOnly;
132
- if (browserStartIndex === 0 && browserEndIndex === 0 || isInputReadOnly) {
136
+ if (browserStartIndex === 0 && browserEndIndex === 0) {
133
137
  return null;
134
138
  }
135
139
  const nextSectionIndex = browserStartIndex <= sections[0].startInInput ? 1 // Special case if browser index is in invisible characters at the beginning.
@@ -144,10 +148,6 @@ const useFieldV6TextField = params => {
144
148
  isFieldFocused: () => inputRef.current === (0, _utils.getActiveElement)(document)
145
149
  }), [inputRef, parsedSelectedSections, sections, setSelectedSections]);
146
150
  const syncSelectionFromDOM = () => {
147
- if (readOnly) {
148
- setSelectedSections(null);
149
- return;
150
- }
151
151
  const browserStartIndex = inputRef.current.selectionStart ?? 0;
152
152
  let nextSectionIndex;
153
153
  if (browserStartIndex <= sections[0].startInInput) {
@@ -172,7 +172,7 @@ const useFieldV6TextField = params => {
172
172
  if (!input || input !== inputRef.current) {
173
173
  return;
174
174
  }
175
- if (activeSectionIndex != null || readOnly) {
175
+ if (activeSectionIndex != null) {
176
176
  return;
177
177
  }
178
178
  if (
@@ -306,6 +306,7 @@ const useFieldV6TextField = params => {
306
306
  }
307
307
  return () => {
308
308
  clearTimeout(focusTimeoutRef.current);
309
+ clearTimeout(selectionSyncTimeoutRef.current);
309
310
  };
310
311
  }, []); // eslint-disable-line react-hooks/exhaustive-deps
311
312
 
@@ -12,6 +12,7 @@ var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedE
12
12
  var _useId = _interopRequireDefault(require("@mui/utils/useId"));
13
13
  var _useField = require("./useField.utils");
14
14
  var _utils = require("../../utils/utils");
15
+ var _usePickersTranslations = require("../../../hooks/usePickersTranslations");
15
16
  var _useUtils = require("../useUtils");
16
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -47,7 +48,7 @@ const useFieldV7TextField = params => {
47
48
  } = params;
48
49
  const sectionListRef = React.useRef(null);
49
50
  const handleSectionListRef = (0, _useForkRef.default)(inSectionListRef, sectionListRef);
50
- const localeText = (0, _useUtils.useLocaleText)();
51
+ const translations = (0, _usePickersTranslations.usePickersTranslations)();
51
52
  const utils = (0, _useUtils.useUtils)();
52
53
  const id = (0, _useId.default)();
53
54
  const [focused, setFocused] = React.useState(false);
@@ -229,7 +230,7 @@ const useFieldV7TextField = params => {
229
230
  const getInputContainerClickHandler = (0, _useEventCallback.default)(sectionIndex => event => {
230
231
  // The click event on the clear button would propagate to the input, trigger this handler and result in a wrong section selection.
231
232
  // We avoid this by checking if the call to this function is actually intended, or a side effect.
232
- if (event.isDefaultPrevented() || readOnly) {
233
+ if (event.isDefaultPrevented()) {
233
234
  return;
234
235
  }
235
236
  setSelectedSections(sectionIndex);
@@ -239,9 +240,6 @@ const useFieldV7TextField = params => {
239
240
  event.preventDefault();
240
241
  });
241
242
  const getInputContentFocusHandler = (0, _useEventCallback.default)(sectionIndex => () => {
242
- if (readOnly) {
243
- return;
244
- }
245
243
  setSelectedSections(sectionIndex);
246
244
  });
247
245
  const handleInputContentPaste = (0, _useEventCallback.default)(event => {
@@ -350,8 +348,8 @@ const useFieldV7TextField = params => {
350
348
  'aria-valuenow': (0, _useField.getSectionValueNow)(section, utils),
351
349
  'aria-valuemin': sectionBoundaries[section.type].minimum,
352
350
  'aria-valuemax': sectionBoundaries[section.type].maximum,
353
- 'aria-valuetext': section.value ? (0, _useField.getSectionValueText)(section, utils) : localeText.empty,
354
- 'aria-label': localeText[section.type],
351
+ 'aria-valuetext': section.value ? (0, _useField.getSectionValueText)(section, utils) : translations.empty,
352
+ 'aria-label': translations[section.type],
355
353
  'aria-disabled': disabled,
356
354
  spellCheck: isEditable ? false : undefined,
357
355
  autoCapitalize: isEditable ? 'off' : undefined,
@@ -373,7 +371,7 @@ const useFieldV7TextField = params => {
373
371
  }
374
372
  };
375
373
  });
376
- }, [state.sections, getInputContentFocusHandler, handleInputContentPaste, handleInputContentDragOver, handleInputContentInput, getInputContainerClickHandler, handleInputContentMouseUp, disabled, readOnly, isContainerEditable, localeText, utils, sectionBoundaries, id]);
374
+ }, [state.sections, getInputContentFocusHandler, handleInputContentPaste, handleInputContentDragOver, handleInputContentInput, getInputContainerClickHandler, handleInputContentMouseUp, disabled, readOnly, isContainerEditable, translations, utils, sectionBoundaries, id]);
377
375
  const handleValueStrChange = (0, _useEventCallback.default)(event => {
378
376
  updateValueFromValueStr(event.target.value);
379
377
  });
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.useUtils = exports.useNow = exports.useLocalizationContext = exports.useLocaleText = exports.useDefaultDates = void 0;
7
+ exports.useUtils = exports.useNow = exports.useLocalizationContext = exports.useDefaultDates = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var React = _interopRequireWildcard(require("react"));
10
10
  var _LocalizationProvider = require("../../LocalizationProvider/LocalizationProvider");
@@ -29,8 +29,6 @@ const useUtils = () => useLocalizationContext().utils;
29
29
  exports.useUtils = useUtils;
30
30
  const useDefaultDates = () => useLocalizationContext().defaultDates;
31
31
  exports.useDefaultDates = useDefaultDates;
32
- const useLocaleText = () => useLocalizationContext().localeText;
33
- exports.useLocaleText = useLocaleText;
34
32
  const useNow = timezone => {
35
33
  const utils = useUtils();
36
34
  const now = React.useRef();
@@ -213,6 +213,12 @@ Object.defineProperty(exports, "replaceInvalidDateByNull", {
213
213
  return _dateUtils.replaceInvalidDateByNull;
214
214
  }
215
215
  });
216
+ Object.defineProperty(exports, "resolveDateTimeFormat", {
217
+ enumerable: true,
218
+ get: function () {
219
+ return _dateTimeUtils.resolveDateTimeFormat;
220
+ }
221
+ });
216
222
  Object.defineProperty(exports, "resolveTimeViewsResponse", {
217
223
  enumerable: true,
218
224
  get: function () {
@@ -273,12 +279,6 @@ Object.defineProperty(exports, "useField", {
273
279
  return _useField.useField;
274
280
  }
275
281
  });
276
- Object.defineProperty(exports, "useLocaleText", {
277
- enumerable: true,
278
- get: function () {
279
- return _useUtils.useLocaleText;
280
- }
281
- });
282
282
  Object.defineProperty(exports, "useLocalizationContext", {
283
283
  enumerable: true,
284
284
  get: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-date-pickers",
3
- "version": "7.8.0",
3
+ "version": "7.10.0",
4
4
  "description": "The community edition of the Date and Time Picker components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@babel/runtime": "^7.24.7",
39
39
  "@mui/base": "^5.0.0-beta.40",
40
- "@mui/system": "^5.15.20",
41
- "@mui/utils": "^5.15.20",
40
+ "@mui/system": "^5.16.0",
41
+ "@mui/utils": "^5.16.0",
42
42
  "@types/react-transition-group": "^4.4.10",
43
43
  "clsx": "^2.1.1",
44
44
  "prop-types": "^15.8.1",