@mui/x-date-pickers 7.19.0 → 7.21.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 (125) hide show
  1. package/AdapterDayjs/AdapterDayjs.js +2 -0
  2. package/CHANGELOG.md +224 -43
  3. package/DateCalendar/DateCalendar.js +1 -1
  4. package/DateCalendar/DateCalendar.types.d.ts +1 -1
  5. package/DateField/DateField.types.d.ts +2 -7
  6. package/DateField/index.d.ts +1 -1
  7. package/DatePicker/DatePicker.js +1 -1
  8. package/DatePicker/DatePicker.types.d.ts +8 -1
  9. package/DatePicker/index.d.ts +1 -1
  10. package/DateTimeField/DateTimeField.types.d.ts +2 -7
  11. package/DateTimeField/index.d.ts +1 -1
  12. package/DateTimePicker/DateTimePicker.js +1 -1
  13. package/DateTimePicker/DateTimePicker.types.d.ts +9 -1
  14. package/DateTimePicker/DateTimePickerTabs.js +1 -1
  15. package/DateTimePicker/index.d.ts +1 -1
  16. package/DesktopDatePicker/DesktopDatePicker.js +1 -1
  17. package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  18. package/DigitalClock/DigitalClock.js +33 -0
  19. package/MobileDatePicker/MobileDatePicker.js +1 -1
  20. package/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  21. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
  22. package/PickersSectionList/PickersSectionList.d.ts +9 -0
  23. package/PickersSectionList/PickersSectionList.js +30 -9
  24. package/StaticDatePicker/StaticDatePicker.js +1 -1
  25. package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  26. package/TimeClock/Clock.js +8 -0
  27. package/TimeField/TimeField.types.d.ts +2 -7
  28. package/TimeField/index.d.ts +1 -1
  29. package/TimePicker/TimePicker.types.d.ts +9 -1
  30. package/TimePicker/index.d.ts +1 -1
  31. package/hooks/index.d.ts +2 -0
  32. package/hooks/index.js +3 -1
  33. package/hooks/useParsedFormat.d.ts +15 -0
  34. package/hooks/useParsedFormat.js +43 -0
  35. package/hooks/usePickersContext.d.ts +4 -0
  36. package/hooks/usePickersContext.js +15 -0
  37. package/index.js +1 -1
  38. package/internals/components/PickersProvider.d.ts +34 -0
  39. package/internals/components/PickersProvider.js +26 -0
  40. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -10
  41. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +2 -5
  42. package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -2
  43. package/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
  44. package/internals/hooks/useField/useField.js +1 -1
  45. package/internals/hooks/useField/useField.utils.d.ts +3 -3
  46. package/internals/hooks/useField/useField.utils.js +13 -13
  47. package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  48. package/internals/hooks/useField/useFieldState.js +3 -5
  49. package/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
  50. package/internals/hooks/usePicker/usePicker.js +10 -1
  51. package/internals/hooks/usePicker/usePicker.types.d.ts +2 -1
  52. package/internals/hooks/usePicker/usePickerOwnerState.d.ts +9 -0
  53. package/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
  54. package/internals/hooks/usePicker/usePickerValue.js +7 -2
  55. package/internals/hooks/usePicker/usePickerValue.types.d.ts +2 -0
  56. package/internals/index.d.ts +1 -0
  57. package/internals/index.js +1 -0
  58. package/internals/utils/utils.d.ts +7 -0
  59. package/internals/utils/utils.js +11 -0
  60. package/models/pickers.d.ts +19 -1
  61. package/modern/AdapterDayjs/AdapterDayjs.js +2 -0
  62. package/modern/DateCalendar/DateCalendar.js +1 -1
  63. package/modern/DatePicker/DatePicker.js +1 -1
  64. package/modern/DateTimePicker/DateTimePicker.js +1 -1
  65. package/modern/DateTimePicker/DateTimePickerTabs.js +1 -1
  66. package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -1
  67. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  68. package/modern/DigitalClock/DigitalClock.js +33 -0
  69. package/modern/MobileDatePicker/MobileDatePicker.js +1 -1
  70. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  71. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
  72. package/modern/PickersSectionList/PickersSectionList.js +30 -9
  73. package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
  74. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  75. package/modern/TimeClock/Clock.js +8 -0
  76. package/modern/hooks/index.js +3 -1
  77. package/modern/hooks/useParsedFormat.js +43 -0
  78. package/modern/hooks/usePickersContext.js +15 -0
  79. package/modern/index.js +1 -1
  80. package/modern/internals/components/PickersProvider.js +26 -0
  81. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +9 -10
  82. package/modern/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
  83. package/modern/internals/hooks/useField/useField.js +1 -1
  84. package/modern/internals/hooks/useField/useField.utils.js +13 -13
  85. package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  86. package/modern/internals/hooks/useField/useFieldState.js +3 -5
  87. package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
  88. package/modern/internals/hooks/usePicker/usePicker.js +10 -1
  89. package/modern/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
  90. package/modern/internals/hooks/usePicker/usePickerValue.js +7 -2
  91. package/modern/internals/index.js +1 -0
  92. package/modern/internals/utils/utils.js +11 -0
  93. package/node/AdapterDayjs/AdapterDayjs.js +2 -0
  94. package/node/DateCalendar/DateCalendar.js +1 -1
  95. package/node/DatePicker/DatePicker.js +1 -1
  96. package/node/DateTimePicker/DateTimePicker.js +1 -1
  97. package/node/DateTimePicker/DateTimePickerTabs.js +1 -1
  98. package/node/DesktopDatePicker/DesktopDatePicker.js +1 -1
  99. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
  100. package/node/DigitalClock/DigitalClock.js +33 -0
  101. package/node/MobileDatePicker/MobileDatePicker.js +1 -1
  102. package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  103. package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +32 -1
  104. package/node/PickersSectionList/PickersSectionList.js +30 -9
  105. package/node/StaticDatePicker/StaticDatePicker.js +1 -1
  106. package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  107. package/node/TimeClock/Clock.js +8 -0
  108. package/node/hooks/index.js +15 -1
  109. package/node/hooks/useParsedFormat.js +50 -0
  110. package/node/hooks/usePickersContext.js +21 -0
  111. package/node/index.js +1 -1
  112. package/node/internals/components/PickersProvider.js +34 -0
  113. package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +7 -9
  114. package/node/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
  115. package/node/internals/hooks/useField/useField.js +1 -1
  116. package/node/internals/hooks/useField/useField.utils.js +13 -13
  117. package/node/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  118. package/node/internals/hooks/useField/useFieldState.js +3 -5
  119. package/node/internals/hooks/useMobilePicker/useMobilePicker.js +5 -3
  120. package/node/internals/hooks/usePicker/usePicker.js +10 -1
  121. package/node/internals/hooks/usePicker/usePickerOwnerState.js +20 -0
  122. package/node/internals/hooks/usePicker/usePickerValue.js +7 -1
  123. package/node/internals/index.js +7 -0
  124. package/node/internals/utils/utils.js +13 -1
  125. package/package.json +4 -4
@@ -206,7 +206,7 @@ const useFieldCharacterEditing = ({
206
206
  // When editing a letter-format month and the user presses a digit,
207
207
  // We can support the numeric editing by using the digit-format month and re-formatting the result.
208
208
  if (activeSection.type === 'month') {
209
- const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils, timezone, 'digit', 'month', 'MM');
209
+ const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils, 'digit', 'month', 'MM');
210
210
  const response = getNewSectionValue(queryValue, {
211
211
  type: activeSection.type,
212
212
  format: 'MM',
@@ -231,7 +231,7 @@ const useFieldCharacterEditing = ({
231
231
  if (isQueryResponseWithoutValue(response)) {
232
232
  return response;
233
233
  }
234
- const formattedValue = (0, _useField.getDaysInWeekStr)(utils, timezone, activeSection.format)[Number(response.sectionValue) - 1];
234
+ const formattedValue = (0, _useField.getDaysInWeekStr)(utils, activeSection.format)[Number(response.sectionValue) - 1];
235
235
  return (0, _extends2.default)({}, response, {
236
236
  sectionValue: formattedValue
237
237
  });
@@ -56,7 +56,6 @@ const useFieldState = params => {
56
56
  const sectionsValueBoundaries = React.useMemo(() => (0, _useField.getSectionsBoundaries)(utils, localizedDigits, timezone), [utils, localizedDigits, timezone]);
57
57
  const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, date => (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
58
58
  utils,
59
- timezone,
60
59
  localeText: translations,
61
60
  localizedDigits,
62
61
  format,
@@ -65,7 +64,7 @@ const useFieldState = params => {
65
64
  shouldRespectLeadingZeros,
66
65
  enableAccessibleFieldDOMStructure,
67
66
  isRtl
68
- })), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, timezone, enableAccessibleFieldDOMStructure]);
67
+ })), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, enableAccessibleFieldDOMStructure]);
69
68
  const [state, setState] = React.useState(() => {
70
69
  const sections = getSectionsFromValue(valueFromTheOutside);
71
70
  (0, _useField.validateSections)(sections, valueType);
@@ -162,7 +161,6 @@ const useFieldState = params => {
162
161
  }
163
162
  const sections = (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
164
163
  utils,
165
- timezone,
166
164
  localeText: translations,
167
165
  localizedDigits,
168
166
  format,
@@ -172,7 +170,7 @@ const useFieldState = params => {
172
170
  enableAccessibleFieldDOMStructure,
173
171
  isRtl
174
172
  });
175
- return (0, _useField.mergeDateIntoReferenceDate)(utils, timezone, date, sections, referenceDate, false);
173
+ return (0, _useField.mergeDateIntoReferenceDate)(utils, date, sections, referenceDate, false);
176
174
  };
177
175
  const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
178
176
  const newReferenceValue = fieldValueManager.updateReferenceValue(utils, newValue, state.referenceValue);
@@ -210,7 +208,7 @@ const useFieldState = params => {
210
208
  * This makes sure that we don't lose some information of the initial date (like the time on a date field).
211
209
  */
212
210
  if (newActiveDate != null && utils.isValid(newActiveDate)) {
213
- const mergedDate = (0, _useField.mergeDateIntoReferenceDate)(utils, timezone, newActiveDate, newActiveDateSections, activeDateManager.referenceDate, true);
211
+ const mergedDate = (0, _useField.mergeDateIntoReferenceDate)(utils, newActiveDate, newActiveDateSections, activeDateManager.referenceDate, true);
214
212
  values = activeDateManager.getNewValuesFromNewActiveDate(mergedDate);
215
213
  shouldPublish = true;
216
214
  } else {
@@ -15,8 +15,8 @@ var _useId = _interopRequireDefault(require("@mui/utils/useId"));
15
15
  var _PickersModalDialog = require("../../components/PickersModalDialog");
16
16
  var _usePicker = require("../usePicker");
17
17
  var _utils = require("../../utils/utils");
18
- var _LocalizationProvider = require("../../../LocalizationProvider");
19
18
  var _PickersLayout = require("../../../PickersLayout");
19
+ var _PickersProvider = require("../../components/PickersProvider");
20
20
  var _jsxRuntime = require("react/jsx-runtime");
21
21
  const _excluded = ["props", "getOpenDialogAriaText"];
22
22
  /**
@@ -57,7 +57,8 @@ const useMobilePicker = _ref => {
57
57
  actions,
58
58
  layoutProps,
59
59
  renderCurrentView,
60
- fieldProps: pickerFieldProps
60
+ fieldProps: pickerFieldProps,
61
+ contextValue
61
62
  } = (0, _usePicker.usePicker)((0, _extends2.default)({}, pickerParams, {
62
63
  props,
63
64
  fieldRef,
@@ -118,7 +119,8 @@ const useMobilePicker = _ref => {
118
119
  }, innerSlotProps?.mobilePaper)
119
120
  });
120
121
  const handleFieldRef = (0, _useForkRef.default)(fieldRef, fieldProps.unstableFieldRef);
121
- const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_LocalizationProvider.LocalizationProvider, {
122
+ const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_PickersProvider.PickersProvider, {
123
+ contextValue: contextValue,
122
124
  localeText: localeText,
123
125
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({}, fieldProps, {
124
126
  slots: slotsForField,
@@ -8,6 +8,7 @@ var _warning = require("@mui/x-internals/warning");
8
8
  var _usePickerValue = require("./usePickerValue");
9
9
  var _usePickerViews = require("./usePickerViews");
10
10
  var _usePickerLayoutProps = require("./usePickerLayoutProps");
11
+ var _usePickerOwnerState = require("./usePickerOwnerState");
11
12
  const usePicker = ({
12
13
  props,
13
14
  valueManager,
@@ -45,6 +46,10 @@ const usePicker = ({
45
46
  propsFromPickerValue: pickerValueResponse.layoutProps,
46
47
  propsFromPickerViews: pickerViewsResponse.layoutProps
47
48
  });
49
+ const pickerOwnerState = (0, _usePickerOwnerState.usePickerOwnerState)({
50
+ props,
51
+ pickerValueResponse
52
+ });
48
53
  return {
49
54
  // Picker value
50
55
  open: pickerValueResponse.open,
@@ -55,7 +60,11 @@ const usePicker = ({
55
60
  hasUIView: pickerViewsResponse.hasUIView,
56
61
  shouldRestoreFocus: pickerViewsResponse.shouldRestoreFocus,
57
62
  // Picker layout
58
- layoutProps: pickerLayoutResponse.layoutProps
63
+ layoutProps: pickerLayoutResponse.layoutProps,
64
+ // Picker context
65
+ contextValue: pickerValueResponse.contextValue,
66
+ // Picker owner state
67
+ ownerState: pickerOwnerState
59
68
  };
60
69
  };
61
70
  exports.usePicker = usePicker;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.usePickerOwnerState = usePickerOwnerState;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ function usePickerOwnerState(parameters) {
10
+ const {
11
+ props,
12
+ pickerValueResponse
13
+ } = parameters;
14
+ return React.useMemo(() => ({
15
+ value: pickerValueResponse.viewProps.value,
16
+ open: pickerValueResponse.open,
17
+ disabled: props.disabled ?? false,
18
+ readOnly: props.readOnly ?? false
19
+ }), [pickerValueResponse.viewProps.value, pickerValueResponse.open, props.disabled, props.readOnly]);
20
+ }
@@ -341,12 +341,18 @@ const usePickerValue = ({
341
341
  onSelectShortcut: handleSelectShortcut,
342
342
  isValid
343
343
  });
344
+ const contextValue = React.useMemo(() => ({
345
+ onOpen: handleOpen,
346
+ onClose: handleClose,
347
+ open: isOpen
348
+ }), [isOpen, handleClose, handleOpen]);
344
349
  return {
345
350
  open: isOpen,
346
351
  fieldProps: fieldResponse,
347
352
  viewProps: viewResponse,
348
353
  layoutProps: layoutResponse,
349
- actions
354
+ actions,
355
+ contextValue
350
356
  };
351
357
  };
352
358
  exports.usePickerValue = usePickerValue;
@@ -45,6 +45,12 @@ Object.defineProperty(exports, "PickersPopper", {
45
45
  return _PickersPopper.PickersPopper;
46
46
  }
47
47
  });
48
+ Object.defineProperty(exports, "PickersProvider", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _PickersProvider.PickersProvider;
52
+ }
53
+ });
48
54
  Object.defineProperty(exports, "PickersToolbar", {
49
55
  enumerable: true,
50
56
  get: function () {
@@ -304,6 +310,7 @@ Object.defineProperty(exports, "useViews", {
304
310
  }
305
311
  });
306
312
  var _PickersArrowSwitcher = require("./components/PickersArrowSwitcher/PickersArrowSwitcher");
313
+ var _PickersProvider = require("./components/PickersProvider");
307
314
  var _PickersModalDialog = require("./components/PickersModalDialog");
308
315
  var _PickersPopper = require("./components/PickersPopper");
309
316
  var _PickersToolbar = require("./components/PickersToolbar");
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DEFAULT_DESKTOP_MODE_MEDIA_QUERY = void 0;
7
7
  exports.arrayIncludes = arrayIncludes;
8
- exports.onSpaceOrEnter = exports.getActiveElement = exports.executeInTheNextEventLoopTick = void 0;
8
+ exports.onSpaceOrEnter = exports.getFocusedListItemIndex = exports.getActiveElement = exports.executeInTheNextEventLoopTick = void 0;
9
9
  /* Use it instead of .includes method for IE support */
10
10
  function arrayIncludes(array, itemOrItems) {
11
11
  if (Array.isArray(itemOrItems)) {
@@ -42,5 +42,17 @@ const getActiveElement = (root = document) => {
42
42
  }
43
43
  return activeEl;
44
44
  };
45
+
46
+ /**
47
+ * Gets the index of the focused list item in a given ul list element.
48
+ *
49
+ * @param {HTMLUListElement} listElement - The list element to search within.
50
+ * @returns {number} The index of the focused list item, or -1 if none is focused.
51
+ */
45
52
  exports.getActiveElement = getActiveElement;
53
+ const getFocusedListItemIndex = listElement => {
54
+ const children = Array.from(listElement.children);
55
+ return children.indexOf(getActiveElement(document));
56
+ };
57
+ exports.getFocusedListItemIndex = getFocusedListItemIndex;
46
58
  const DEFAULT_DESKTOP_MODE_MEDIA_QUERY = exports.DEFAULT_DESKTOP_MODE_MEDIA_QUERY = '@media (pointer: fine)';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-date-pickers",
3
- "version": "7.19.0",
3
+ "version": "7.21.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",
@@ -35,13 +35,13 @@
35
35
  "directory": "packages/x-date-pickers"
36
36
  },
37
37
  "dependencies": {
38
- "@babel/runtime": "^7.25.6",
39
- "@mui/utils": "^5.16.6",
38
+ "@babel/runtime": "^7.25.7",
39
+ "@mui/utils": "^5.16.6 || ^6.0.0",
40
40
  "@types/react-transition-group": "^4.4.11",
41
41
  "clsx": "^2.1.1",
42
42
  "prop-types": "^15.8.1",
43
43
  "react-transition-group": "^4.4.5",
44
- "@mui/x-internals": "7.18.0"
44
+ "@mui/x-internals": "7.21.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@emotion/react": "^11.9.0",