@mui/x-date-pickers 7.20.0 → 7.22.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 (44) hide show
  1. package/AdapterDayjs/AdapterDayjs.js +2 -0
  2. package/CHANGELOG.md +200 -31
  3. package/DateCalendar/DayCalendar.js +3 -4
  4. package/DateCalendar/useCalendarState.d.ts +3 -1
  5. package/DateCalendar/useCalendarState.js +27 -2
  6. package/DigitalClock/DigitalClock.js +10 -12
  7. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +2 -8
  8. package/PickersSectionList/PickersSectionList.d.ts +9 -0
  9. package/PickersSectionList/PickersSectionList.js +30 -9
  10. package/index.js +1 -1
  11. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +3 -7
  12. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +2 -5
  13. package/internals/hooks/useField/useField.js +1 -1
  14. package/internals/hooks/usePicker/usePicker.js +8 -1
  15. package/internals/hooks/usePicker/usePicker.types.d.ts +2 -1
  16. package/internals/hooks/usePicker/usePickerOwnerState.d.ts +9 -0
  17. package/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
  18. package/internals/utils/utils.js +2 -2
  19. package/models/pickers.d.ts +18 -0
  20. package/modern/AdapterDayjs/AdapterDayjs.js +2 -0
  21. package/modern/DateCalendar/DayCalendar.js +3 -4
  22. package/modern/DateCalendar/useCalendarState.js +27 -2
  23. package/modern/DigitalClock/DigitalClock.js +10 -12
  24. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +2 -8
  25. package/modern/PickersSectionList/PickersSectionList.js +30 -9
  26. package/modern/index.js +1 -1
  27. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +3 -7
  28. package/modern/internals/hooks/useField/useField.js +1 -1
  29. package/modern/internals/hooks/usePicker/usePicker.js +8 -1
  30. package/modern/internals/hooks/usePicker/usePickerOwnerState.js +13 -0
  31. package/modern/internals/utils/utils.js +2 -2
  32. package/node/AdapterDayjs/AdapterDayjs.js +2 -0
  33. package/node/DateCalendar/DayCalendar.js +3 -4
  34. package/node/DateCalendar/useCalendarState.js +27 -2
  35. package/node/DigitalClock/DigitalClock.js +10 -12
  36. package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +2 -8
  37. package/node/PickersSectionList/PickersSectionList.js +30 -9
  38. package/node/index.js +1 -1
  39. package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +3 -7
  40. package/node/internals/hooks/useField/useField.js +1 -1
  41. package/node/internals/hooks/usePicker/usePicker.js +8 -1
  42. package/node/internals/hooks/usePicker/usePickerOwnerState.js +20 -0
  43. package/node/internals/utils/utils.js +2 -2
  44. package/package.json +2 -2
@@ -239,21 +239,22 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
239
239
  return !containsValidTime() || !isValidValue();
240
240
  }, [disableIgnoringDatePartForTimeValidation, utils, minTime, maxTime, disableFuture, now, disablePast, minutesStep, shouldDisableTime]);
241
241
  const timeOptions = React.useMemo(() => {
242
+ const result = [];
242
243
  const startOfDay = utils.startOfDay(valueOrReferenceDate);
243
- return [startOfDay, ...Array.from({
244
- length: Math.ceil(24 * 60 / timeStep) - 1
245
- }, (_, index) => utils.addMinutes(startOfDay, timeStep * (index + 1)))];
244
+ let nextTimeStepOption = startOfDay;
245
+ while (utils.isSameDay(valueOrReferenceDate, nextTimeStepOption)) {
246
+ result.push(nextTimeStepOption);
247
+ nextTimeStepOption = utils.addMinutes(nextTimeStepOption, timeStep);
248
+ }
249
+ return result;
246
250
  }, [valueOrReferenceDate, timeStep, utils]);
247
251
  const focusedOptionIndex = timeOptions.findIndex(option => utils.isEqual(option, valueOrReferenceDate));
248
252
  const handleKeyDown = event => {
249
253
  switch (event.key) {
250
254
  case 'PageUp':
251
255
  {
252
- if (!listRef.current) {
253
- return;
254
- }
255
256
  const newIndex = (0, _utils.getFocusedListItemIndex)(listRef.current) - 5;
256
- const children = listRef.current?.children;
257
+ const children = listRef.current.children;
257
258
  const newFocusedIndex = Math.max(0, newIndex);
258
259
  const childToFocus = children[newFocusedIndex];
259
260
  if (childToFocus) {
@@ -264,11 +265,8 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
264
265
  }
265
266
  case 'PageDown':
266
267
  {
267
- if (!listRef.current) {
268
- return;
269
- }
270
268
  const newIndex = (0, _utils.getFocusedListItemIndex)(listRef.current) + 5;
271
- const children = listRef.current?.children;
269
+ const children = listRef.current.children;
272
270
  const newFocusedIndex = Math.min(children.length - 1, newIndex);
273
271
  const childToFocus = children[newFocusedIndex];
274
272
  if (childToFocus) {
@@ -311,7 +309,7 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
311
309
  tabIndex: tabIndex
312
310
  }, clockItemProps, {
313
311
  children: formattedValue
314
- }), formattedValue);
312
+ }), `${option.valueOf()}-${formattedValue}`);
315
313
  })
316
314
  })
317
315
  }));
@@ -151,11 +151,8 @@ const MultiSectionDigitalClockSection = exports.MultiSectionDigitalClockSection
151
151
  switch (event.key) {
152
152
  case 'PageUp':
153
153
  {
154
- if (!containerRef.current) {
155
- return;
156
- }
157
154
  const newIndex = (0, _utils.getFocusedListItemIndex)(containerRef.current) - 5;
158
- const children = containerRef.current?.children;
155
+ const children = containerRef.current.children;
159
156
  const newFocusedIndex = Math.max(0, newIndex);
160
157
  const childToFocus = children[newFocusedIndex];
161
158
  if (childToFocus) {
@@ -166,11 +163,8 @@ const MultiSectionDigitalClockSection = exports.MultiSectionDigitalClockSection
166
163
  }
167
164
  case 'PageDown':
168
165
  {
169
- if (!containerRef.current) {
170
- return;
171
- }
172
166
  const newIndex = (0, _utils.getFocusedListItemIndex)(containerRef.current) + 5;
173
- const children = containerRef.current?.children;
167
+ const children = containerRef.current.children;
174
168
  const newFocusedIndex = Math.min(children.length - 1, newIndex);
175
169
  const childToFocus = children[newFocusedIndex];
176
170
  if (childToFocus) {
@@ -56,15 +56,6 @@ const useUtilityClasses = ownerState => {
56
56
  };
57
57
  return (0, _composeClasses.default)(slots, _pickersSectionListClasses.getPickersSectionListUtilityClass, classes);
58
58
  };
59
- /**
60
- * Demos:
61
- *
62
- * - [Custom field](https://mui.com/x/react-date-pickers/custom-field/)
63
- *
64
- * API:
65
- *
66
- * - [PickersSectionList API](https://mui.com/x/api/date-pickers/pickers-section-list/)
67
- */
68
59
  function PickersSection(props) {
69
60
  const {
70
61
  slots,
@@ -112,6 +103,36 @@ function PickersSection(props) {
112
103
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SectionSeparator, (0, _extends2.default)({}, sectionSeparatorBeforeProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(SectionContent, (0, _extends2.default)({}, sectionContentProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(SectionSeparator, (0, _extends2.default)({}, sectionSeparatorAfterProps))]
113
104
  }));
114
105
  }
106
+ process.env.NODE_ENV !== "production" ? PickersSection.propTypes = {
107
+ // ----------------------------- Warning --------------------------------
108
+ // | These PropTypes are generated from the TypeScript type definitions |
109
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
110
+ // ----------------------------------------------------------------------
111
+ classes: _propTypes.default.object.isRequired,
112
+ element: _propTypes.default.shape({
113
+ after: _propTypes.default.object.isRequired,
114
+ before: _propTypes.default.object.isRequired,
115
+ container: _propTypes.default.object.isRequired,
116
+ content: _propTypes.default.object.isRequired
117
+ }).isRequired,
118
+ /**
119
+ * The props used for each component slot.
120
+ */
121
+ slotProps: _propTypes.default.object,
122
+ /**
123
+ * Overridable component slots.
124
+ */
125
+ slots: _propTypes.default.object
126
+ } : void 0;
127
+ /**
128
+ * Demos:
129
+ *
130
+ * - [Custom field](https://mui.com/x/react-date-pickers/custom-field/)
131
+ *
132
+ * API:
133
+ *
134
+ * - [PickersSectionList API](https://mui.com/x/api/date-pickers/pickers-section-list/)
135
+ */
115
136
  const PickersSectionList = exports.PickersSectionList = /*#__PURE__*/React.forwardRef(function PickersSectionList(inProps, ref) {
116
137
  const props = (0, _styles.useThemeProps)({
117
138
  props: inProps,
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v7.20.0
2
+ * @mui/x-date-pickers v7.22.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -66,7 +66,8 @@ const useDesktopPicker = _ref => {
66
66
  renderCurrentView,
67
67
  shouldRestoreFocus,
68
68
  fieldProps: pickerFieldProps,
69
- contextValue
69
+ contextValue,
70
+ ownerState
70
71
  } = (0, _usePicker.usePicker)((0, _extends2.default)({}, pickerParams, {
71
72
  props,
72
73
  fieldRef,
@@ -74,11 +75,6 @@ const useDesktopPicker = _ref => {
74
75
  additionalViewProps: {},
75
76
  wrapperVariant: 'desktop'
76
77
  }));
77
-
78
- // TODO v8: Apply this ownerState to all the slots in this hook.
79
- const ownerStateV8 = {
80
- open
81
- };
82
78
  const InputAdornment = slots.inputAdornment ?? _InputAdornment.default;
83
79
  const _useSlotProps = (0, _useSlotProps3.default)({
84
80
  elementType: InputAdornment,
@@ -106,7 +102,7 @@ const useDesktopPicker = _ref => {
106
102
  const openPickerIconProps = (0, _useSlotProps3.default)({
107
103
  elementType: OpenPickerIcon,
108
104
  externalSlotProps: innerSlotProps?.openPickerIcon,
109
- ownerState: ownerStateV8
105
+ ownerState
110
106
  });
111
107
  const Field = slots.field;
112
108
  const fieldProps = (0, _useSlotProps3.default)({
@@ -83,7 +83,7 @@ const useField = params => {
83
83
  // eslint-disable-next-line default-case
84
84
  switch (true) {
85
85
  // Select all
86
- case (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'a' && !event.shiftKey && !event.altKey:
86
+ case (event.ctrlKey || event.metaKey) && String.fromCharCode(event.keyCode) === 'A' && !event.shiftKey && !event.altKey:
87
87
  {
88
88
  // prevent default to make sure that the next line "select all" while updating
89
89
  // the internal state at the same time.
@@ -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,
@@ -57,7 +62,9 @@ const usePicker = ({
57
62
  // Picker layout
58
63
  layoutProps: pickerLayoutResponse.layoutProps,
59
64
  // Picker context
60
- contextValue: pickerValueResponse.contextValue
65
+ contextValue: pickerValueResponse.contextValue,
66
+ // Picker owner state
67
+ ownerState: pickerOwnerState
61
68
  };
62
69
  };
63
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
+ }
@@ -51,8 +51,8 @@ const getActiveElement = (root = document) => {
51
51
  */
52
52
  exports.getActiveElement = getActiveElement;
53
53
  const getFocusedListItemIndex = listElement => {
54
- const children = listElement.children;
55
- return Array.from(children).findIndex(child => child === getActiveElement(document));
54
+ const children = Array.from(listElement.children);
55
+ return children.indexOf(getActiveElement(document));
56
56
  };
57
57
  exports.getFocusedListItemIndex = getFocusedListItemIndex;
58
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.20.0",
3
+ "version": "7.22.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",
@@ -41,7 +41,7 @@
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.20.0"
44
+ "@mui/x-internals": "7.21.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@emotion/react": "^11.9.0",