@mui/x-date-pickers 5.0.0-beta.7 → 5.0.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.
- package/AdapterDateFns/index.d.ts +7 -1
- package/AdapterDateFns/index.js +51 -1
- package/AdapterDayjs/index.d.ts +12 -1
- package/AdapterDayjs/index.js +45 -1
- package/CHANGELOG.md +78 -1
- package/CalendarPicker/CalendarPicker.d.ts +4 -1
- package/CalendarPicker/CalendarPicker.js +40 -10
- package/CalendarPicker/DayPicker.d.ts +2 -1
- package/CalendarPicker/DayPicker.js +100 -4
- package/CalendarPicker/PickersCalendarHeader.d.ts +8 -0
- package/CalendarPicker/useCalendarState.d.ts +10 -4
- package/CalendarPicker/useCalendarState.js +4 -3
- package/ClockPicker/ClockPicker.d.ts +3 -8
- package/DateField/DateField.interfaces.d.ts +4 -4
- package/DateField/index.d.ts +1 -1
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +35 -4
- package/DateTimePicker/DateTimePicker.js +2 -1
- package/DateTimePicker/DateTimePickerTabs.d.ts +20 -4
- package/DateTimePicker/DateTimePickerTabs.js +34 -5
- package/DateTimePicker/DateTimePickerToolbar.js +54 -68
- package/DateTimePicker/index.d.ts +2 -0
- package/DateTimePicker/index.js +2 -1
- package/DateTimePicker/shared.d.ts +2 -1
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
- package/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
- package/MonthPicker/MonthPicker.d.ts +4 -0
- package/MonthPicker/MonthPicker.js +87 -10
- package/MonthPicker/PickersMonth.d.ts +6 -2
- package/MonthPicker/PickersMonth.js +23 -4
- package/PickersDay/PickersDay.d.ts +4 -2
- package/PickersDay/PickersDay.js +13 -74
- package/StaticDateTimePicker/StaticDateTimePicker.js +12 -5
- package/YearPicker/PickersYear.d.ts +3 -0
- package/YearPicker/PickersYear.js +11 -4
- package/YearPicker/YearPicker.d.ts +3 -0
- package/YearPicker/YearPicker.js +42 -8
- package/index.js +1 -1
- package/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.d.ts +8 -0
- package/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +26 -4
- package/internals/components/CalendarOrClockPicker/useFocusManagement.d.ts +10 -0
- package/internals/components/CalendarOrClockPicker/useFocusManagement.js +18 -0
- package/internals/components/PickersArrowSwitcher.d.ts +16 -0
- package/internals/components/PickersModalDialog.d.ts +2 -2
- package/internals/components/PureDateInput.d.ts +4 -0
- package/internals/components/PureDateInput.js +1 -1
- package/internals/components/wrappers/WrapperProps.d.ts +8 -0
- package/internals/hooks/useField/index.d.ts +1 -1
- package/internals/hooks/useField/useField.d.ts +2 -2
- package/internals/hooks/useField/useField.interfaces.d.ts +24 -20
- package/internals/hooks/useField/useField.js +44 -15
- package/internals/hooks/useField/useField.utils.d.ts +8 -8
- package/internals/hooks/useField/useField.utils.js +14 -52
- package/internals/hooks/validation/useDateValidation.d.ts +1 -0
- package/internals/hooks/validation/useDateValidation.js +1 -3
- package/internals/index.d.ts +0 -2
- package/internals/index.js +0 -1
- package/internals/models/muiPickersAdapter.d.ts +8 -0
- package/internals/models/props/baseToolbarProps.d.ts +0 -1
- package/internals-fields/index.d.ts +2 -0
- package/internals-fields/index.js +3 -0
- package/internals-fields/package.json +6 -0
- package/legacy/AdapterDateFns/index.js +76 -1
- package/legacy/AdapterDayjs/index.js +74 -1
- package/legacy/CalendarPicker/CalendarPicker.js +49 -9
- package/legacy/CalendarPicker/DayPicker.js +109 -5
- package/legacy/CalendarPicker/useCalendarState.js +4 -3
- package/legacy/DateField/useDateField.js +33 -4
- package/legacy/DateTimePicker/DateTimePicker.js +2 -1
- package/legacy/DateTimePicker/DateTimePickerTabs.js +34 -5
- package/legacy/DateTimePicker/DateTimePickerToolbar.js +60 -74
- package/legacy/DateTimePicker/index.js +2 -1
- package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +15 -4
- package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +15 -4
- package/legacy/MonthPicker/MonthPicker.js +100 -8
- package/legacy/MonthPicker/PickersMonth.js +28 -3
- package/legacy/PickersDay/PickersDay.js +22 -75
- package/legacy/StaticDateTimePicker/StaticDateTimePicker.js +14 -4
- package/legacy/YearPicker/PickersYear.js +16 -3
- package/legacy/YearPicker/YearPicker.js +50 -8
- package/legacy/index.js +1 -1
- package/legacy/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +25 -3
- package/legacy/internals/components/CalendarOrClockPicker/useFocusManagement.js +27 -0
- package/legacy/internals/components/PureDateInput.js +1 -1
- package/legacy/internals/hooks/useField/useField.js +64 -26
- package/legacy/internals/hooks/useField/useField.utils.js +14 -52
- package/legacy/internals/hooks/validation/useDateValidation.js +1 -3
- package/legacy/internals/index.js +0 -1
- package/legacy/internals-fields/index.js +3 -0
- package/modern/AdapterDateFns/index.js +51 -1
- package/modern/AdapterDayjs/index.js +43 -1
- package/modern/CalendarPicker/CalendarPicker.js +40 -10
- package/modern/CalendarPicker/DayPicker.js +100 -4
- package/modern/CalendarPicker/useCalendarState.js +4 -3
- package/modern/DateField/useDateField.js +35 -4
- package/modern/DateTimePicker/DateTimePicker.js +2 -1
- package/modern/DateTimePicker/DateTimePickerTabs.js +34 -5
- package/modern/DateTimePicker/DateTimePickerToolbar.js +54 -68
- package/modern/DateTimePicker/index.js +2 -1
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
- package/modern/MonthPicker/MonthPicker.js +87 -10
- package/modern/MonthPicker/PickersMonth.js +21 -4
- package/modern/PickersDay/PickersDay.js +13 -74
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +12 -5
- package/modern/YearPicker/PickersYear.js +11 -4
- package/modern/YearPicker/YearPicker.js +42 -8
- package/modern/index.js +1 -1
- package/modern/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +24 -4
- package/modern/internals/components/CalendarOrClockPicker/useFocusManagement.js +18 -0
- package/modern/internals/components/PureDateInput.js +1 -1
- package/modern/internals/hooks/useField/useField.js +42 -15
- package/modern/internals/hooks/useField/useField.utils.js +14 -52
- package/modern/internals/hooks/validation/useDateValidation.js +1 -3
- package/modern/internals/index.js +0 -1
- package/modern/internals-fields/index.js +3 -0
- package/node/AdapterDateFns/index.js +57 -6
- package/node/AdapterDayjs/index.js +49 -6
- package/node/CalendarPicker/CalendarPicker.js +39 -9
- package/node/CalendarPicker/DayPicker.js +100 -3
- package/node/CalendarPicker/useCalendarState.js +4 -3
- package/node/DateField/useDateField.js +35 -3
- package/node/DateTimePicker/DateTimePicker.js +2 -1
- package/node/DateTimePicker/DateTimePickerTabs.js +32 -4
- package/node/DateTimePicker/DateTimePickerToolbar.js +54 -70
- package/node/DateTimePicker/index.js +9 -1
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
- package/node/MonthPicker/MonthPicker.js +87 -9
- package/node/MonthPicker/PickersMonth.js +26 -6
- package/node/PickersDay/PickersDay.js +12 -73
- package/node/StaticDateTimePicker/StaticDateTimePicker.js +13 -5
- package/node/YearPicker/PickersYear.js +11 -4
- package/node/YearPicker/YearPicker.js +43 -8
- package/node/index.js +1 -1
- package/node/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +27 -4
- package/node/internals/components/CalendarOrClockPicker/useFocusManagement.js +32 -0
- package/node/internals/components/PureDateInput.js +1 -1
- package/node/internals/hooks/useField/useField.js +44 -15
- package/node/internals/hooks/useField/useField.utils.js +16 -56
- package/node/internals/hooks/validation/useDateValidation.js +3 -1
- package/node/internals/index.js +0 -26
- package/node/internals-fields/index.js +31 -0
- package/package.json +1 -1
|
@@ -18,6 +18,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
18
18
|
|
|
19
19
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
20
20
|
|
|
21
|
+
var _system = require("@mui/system");
|
|
22
|
+
|
|
21
23
|
var _styles = require("@mui/material/styles");
|
|
22
24
|
|
|
23
25
|
var _material = require("@mui/material");
|
|
@@ -32,7 +34,7 @@ var _dateUtils = require("../internals/utils/date-utils");
|
|
|
32
34
|
|
|
33
35
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
34
36
|
|
|
35
|
-
const _excluded = ["className", "date", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday"];
|
|
37
|
+
const _excluded = ["className", "date", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange"];
|
|
36
38
|
|
|
37
39
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
38
40
|
|
|
@@ -90,13 +92,18 @@ const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(inProps,
|
|
|
90
92
|
onChange,
|
|
91
93
|
shouldDisableMonth,
|
|
92
94
|
readOnly,
|
|
93
|
-
disableHighlightToday
|
|
95
|
+
disableHighlightToday,
|
|
96
|
+
autoFocus = false,
|
|
97
|
+
onMonthFocus,
|
|
98
|
+
hasFocus,
|
|
99
|
+
onFocusedViewChange
|
|
94
100
|
} = props,
|
|
95
101
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
96
102
|
const ownerState = props;
|
|
97
103
|
const classes = useUtilityClasses(ownerState);
|
|
104
|
+
const theme = (0, _system.useTheme)();
|
|
98
105
|
const selectedDateOrToday = date != null ? date : now;
|
|
99
|
-
const
|
|
106
|
+
const selectedMonth = React.useMemo(() => {
|
|
100
107
|
if (date != null) {
|
|
101
108
|
return utils.getMonth(date);
|
|
102
109
|
}
|
|
@@ -107,8 +114,8 @@ const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(inProps,
|
|
|
107
114
|
|
|
108
115
|
return utils.getMonth(now);
|
|
109
116
|
}, [now, date, utils, disableHighlightToday]);
|
|
110
|
-
|
|
111
|
-
const isMonthDisabled = month => {
|
|
117
|
+
const [focusedMonth, setFocusedMonth] = React.useState(() => selectedMonth || utils.getMonth(now));
|
|
118
|
+
const isMonthDisabled = React.useCallback(month => {
|
|
112
119
|
const firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : minDate);
|
|
113
120
|
const lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : maxDate);
|
|
114
121
|
|
|
@@ -125,7 +132,7 @@ const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(inProps,
|
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
return shouldDisableMonth(month);
|
|
128
|
-
};
|
|
135
|
+
}, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableMonth, utils]);
|
|
129
136
|
|
|
130
137
|
const onMonthSelect = month => {
|
|
131
138
|
if (readOnly) {
|
|
@@ -136,20 +143,87 @@ const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(inProps,
|
|
|
136
143
|
onChange(newDate, 'finish');
|
|
137
144
|
};
|
|
138
145
|
|
|
146
|
+
const [internalHasFocus, setInternalHasFocus] = (0, _material.useControlled)({
|
|
147
|
+
name: 'MonthPicker',
|
|
148
|
+
state: 'hasFocus',
|
|
149
|
+
controlled: hasFocus,
|
|
150
|
+
default: autoFocus
|
|
151
|
+
});
|
|
152
|
+
const changeHasFocus = React.useCallback(newHasFocus => {
|
|
153
|
+
setInternalHasFocus(newHasFocus);
|
|
154
|
+
|
|
155
|
+
if (onFocusedViewChange) {
|
|
156
|
+
onFocusedViewChange(newHasFocus);
|
|
157
|
+
}
|
|
158
|
+
}, [setInternalHasFocus, onFocusedViewChange]);
|
|
159
|
+
const focusMonth = React.useCallback(month => {
|
|
160
|
+
if (!isMonthDisabled(utils.setMonth(selectedDateOrToday, month))) {
|
|
161
|
+
setFocusedMonth(month);
|
|
162
|
+
changeHasFocus(true);
|
|
163
|
+
|
|
164
|
+
if (onMonthFocus) {
|
|
165
|
+
onMonthFocus(month);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}, [selectedDateOrToday, isMonthDisabled, utils, onMonthFocus, changeHasFocus]);
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
setFocusedMonth(prevFocusedMonth => selectedMonth !== null && prevFocusedMonth !== selectedMonth ? selectedMonth : prevFocusedMonth);
|
|
171
|
+
}, [selectedMonth]);
|
|
172
|
+
const handleKeyDown = (0, _material.useEventCallback)(event => {
|
|
173
|
+
const monthsInYear = 12;
|
|
174
|
+
const monthsInRow = 3;
|
|
175
|
+
|
|
176
|
+
switch (event.key) {
|
|
177
|
+
case 'ArrowUp':
|
|
178
|
+
focusMonth((monthsInYear + focusedMonth - monthsInRow) % monthsInYear);
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
break;
|
|
181
|
+
|
|
182
|
+
case 'ArrowDown':
|
|
183
|
+
focusMonth((monthsInYear + focusedMonth + monthsInRow) % monthsInYear);
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
case 'ArrowLeft':
|
|
188
|
+
focusMonth((monthsInYear + focusedMonth + (theme.direction === 'ltr' ? -1 : 1)) % monthsInYear);
|
|
189
|
+
event.preventDefault();
|
|
190
|
+
break;
|
|
191
|
+
|
|
192
|
+
case 'ArrowRight':
|
|
193
|
+
focusMonth((monthsInYear + focusedMonth + (theme.direction === 'ltr' ? 1 : -1)) % monthsInYear);
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
break;
|
|
196
|
+
|
|
197
|
+
default:
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
const handleMonthFocus = React.useCallback((event, month) => {
|
|
202
|
+
focusMonth(month);
|
|
203
|
+
}, [focusMonth]);
|
|
204
|
+
const handleMonthBlur = React.useCallback(() => {
|
|
205
|
+
changeHasFocus(false);
|
|
206
|
+
}, [changeHasFocus]);
|
|
139
207
|
const currentMonthNumber = utils.getMonth(now);
|
|
140
208
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(MonthPickerRoot, (0, _extends2.default)({
|
|
141
209
|
ref: ref,
|
|
142
210
|
className: (0, _clsx.default)(classes.root, className),
|
|
143
|
-
ownerState: ownerState
|
|
211
|
+
ownerState: ownerState,
|
|
212
|
+
onKeyDown: handleKeyDown
|
|
144
213
|
}, other, {
|
|
145
214
|
children: utils.getMonthArray(selectedDateOrToday).map(month => {
|
|
146
215
|
const monthNumber = utils.getMonth(month);
|
|
147
216
|
const monthText = utils.format(month, 'monthShort');
|
|
217
|
+
const isDisabled = disabled || isMonthDisabled(month);
|
|
148
218
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PickersMonth.PickersMonth, {
|
|
149
219
|
value: monthNumber,
|
|
150
|
-
selected: monthNumber ===
|
|
220
|
+
selected: monthNumber === selectedMonth,
|
|
221
|
+
tabIndex: monthNumber === focusedMonth && !isDisabled ? 0 : -1,
|
|
222
|
+
hasFocus: internalHasFocus && monthNumber === focusedMonth,
|
|
151
223
|
onSelect: onMonthSelect,
|
|
152
|
-
|
|
224
|
+
onFocus: handleMonthFocus,
|
|
225
|
+
onBlur: handleMonthBlur,
|
|
226
|
+
disabled: isDisabled,
|
|
153
227
|
"aria-current": currentMonthNumber === monthNumber ? 'date' : undefined,
|
|
154
228
|
children: monthText
|
|
155
229
|
}, monthText);
|
|
@@ -162,6 +236,7 @@ process.env.NODE_ENV !== "production" ? MonthPicker.propTypes = {
|
|
|
162
236
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
163
237
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
164
238
|
// ----------------------------------------------------------------------
|
|
239
|
+
autoFocus: _propTypes.default.bool,
|
|
165
240
|
|
|
166
241
|
/**
|
|
167
242
|
* Override or extend the styles applied to the component.
|
|
@@ -200,6 +275,7 @@ process.env.NODE_ENV !== "production" ? MonthPicker.propTypes = {
|
|
|
200
275
|
* @default false
|
|
201
276
|
*/
|
|
202
277
|
disablePast: _propTypes.default.bool,
|
|
278
|
+
hasFocus: _propTypes.default.bool,
|
|
203
279
|
|
|
204
280
|
/**
|
|
205
281
|
* Maximal selectable date. @DateIOType
|
|
@@ -215,6 +291,8 @@ process.env.NODE_ENV !== "production" ? MonthPicker.propTypes = {
|
|
|
215
291
|
* Callback fired on date change.
|
|
216
292
|
*/
|
|
217
293
|
onChange: _propTypes.default.func.isRequired,
|
|
294
|
+
onFocusedViewChange: _propTypes.default.func,
|
|
295
|
+
onMonthFocus: _propTypes.default.func,
|
|
218
296
|
|
|
219
297
|
/**
|
|
220
298
|
* If `true` picker is readonly
|
|
@@ -21,11 +21,13 @@ var _styles = require("@mui/material/styles");
|
|
|
21
21
|
|
|
22
22
|
var _material = require("@mui/material");
|
|
23
23
|
|
|
24
|
-
var _utils = require("
|
|
24
|
+
var _utils = require("@mui/material/utils");
|
|
25
|
+
|
|
26
|
+
var _utils2 = require("../internals/utils/utils");
|
|
25
27
|
|
|
26
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
29
|
|
|
28
|
-
const _excluded = ["disabled", "onSelect", "selected", "value"];
|
|
30
|
+
const _excluded = ["disabled", "onSelect", "selected", "value", "tabIndex", "hasFocus", "onFocus", "onBlur"];
|
|
29
31
|
|
|
30
32
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
33
|
|
|
@@ -63,16 +65,23 @@ const PickersMonthRoot = (0, _styles.styled)(_Typography.default)(({
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
}));
|
|
68
|
+
|
|
69
|
+
const noop = () => {};
|
|
66
70
|
/**
|
|
67
71
|
* @ignore - do not document.
|
|
68
72
|
*/
|
|
69
73
|
|
|
74
|
+
|
|
70
75
|
const PickersMonth = props => {
|
|
71
76
|
const {
|
|
72
77
|
disabled,
|
|
73
78
|
onSelect,
|
|
74
79
|
selected,
|
|
75
|
-
value
|
|
80
|
+
value,
|
|
81
|
+
tabIndex,
|
|
82
|
+
hasFocus,
|
|
83
|
+
onFocus = noop,
|
|
84
|
+
onBlur = noop
|
|
76
85
|
} = props,
|
|
77
86
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
78
87
|
|
|
@@ -80,16 +89,27 @@ const PickersMonth = props => {
|
|
|
80
89
|
onSelect(value);
|
|
81
90
|
};
|
|
82
91
|
|
|
92
|
+
const ref = React.useRef(null);
|
|
93
|
+
(0, _utils.unstable_useEnhancedEffect)(() => {
|
|
94
|
+
if (hasFocus) {
|
|
95
|
+
var _ref$current;
|
|
96
|
+
|
|
97
|
+
(_ref$current = ref.current) == null ? void 0 : _ref$current.focus();
|
|
98
|
+
}
|
|
99
|
+
}, [hasFocus]);
|
|
83
100
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersMonthRoot, (0, _extends2.default)({
|
|
101
|
+
ref: ref,
|
|
84
102
|
component: "button",
|
|
85
103
|
type: "button",
|
|
86
104
|
className: (0, _clsx.default)(classes.root, selected && classes.selected),
|
|
87
|
-
tabIndex:
|
|
105
|
+
tabIndex: tabIndex,
|
|
88
106
|
onClick: handleSelection,
|
|
89
|
-
onKeyDown: (0,
|
|
107
|
+
onKeyDown: (0, _utils2.onSpaceOrEnter)(handleSelection),
|
|
90
108
|
color: selected ? 'primary' : undefined,
|
|
91
109
|
variant: selected ? 'h5' : 'subtitle1',
|
|
92
|
-
disabled: disabled
|
|
110
|
+
disabled: disabled,
|
|
111
|
+
onFocus: event => onFocus(event, value),
|
|
112
|
+
onBlur: event => onBlur(event, value)
|
|
93
113
|
}, other));
|
|
94
114
|
};
|
|
95
115
|
|
|
@@ -35,7 +35,7 @@ var _pickersDayClasses = require("./pickersDayClasses");
|
|
|
35
35
|
|
|
36
36
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
37
37
|
|
|
38
|
-
const _excluded = ["autoFocus", "className", "day", "disabled", "disableHighlightToday", "disableMargin", "hidden", "isAnimating", "onClick", "
|
|
38
|
+
const _excluded = ["autoFocus", "className", "day", "disabled", "disableHighlightToday", "disableMargin", "hidden", "isAnimating", "onClick", "onDaySelect", "onFocus", "onBlur", "onKeyDown", "onMouseDown", "outsideCurrentMonth", "selected", "showDaysOutsideCurrentMonth", "children", "today"];
|
|
39
39
|
|
|
40
40
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
41
41
|
|
|
@@ -147,10 +147,10 @@ const PickersDayRaw = /*#__PURE__*/React.forwardRef(function PickersDay(inProps,
|
|
|
147
147
|
disableMargin = false,
|
|
148
148
|
isAnimating,
|
|
149
149
|
onClick,
|
|
150
|
-
onDayFocus = noop,
|
|
151
150
|
onDaySelect,
|
|
152
|
-
onFocus,
|
|
153
|
-
|
|
151
|
+
onFocus = noop,
|
|
152
|
+
onBlur = noop,
|
|
153
|
+
onKeyDown = noop,
|
|
154
154
|
onMouseDown,
|
|
155
155
|
outsideCurrentMonth,
|
|
156
156
|
selected = false,
|
|
@@ -179,20 +179,9 @@ const PickersDayRaw = /*#__PURE__*/React.forwardRef(function PickersDay(inProps,
|
|
|
179
179
|
// ref.current being null would be a bug in MUI
|
|
180
180
|
ref.current.focus();
|
|
181
181
|
}
|
|
182
|
-
}, [autoFocus, disabled, isAnimating, outsideCurrentMonth]);
|
|
183
|
-
|
|
184
|
-
const handleFocus = event => {
|
|
185
|
-
if (onDayFocus) {
|
|
186
|
-
onDayFocus(day);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (onFocus) {
|
|
190
|
-
onFocus(event);
|
|
191
|
-
}
|
|
192
|
-
}; // For day outside of current month, move focus from mouseDown to mouseUp
|
|
182
|
+
}, [autoFocus, disabled, isAnimating, outsideCurrentMonth]); // For day outside of current month, move focus from mouseDown to mouseUp
|
|
193
183
|
// Goal: have the onClick ends before sliding to the new month
|
|
194
184
|
|
|
195
|
-
|
|
196
185
|
const handleMouseDown = event => {
|
|
197
186
|
if (onMouseDown) {
|
|
198
187
|
onMouseDown(event);
|
|
@@ -217,59 +206,6 @@ const PickersDayRaw = /*#__PURE__*/React.forwardRef(function PickersDay(inProps,
|
|
|
217
206
|
}
|
|
218
207
|
};
|
|
219
208
|
|
|
220
|
-
const theme = (0, _styles.useTheme)();
|
|
221
|
-
|
|
222
|
-
function handleKeyDown(event) {
|
|
223
|
-
if (onKeyDown !== undefined) {
|
|
224
|
-
onKeyDown(event);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
switch (event.key) {
|
|
228
|
-
case 'ArrowUp':
|
|
229
|
-
onDayFocus(utils.addDays(day, -7));
|
|
230
|
-
event.preventDefault();
|
|
231
|
-
break;
|
|
232
|
-
|
|
233
|
-
case 'ArrowDown':
|
|
234
|
-
onDayFocus(utils.addDays(day, 7));
|
|
235
|
-
event.preventDefault();
|
|
236
|
-
break;
|
|
237
|
-
|
|
238
|
-
case 'ArrowLeft':
|
|
239
|
-
onDayFocus(utils.addDays(day, theme.direction === 'ltr' ? -1 : 1));
|
|
240
|
-
event.preventDefault();
|
|
241
|
-
break;
|
|
242
|
-
|
|
243
|
-
case 'ArrowRight':
|
|
244
|
-
onDayFocus(utils.addDays(day, theme.direction === 'ltr' ? 1 : -1));
|
|
245
|
-
event.preventDefault();
|
|
246
|
-
break;
|
|
247
|
-
|
|
248
|
-
case 'Home':
|
|
249
|
-
onDayFocus(utils.startOfWeek(day));
|
|
250
|
-
event.preventDefault();
|
|
251
|
-
break;
|
|
252
|
-
|
|
253
|
-
case 'End':
|
|
254
|
-
onDayFocus(utils.endOfWeek(day));
|
|
255
|
-
event.preventDefault();
|
|
256
|
-
break;
|
|
257
|
-
|
|
258
|
-
case 'PageUp':
|
|
259
|
-
onDayFocus(utils.getNextMonth(day));
|
|
260
|
-
event.preventDefault();
|
|
261
|
-
break;
|
|
262
|
-
|
|
263
|
-
case 'PageDown':
|
|
264
|
-
onDayFocus(utils.getPreviousMonth(day));
|
|
265
|
-
event.preventDefault();
|
|
266
|
-
break;
|
|
267
|
-
|
|
268
|
-
default:
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
209
|
if (outsideCurrentMonth && !showDaysOutsideCurrentMonth) {
|
|
274
210
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersDayFiller, {
|
|
275
211
|
className: (0, _clsx.default)(classes.root, classes.hiddenDaySpacingFiller, className),
|
|
@@ -285,8 +221,9 @@ const PickersDayRaw = /*#__PURE__*/React.forwardRef(function PickersDay(inProps,
|
|
|
285
221
|
centerRipple: true,
|
|
286
222
|
disabled: disabled,
|
|
287
223
|
tabIndex: selected ? 0 : -1,
|
|
288
|
-
|
|
289
|
-
|
|
224
|
+
onKeyDown: event => onKeyDown(event, day),
|
|
225
|
+
onFocus: event => onFocus(event, day),
|
|
226
|
+
onBlur: event => onBlur(event, day),
|
|
290
227
|
onClick: handleClick,
|
|
291
228
|
onMouseDown: handleMouseDown
|
|
292
229
|
}, other, {
|
|
@@ -295,7 +232,7 @@ const PickersDayRaw = /*#__PURE__*/React.forwardRef(function PickersDay(inProps,
|
|
|
295
232
|
});
|
|
296
233
|
|
|
297
234
|
const areDayPropsEqual = (prevProps, nextProps) => {
|
|
298
|
-
return prevProps.autoFocus === nextProps.autoFocus && prevProps.isAnimating === nextProps.isAnimating && prevProps.today === nextProps.today && prevProps.disabled === nextProps.disabled && prevProps.selected === nextProps.selected && prevProps.disableMargin === nextProps.disableMargin && prevProps.showDaysOutsideCurrentMonth === nextProps.showDaysOutsideCurrentMonth && prevProps.disableHighlightToday === nextProps.disableHighlightToday && prevProps.className === nextProps.className && prevProps.outsideCurrentMonth === nextProps.outsideCurrentMonth && prevProps.
|
|
235
|
+
return prevProps.autoFocus === nextProps.autoFocus && prevProps.isAnimating === nextProps.isAnimating && prevProps.today === nextProps.today && prevProps.disabled === nextProps.disabled && prevProps.selected === nextProps.selected && prevProps.disableMargin === nextProps.disableMargin && prevProps.showDaysOutsideCurrentMonth === nextProps.showDaysOutsideCurrentMonth && prevProps.disableHighlightToday === nextProps.disableHighlightToday && prevProps.className === nextProps.className && prevProps.outsideCurrentMonth === nextProps.outsideCurrentMonth && prevProps.onFocus === nextProps.onFocus && prevProps.onBlur === nextProps.onBlur && prevProps.onDaySelect === nextProps.onDaySelect;
|
|
299
236
|
};
|
|
300
237
|
|
|
301
238
|
exports.areDayPropsEqual = areDayPropsEqual;
|
|
@@ -333,8 +270,10 @@ process.env.NODE_ENV !== "production" ? PickersDayRaw.propTypes = {
|
|
|
333
270
|
*/
|
|
334
271
|
disableMargin: _propTypes.default.bool,
|
|
335
272
|
isAnimating: _propTypes.default.bool,
|
|
336
|
-
|
|
273
|
+
onBlur: _propTypes.default.func,
|
|
337
274
|
onDaySelect: _propTypes.default.func.isRequired,
|
|
275
|
+
onFocus: _propTypes.default.func,
|
|
276
|
+
onKeyDown: _propTypes.default.func,
|
|
338
277
|
|
|
339
278
|
/**
|
|
340
279
|
* If `true`, day is outside of month and will be hidden.
|
|
@@ -27,9 +27,11 @@ var _useDateTimeValidation = require("../internals/hooks/validation/useDateTimeV
|
|
|
27
27
|
|
|
28
28
|
var _usePickerState = require("../internals/hooks/usePickerState");
|
|
29
29
|
|
|
30
|
+
var _DateTimePicker = require("../DateTimePicker");
|
|
31
|
+
|
|
30
32
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
31
33
|
|
|
32
|
-
const _excluded = ["displayStaticWrapperAs", "onChange", "ToolbarComponent", "value", "components", "componentsProps"];
|
|
34
|
+
const _excluded = ["displayStaticWrapperAs", "onChange", "ToolbarComponent", "value", "components", "componentsProps", "hideTabs"];
|
|
33
35
|
|
|
34
36
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
37
|
|
|
@@ -52,8 +54,9 @@ const StaticDateTimePicker = /*#__PURE__*/React.forwardRef(function StaticDateTi
|
|
|
52
54
|
const {
|
|
53
55
|
displayStaticWrapperAs = 'mobile',
|
|
54
56
|
ToolbarComponent = _DateTimePickerToolbar.DateTimePickerToolbar,
|
|
55
|
-
components,
|
|
56
|
-
componentsProps
|
|
57
|
+
components: providedComponents,
|
|
58
|
+
componentsProps,
|
|
59
|
+
hideTabs = displayStaticWrapperAs === 'desktop'
|
|
57
60
|
} = props,
|
|
58
61
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
59
62
|
const {
|
|
@@ -62,6 +65,9 @@ const StaticDateTimePicker = /*#__PURE__*/React.forwardRef(function StaticDateTi
|
|
|
62
65
|
wrapperProps
|
|
63
66
|
} = (0, _usePickerState.usePickerState)(props, _shared.dateTimePickerValueManager);
|
|
64
67
|
const validationError = (0, _useDateTimeValidation.useDateTimeValidation)(props) !== null;
|
|
68
|
+
const components = React.useMemo(() => (0, _extends2.default)({
|
|
69
|
+
Tabs: _DateTimePicker.DateTimePickerTabs
|
|
70
|
+
}, providedComponents), [providedComponents]);
|
|
65
71
|
const DateInputProps = (0, _extends2.default)({}, inputProps, other, {
|
|
66
72
|
ref,
|
|
67
73
|
validationError,
|
|
@@ -78,7 +84,8 @@ const StaticDateTimePicker = /*#__PURE__*/React.forwardRef(function StaticDateTi
|
|
|
78
84
|
ToolbarComponent: ToolbarComponent,
|
|
79
85
|
DateInputProps: DateInputProps,
|
|
80
86
|
components: components,
|
|
81
|
-
componentsProps: componentsProps
|
|
87
|
+
componentsProps: componentsProps,
|
|
88
|
+
hideTabs: hideTabs
|
|
82
89
|
}, other))
|
|
83
90
|
}));
|
|
84
91
|
});
|
|
@@ -235,7 +242,8 @@ process.env.NODE_ENV !== "production" ? StaticDateTimePicker.propTypes = {
|
|
|
235
242
|
getViewSwitchingButtonText: _propTypes.default.func,
|
|
236
243
|
|
|
237
244
|
/**
|
|
238
|
-
*
|
|
245
|
+
* Toggles visibility of date time switching tabs
|
|
246
|
+
* @default false for mobile, true for desktop
|
|
239
247
|
*/
|
|
240
248
|
hideTabs: _propTypes.default.bool,
|
|
241
249
|
ignoreInvalidInputs: _propTypes.default.bool,
|
|
@@ -27,7 +27,7 @@ var _WrapperVariantContext = require("../internals/components/wrappers/WrapperVa
|
|
|
27
27
|
|
|
28
28
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
29
|
|
|
30
|
-
const _excluded = ["autoFocus", "className", "children", "disabled", "onClick", "onKeyDown", "
|
|
30
|
+
const _excluded = ["autoFocus", "className", "children", "disabled", "onClick", "onKeyDown", "value", "tabIndex", "onFocus", "onBlur"];
|
|
31
31
|
|
|
32
32
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
33
|
|
|
@@ -91,10 +91,13 @@ const PickersYearButton = (0, _styles.styled)('button')(({
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}));
|
|
94
|
+
|
|
95
|
+
const noop = () => {};
|
|
94
96
|
/**
|
|
95
97
|
* @ignore - internal component.
|
|
96
98
|
*/
|
|
97
99
|
|
|
100
|
+
|
|
98
101
|
const PickersYear = /*#__PURE__*/React.forwardRef(function PickersYear(props, forwardedRef) {
|
|
99
102
|
const {
|
|
100
103
|
autoFocus,
|
|
@@ -103,8 +106,10 @@ const PickersYear = /*#__PURE__*/React.forwardRef(function PickersYear(props, fo
|
|
|
103
106
|
disabled,
|
|
104
107
|
onClick,
|
|
105
108
|
onKeyDown,
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
value,
|
|
110
|
+
tabIndex,
|
|
111
|
+
onFocus = noop,
|
|
112
|
+
onBlur = noop
|
|
108
113
|
} = props,
|
|
109
114
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
110
115
|
const ref = React.useRef(null);
|
|
@@ -128,9 +133,11 @@ const PickersYear = /*#__PURE__*/React.forwardRef(function PickersYear(props, fo
|
|
|
128
133
|
ref: refHandle,
|
|
129
134
|
disabled: disabled,
|
|
130
135
|
type: "button",
|
|
131
|
-
tabIndex:
|
|
136
|
+
tabIndex: disabled ? -1 : tabIndex,
|
|
132
137
|
onClick: event => onClick(event, value),
|
|
133
138
|
onKeyDown: event => onKeyDown(event, value),
|
|
139
|
+
onFocus: event => onFocus(event, value),
|
|
140
|
+
onBlur: event => onBlur(event, value),
|
|
134
141
|
className: classes.yearButton,
|
|
135
142
|
ownerState: ownerState
|
|
136
143
|
}, other, {
|
|
@@ -17,6 +17,8 @@ var _styles = require("@mui/material/styles");
|
|
|
17
17
|
|
|
18
18
|
var _material = require("@mui/material");
|
|
19
19
|
|
|
20
|
+
var _utils = require("@mui/material/utils");
|
|
21
|
+
|
|
20
22
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
21
23
|
|
|
22
24
|
var _PickersYear = require("./PickersYear");
|
|
@@ -90,7 +92,10 @@ const YearPicker = /*#__PURE__*/React.forwardRef(function YearPicker(inProps, re
|
|
|
90
92
|
onChange,
|
|
91
93
|
readOnly,
|
|
92
94
|
shouldDisableYear,
|
|
93
|
-
disableHighlightToday
|
|
95
|
+
disableHighlightToday,
|
|
96
|
+
onYearFocus,
|
|
97
|
+
hasFocus,
|
|
98
|
+
onFocusedViewChange
|
|
94
99
|
} = props;
|
|
95
100
|
const ownerState = props;
|
|
96
101
|
const classes = useUtilityClasses(ownerState);
|
|
@@ -108,7 +113,20 @@ const YearPicker = /*#__PURE__*/React.forwardRef(function YearPicker(inProps, re
|
|
|
108
113
|
}, [now, date, utils, disableHighlightToday]);
|
|
109
114
|
const wrapperVariant = React.useContext(_WrapperVariantContext.WrapperVariantContext);
|
|
110
115
|
const selectedYearRef = React.useRef(null);
|
|
111
|
-
const [focusedYear, setFocusedYear] = React.useState(currentYear);
|
|
116
|
+
const [focusedYear, setFocusedYear] = React.useState(() => currentYear || utils.getYear(now));
|
|
117
|
+
const [internalHasFocus, setInternalHasFocus] = (0, _utils.useControlled)({
|
|
118
|
+
name: 'YearPicker',
|
|
119
|
+
state: 'hasFocus',
|
|
120
|
+
controlled: hasFocus,
|
|
121
|
+
default: autoFocus
|
|
122
|
+
});
|
|
123
|
+
const changeHasFocus = React.useCallback(newHasFocus => {
|
|
124
|
+
setInternalHasFocus(newHasFocus);
|
|
125
|
+
|
|
126
|
+
if (onFocusedViewChange) {
|
|
127
|
+
onFocusedViewChange(newHasFocus);
|
|
128
|
+
}
|
|
129
|
+
}, [setInternalHasFocus, onFocusedViewChange]);
|
|
112
130
|
const isYearDisabled = React.useCallback(dateToValidate => {
|
|
113
131
|
if (disablePast && utils.isBeforeYear(dateToValidate, now)) {
|
|
114
132
|
return true;
|
|
@@ -145,11 +163,15 @@ const YearPicker = /*#__PURE__*/React.forwardRef(function YearPicker(inProps, re
|
|
|
145
163
|
const focusYear = React.useCallback(year => {
|
|
146
164
|
if (!isYearDisabled(utils.setYear(selectedDateOrToday, year))) {
|
|
147
165
|
setFocusedYear(year);
|
|
166
|
+
changeHasFocus(true);
|
|
167
|
+
onYearFocus == null ? void 0 : onYearFocus(year);
|
|
148
168
|
}
|
|
149
|
-
}, [selectedDateOrToday,
|
|
169
|
+
}, [isYearDisabled, utils, selectedDateOrToday, changeHasFocus, onYearFocus]);
|
|
170
|
+
React.useEffect(() => {
|
|
171
|
+
setFocusedYear(prevFocusedYear => currentYear !== null && prevFocusedYear !== currentYear ? currentYear : prevFocusedYear);
|
|
172
|
+
}, [currentYear]);
|
|
150
173
|
const yearsInRow = wrapperVariant === 'desktop' ? 4 : 3;
|
|
151
|
-
|
|
152
|
-
const handleKeyDown = (event, year) => {
|
|
174
|
+
const handleKeyDown = React.useCallback((event, year) => {
|
|
153
175
|
switch (event.key) {
|
|
154
176
|
case 'ArrowUp':
|
|
155
177
|
focusYear(year - yearsInRow);
|
|
@@ -174,8 +196,15 @@ const YearPicker = /*#__PURE__*/React.forwardRef(function YearPicker(inProps, re
|
|
|
174
196
|
default:
|
|
175
197
|
break;
|
|
176
198
|
}
|
|
177
|
-
};
|
|
178
|
-
|
|
199
|
+
}, [focusYear, theme.direction, yearsInRow]);
|
|
200
|
+
const handleFocus = React.useCallback((event, year) => {
|
|
201
|
+
focusYear(year);
|
|
202
|
+
}, [focusYear]);
|
|
203
|
+
const handleBlur = React.useCallback((event, year) => {
|
|
204
|
+
if (focusedYear === year) {
|
|
205
|
+
changeHasFocus(false);
|
|
206
|
+
}
|
|
207
|
+
}, [focusedYear, changeHasFocus]);
|
|
179
208
|
const nowYear = utils.getYear(now);
|
|
180
209
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(YearPickerRoot, {
|
|
181
210
|
ref: ref,
|
|
@@ -189,9 +218,12 @@ const YearPicker = /*#__PURE__*/React.forwardRef(function YearPicker(inProps, re
|
|
|
189
218
|
value: yearNumber,
|
|
190
219
|
onClick: handleYearSelection,
|
|
191
220
|
onKeyDown: handleKeyDown,
|
|
192
|
-
autoFocus:
|
|
221
|
+
autoFocus: internalHasFocus && yearNumber === focusedYear,
|
|
193
222
|
ref: selected ? selectedYearRef : undefined,
|
|
194
223
|
disabled: disabled || isYearDisabled(year),
|
|
224
|
+
tabIndex: yearNumber === focusedYear ? 0 : -1,
|
|
225
|
+
onFocus: handleFocus,
|
|
226
|
+
onBlur: handleBlur,
|
|
195
227
|
"aria-current": nowYear === yearNumber ? 'date' : undefined,
|
|
196
228
|
children: utils.format(year, 'year')
|
|
197
229
|
}, utils.format(year, 'year'));
|
|
@@ -227,6 +259,7 @@ process.env.NODE_ENV !== "production" ? YearPicker.propTypes = {
|
|
|
227
259
|
* @default false
|
|
228
260
|
*/
|
|
229
261
|
disablePast: _propTypes.default.bool,
|
|
262
|
+
hasFocus: _propTypes.default.bool,
|
|
230
263
|
|
|
231
264
|
/**
|
|
232
265
|
* Maximal selectable date. @DateIOType
|
|
@@ -239,6 +272,8 @@ process.env.NODE_ENV !== "production" ? YearPicker.propTypes = {
|
|
|
239
272
|
minDate: _propTypes.default.any,
|
|
240
273
|
onChange: _propTypes.default.func.isRequired,
|
|
241
274
|
onFocusedDayChange: _propTypes.default.func,
|
|
275
|
+
onFocusedViewChange: _propTypes.default.func,
|
|
276
|
+
onYearFocus: _propTypes.default.func,
|
|
242
277
|
readOnly: _propTypes.default.bool,
|
|
243
278
|
|
|
244
279
|
/**
|
package/node/index.js
CHANGED