@mui/x-date-pickers 8.0.0-alpha.10 → 8.0.0-alpha.11

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.
@@ -15,7 +15,7 @@ var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
15
15
  var _useSlotProps2 = _interopRequireDefault(require("@mui/utils/useSlotProps"));
16
16
  var _RtlProvider = require("@mui/system/RtlProvider");
17
17
  var _styles = require("@mui/material/styles");
18
- var _utils = require("@mui/utils");
18
+ var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
19
19
  var _clsx = _interopRequireDefault(require("clsx"));
20
20
  var _PickersDay = require("../PickersDay/PickersDay");
21
21
  var _usePickerTranslations = require("../hooks/usePickerTranslations");
@@ -27,7 +27,7 @@ var _dateUtils = require("../internals/utils/date-utils");
27
27
  var _dayCalendarClasses = require("./dayCalendarClasses");
28
28
  var _usePickerPrivateContext = require("../internals/hooks/usePickerPrivateContext");
29
29
  var _jsxRuntime = require("react/jsx-runtime");
30
- const _excluded = ["parentProps", "day", "focusableDay", "selectedDays", "isDateDisabled", "currentMonthNumber", "isViewFocused"],
30
+ const _excluded = ["parentProps", "day", "focusedDay", "selectedDays", "isDateDisabled", "currentMonthNumber", "isViewFocused"],
31
31
  _excluded2 = ["ownerState"];
32
32
  const useUtilityClasses = classes => {
33
33
  const slots = {
@@ -41,7 +41,7 @@ const useUtilityClasses = classes => {
41
41
  weekNumberLabel: ['weekNumberLabel'],
42
42
  weekNumber: ['weekNumber']
43
43
  };
44
- return (0, _utils.unstable_composeClasses)(slots, _dayCalendarClasses.getDayCalendarUtilityClass, classes);
44
+ return (0, _composeClasses.default)(slots, _dayCalendarClasses.getDayCalendarUtilityClass, classes);
45
45
  };
46
46
  const weeksContainerHeight = (_dimensions.DAY_SIZE + _dimensions.DAY_MARGIN * 2) * 6;
47
47
  const PickersCalendarDayRoot = (0, _styles.styled)('div', {
@@ -144,7 +144,7 @@ function WrappedDay(_ref) {
144
144
  let {
145
145
  parentProps,
146
146
  day,
147
- focusableDay,
147
+ focusedDay,
148
148
  selectedDays,
149
149
  isDateDisabled,
150
150
  currentMonthNumber,
@@ -165,7 +165,8 @@ function WrappedDay(_ref) {
165
165
  const {
166
166
  ownerState
167
167
  } = (0, _usePickerPrivateContext.usePickerPrivateContext)();
168
- const isFocusableDay = focusableDay !== null && utils.isSameDay(day, focusableDay);
168
+ const isFocusableDay = focusedDay != null && utils.isSameDay(day, focusedDay);
169
+ const isFocusedDay = isViewFocused && isFocusableDay;
169
170
  const isSelected = selectedDays.some(selectedDay => utils.isSameDay(selectedDay, day));
170
171
  const isToday = utils.isSameDay(day, now);
171
172
  const isDisabled = React.useMemo(() => disabled || isDateDisabled(day), [disabled, isDateDisabled, day]);
@@ -207,7 +208,7 @@ function WrappedDay(_ref) {
207
208
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Day, (0, _extends2.default)({}, dayProps, {
208
209
  day: day,
209
210
  disabled: isDisabled,
210
- autoFocus: isViewFocused && isFocusableDay,
211
+ autoFocus: !outsideCurrentMonth && isFocusedDay,
211
212
  today: isToday,
212
213
  outsideCurrentMonth: outsideCurrentMonth,
213
214
  isFirstVisibleCell: isFirstVisibleCell,
@@ -258,7 +259,6 @@ function DayCalendar(inProps) {
258
259
  gridLabelId,
259
260
  displayWeekNumber,
260
261
  fixedWeekNumber,
261
- autoFocus,
262
262
  timezone
263
263
  } = props;
264
264
  const now = (0, _useUtils.useNow)(timezone);
@@ -275,13 +275,6 @@ function DayCalendar(inProps) {
275
275
  timezone
276
276
  });
277
277
  const translations = (0, _usePickerTranslations.usePickerTranslations)();
278
- const [internalHasFocus, setInternalHasFocus] = (0, _utils.unstable_useControlled)({
279
- name: 'DayCalendar',
280
- state: 'hasFocus',
281
- controlled: hasFocus,
282
- default: autoFocus ?? false
283
- });
284
- const [internalFocusedDay, setInternalFocusedDay] = React.useState(() => focusedDay || now);
285
278
  const handleDaySelect = (0, _useEventCallback.default)(day => {
286
279
  if (readOnly) {
287
280
  return;
@@ -291,9 +284,7 @@ function DayCalendar(inProps) {
291
284
  const focusDay = day => {
292
285
  if (!isDateDisabled(day)) {
293
286
  onFocusedDayChange(day);
294
- setInternalFocusedDay(day);
295
287
  onFocusedViewChange?.(true);
296
- setInternalHasFocus(true);
297
288
  }
298
289
  };
299
290
  const handleKeyDown = (0, _useEventCallback.default)((event, day) => {
@@ -360,7 +351,7 @@ function DayCalendar(inProps) {
360
351
  });
361
352
  const handleFocus = (0, _useEventCallback.default)((event, day) => focusDay(day));
362
353
  const handleBlur = (0, _useEventCallback.default)((event, day) => {
363
- if (internalHasFocus && utils.isSameDay(internalFocusedDay, day)) {
354
+ if (focusedDay != null && utils.isSameDay(focusedDay, day)) {
364
355
  onFocusedViewChange?.(false);
365
356
  }
366
357
  });
@@ -372,23 +363,6 @@ function DayCalendar(inProps) {
372
363
  const transitionKey = `${currentYearNumber}-${currentMonthNumber}`;
373
364
  // eslint-disable-next-line react-hooks/exhaustive-deps
374
365
  const slideNodeRef = React.useMemo(() => /*#__PURE__*/React.createRef(), [transitionKey]);
375
- const focusableDay = React.useMemo(() => {
376
- const startOfMonth = utils.startOfMonth(currentMonth);
377
- const endOfMonth = utils.endOfMonth(currentMonth);
378
- if (isDateDisabled(internalFocusedDay) || utils.isAfterDay(internalFocusedDay, endOfMonth) || utils.isBeforeDay(internalFocusedDay, startOfMonth)) {
379
- return (0, _dateUtils.findClosestEnabledDate)({
380
- utils,
381
- date: internalFocusedDay,
382
- minDate: startOfMonth,
383
- maxDate: endOfMonth,
384
- disablePast,
385
- disableFuture,
386
- isDateDisabled,
387
- timezone
388
- });
389
- }
390
- return internalFocusedDay;
391
- }, [currentMonth, disableFuture, disablePast, internalFocusedDay, isDateDisabled, utils, timezone]);
392
366
  const weeksToDisplay = React.useMemo(() => {
393
367
  const toDisplay = utils.getWeekArray(currentMonth);
394
368
  let nextMonth = utils.addMonths(currentMonth, 1);
@@ -455,14 +429,14 @@ function DayCalendar(inProps) {
455
429
  parentProps: props,
456
430
  day: day,
457
431
  selectedDays: validSelectedDays,
458
- focusableDay: focusableDay,
432
+ isViewFocused: hasFocus,
433
+ focusedDay: focusedDay,
459
434
  onKeyDown: handleKeyDown,
460
435
  onFocus: handleFocus,
461
436
  onBlur: handleBlur,
462
437
  onDaySelect: handleDaySelect,
463
438
  isDateDisabled: isDateDisabled,
464
- currentMonthNumber: currentMonthNumber,
465
- isViewFocused: internalHasFocus
439
+ currentMonthNumber: currentMonthNumber
466
440
  // fix issue of announcing column 1 as column 2 when `displayWeekNumber` is enabled
467
441
  ,
468
442
  "aria-colindex": dayIndex + 1
@@ -6,7 +6,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
6
6
  Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
- exports.useCalendarState = exports.createCalendarStateReducer = void 0;
9
+ exports.useCalendarState = void 0;
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
  var React = _interopRequireWildcard(require("react"));
12
12
  var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
@@ -14,13 +14,15 @@ var _useIsDateDisabled = require("./useIsDateDisabled");
14
14
  var _useUtils = require("../internals/hooks/useUtils");
15
15
  var _valueManagers = require("../internals/utils/valueManagers");
16
16
  var _getDefaultReferenceDate = require("../internals/utils/getDefaultReferenceDate");
17
- const createCalendarStateReducer = (reduceAnimations, disableSwitchToMonthOnDayFocus, utils) => (state, action) => {
17
+ var _dateUtils = require("../internals/utils/date-utils");
18
+ const createCalendarStateReducer = (reduceAnimations, utils) => (state, action) => {
18
19
  switch (action.type) {
19
- case 'changeMonth':
20
+ case 'setVisibleDate':
20
21
  return (0, _extends2.default)({}, state, {
21
22
  slideDirection: action.direction,
22
- currentMonth: action.newMonth,
23
- isMonthSwitchingAnimating: !reduceAnimations
23
+ currentMonth: action.month,
24
+ isMonthSwitchingAnimating: !utils.isSameMonth(action.month, state.currentMonth) && !reduceAnimations && !action.skipAnimation,
25
+ focusedDay: action.focusedDay
24
26
  });
25
27
  case 'changeMonthTimezone':
26
28
  {
@@ -40,40 +42,27 @@ const createCalendarStateReducer = (reduceAnimations, disableSwitchToMonthOnDayF
40
42
  return (0, _extends2.default)({}, state, {
41
43
  isMonthSwitchingAnimating: false
42
44
  });
43
- case 'changeFocusedDay':
44
- {
45
- if (state.focusedDay != null && action.focusedDay != null && utils.isSameDay(action.focusedDay, state.focusedDay)) {
46
- return state;
47
- }
48
- const needMonthSwitch = action.focusedDay != null && !disableSwitchToMonthOnDayFocus && !utils.isSameMonth(state.currentMonth, action.focusedDay);
49
- return (0, _extends2.default)({}, state, {
50
- focusedDay: action.focusedDay,
51
- isMonthSwitchingAnimating: needMonthSwitch && !reduceAnimations && !action.withoutMonthSwitchingAnimation,
52
- currentMonth: needMonthSwitch ? utils.startOfMonth(action.focusedDay) : state.currentMonth,
53
- slideDirection: action.focusedDay != null && utils.isAfterDay(action.focusedDay, state.currentMonth) ? 'left' : 'right'
54
- });
55
- }
56
45
  default:
57
46
  throw new Error('missing support');
58
47
  }
59
48
  };
60
- exports.createCalendarStateReducer = createCalendarStateReducer;
61
49
  const useCalendarState = params => {
62
50
  const {
63
51
  value,
64
52
  referenceDate: referenceDateProp,
65
53
  disableFuture,
66
54
  disablePast,
67
- disableSwitchToMonthOnDayFocus = false,
68
55
  maxDate,
69
56
  minDate,
70
57
  onMonthChange,
58
+ onYearChange,
71
59
  reduceAnimations,
72
60
  shouldDisableDate,
73
- timezone
61
+ timezone,
62
+ getCurrentMonthFromVisibleDate
74
63
  } = params;
75
64
  const utils = (0, _useUtils.useUtils)();
76
- const reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations), disableSwitchToMonthOnDayFocus, utils)).current;
65
+ const reducerFn = React.useRef(createCalendarStateReducer(Boolean(reduceAnimations), utils)).current;
77
66
  const referenceDate = React.useMemo(() => {
78
67
  return _valueManagers.singleItemValueManager.getInitialReferenceValue({
79
68
  value,
@@ -93,6 +82,14 @@ const useCalendarState = params => {
93
82
  currentMonth: utils.startOfMonth(referenceDate),
94
83
  slideDirection: 'left'
95
84
  });
85
+ const isDateDisabled = (0, _useIsDateDisabled.useIsDateDisabled)({
86
+ shouldDisableDate,
87
+ minDate,
88
+ maxDate,
89
+ disableFuture,
90
+ disablePast,
91
+ timezone
92
+ });
96
93
 
97
94
  // Ensure that `calendarState.currentMonth` timezone is updated when `referenceDate` (or timezone changes)
98
95
  // https://github.com/mui/mui-x/issues/10804
@@ -102,54 +99,66 @@ const useCalendarState = params => {
102
99
  newTimezone: utils.getTimezone(referenceDate)
103
100
  });
104
101
  }, [referenceDate, utils]);
105
- const handleChangeMonth = React.useCallback(payload => {
106
- dispatch((0, _extends2.default)({
107
- type: 'changeMonth'
108
- }, payload));
109
- if (onMonthChange) {
110
- onMonthChange(payload.newMonth);
111
- }
112
- }, [onMonthChange]);
113
- const changeMonth = React.useCallback(newDate => {
114
- const newDateRequested = newDate;
115
- if (utils.isSameMonth(newDateRequested, calendarState.currentMonth)) {
102
+ const setVisibleDate = (0, _useEventCallback.default)(({
103
+ target,
104
+ reason
105
+ }) => {
106
+ if (reason === 'cell-interaction' && calendarState.focusedDay != null && utils.isSameDay(target, calendarState.focusedDay)) {
116
107
  return;
117
108
  }
118
- handleChangeMonth({
119
- newMonth: utils.startOfMonth(newDateRequested),
120
- direction: utils.isAfterDay(newDateRequested, calendarState.currentMonth) ? 'left' : 'right'
109
+ const skipAnimation = reason === 'cell-interaction';
110
+ let month;
111
+ let focusedDay;
112
+ if (reason === 'cell-interaction') {
113
+ month = getCurrentMonthFromVisibleDate(target, calendarState.currentMonth);
114
+ focusedDay = target;
115
+ } else {
116
+ month = utils.isSameMonth(target, calendarState.currentMonth) ? calendarState.currentMonth : utils.startOfMonth(target);
117
+ focusedDay = target;
118
+
119
+ // If the date is disabled, we try to find a non-disabled date inside the same month.
120
+ if (isDateDisabled(focusedDay)) {
121
+ const startOfMonth = utils.startOfMonth(target);
122
+ const endOfMonth = utils.endOfMonth(target);
123
+ focusedDay = (0, _dateUtils.findClosestEnabledDate)({
124
+ utils,
125
+ date: focusedDay,
126
+ minDate: utils.isBefore(minDate, startOfMonth) ? startOfMonth : minDate,
127
+ maxDate: utils.isAfter(maxDate, endOfMonth) ? endOfMonth : maxDate,
128
+ disablePast,
129
+ disableFuture,
130
+ isDateDisabled,
131
+ timezone
132
+ });
133
+ }
134
+ }
135
+ const hasChangedMonth = !utils.isSameMonth(calendarState.currentMonth, month);
136
+ const hasChangedYear = !utils.isSameYear(calendarState.currentMonth, month);
137
+ if (hasChangedMonth) {
138
+ onMonthChange?.(month);
139
+ }
140
+ if (hasChangedYear) {
141
+ onYearChange?.(utils.startOfYear(month));
142
+ }
143
+ dispatch({
144
+ type: 'setVisibleDate',
145
+ month,
146
+ direction: utils.isAfterDay(month, calendarState.currentMonth) ? 'left' : 'right',
147
+ focusedDay: calendarState.focusedDay != null && focusedDay != null && utils.isSameDay(focusedDay, calendarState.focusedDay) ? calendarState.focusedDay : focusedDay,
148
+ skipAnimation
121
149
  });
122
- }, [calendarState.currentMonth, handleChangeMonth, utils]);
123
- const isDateDisabled = (0, _useIsDateDisabled.useIsDateDisabled)({
124
- shouldDisableDate,
125
- minDate,
126
- maxDate,
127
- disableFuture,
128
- disablePast,
129
- timezone
130
150
  });
131
151
  const onMonthSwitchingAnimationEnd = React.useCallback(() => {
132
152
  dispatch({
133
153
  type: 'finishMonthSwitchingAnimation'
134
154
  });
135
155
  }, []);
136
- const changeFocusedDay = (0, _useEventCallback.default)((newFocusedDate, withoutMonthSwitchingAnimation) => {
137
- if (!isDateDisabled(newFocusedDate)) {
138
- dispatch({
139
- type: 'changeFocusedDay',
140
- focusedDay: newFocusedDate,
141
- withoutMonthSwitchingAnimation
142
- });
143
- }
144
- });
145
156
  return {
146
157
  referenceDate,
147
158
  calendarState,
148
- changeMonth,
149
- changeFocusedDay,
159
+ setVisibleDate,
150
160
  isDateDisabled,
151
- onMonthSwitchingAnimationEnd,
152
- handleChangeMonth
161
+ onMonthSwitchingAnimationEnd
153
162
  };
154
163
  };
155
164
  exports.useCalendarState = useCalendarState;
@@ -166,8 +166,8 @@ const PickersCalendarHeader = exports.PickersCalendarHeader = /*#__PURE__*/React
166
166
  className: classes.switchViewIcon
167
167
  }),
168
168
  switchViewIconProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps, _excluded2);
169
- const selectNextMonth = () => onMonthChange(utils.addMonths(month, 1), 'left');
170
- const selectPreviousMonth = () => onMonthChange(utils.addMonths(month, -1), 'right');
169
+ const selectNextMonth = () => onMonthChange(utils.addMonths(month, 1));
170
+ const selectPreviousMonth = () => onMonthChange(utils.addMonths(month, -1));
171
171
  const isNextMonthDisabled = (0, _dateHelpersHooks.useNextMonthDisabled)(month, {
172
172
  disableFuture,
173
173
  maxDate,
@@ -120,7 +120,8 @@ const PickersInputBaseSection = (0, _styles.styled)(_PickersSectionList.Unstable
120
120
  letterSpacing: 'inherit',
121
121
  lineHeight: '1.4375em',
122
122
  // 23px
123
- display: 'flex'
123
+ display: 'inline-block',
124
+ whiteSpace: 'nowrap'
124
125
  }));
125
126
  const PickersInputBaseSectionContent = (0, _styles.styled)(_PickersSectionList.Unstable_PickersSectionListSectionContent, {
126
127
  name: 'MuiPickersInputBase',
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v8.0.0-alpha.10
2
+ * @mui/x-date-pickers v8.0.0-alpha.11
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-date-pickers",
3
- "version": "8.0.0-alpha.10",
3
+ "version": "8.0.0-alpha.11",
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": "8.0.0-alpha.10"
44
+ "@mui/x-internals": "8.0.0-alpha.11"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@emotion/react": "^11.9.0",