@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.
Files changed (144) hide show
  1. package/AdapterDateFns/index.d.ts +7 -1
  2. package/AdapterDateFns/index.js +51 -1
  3. package/AdapterDayjs/index.d.ts +12 -1
  4. package/AdapterDayjs/index.js +45 -1
  5. package/CHANGELOG.md +78 -1
  6. package/CalendarPicker/CalendarPicker.d.ts +4 -1
  7. package/CalendarPicker/CalendarPicker.js +40 -10
  8. package/CalendarPicker/DayPicker.d.ts +2 -1
  9. package/CalendarPicker/DayPicker.js +100 -4
  10. package/CalendarPicker/PickersCalendarHeader.d.ts +8 -0
  11. package/CalendarPicker/useCalendarState.d.ts +10 -4
  12. package/CalendarPicker/useCalendarState.js +4 -3
  13. package/ClockPicker/ClockPicker.d.ts +3 -8
  14. package/DateField/DateField.interfaces.d.ts +4 -4
  15. package/DateField/index.d.ts +1 -1
  16. package/DateField/useDateField.d.ts +1 -1
  17. package/DateField/useDateField.js +35 -4
  18. package/DateTimePicker/DateTimePicker.js +2 -1
  19. package/DateTimePicker/DateTimePickerTabs.d.ts +20 -4
  20. package/DateTimePicker/DateTimePickerTabs.js +34 -5
  21. package/DateTimePicker/DateTimePickerToolbar.js +54 -68
  22. package/DateTimePicker/index.d.ts +2 -0
  23. package/DateTimePicker/index.js +2 -1
  24. package/DateTimePicker/shared.d.ts +2 -1
  25. package/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
  26. package/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
  27. package/MonthPicker/MonthPicker.d.ts +4 -0
  28. package/MonthPicker/MonthPicker.js +87 -10
  29. package/MonthPicker/PickersMonth.d.ts +6 -2
  30. package/MonthPicker/PickersMonth.js +23 -4
  31. package/PickersDay/PickersDay.d.ts +4 -2
  32. package/PickersDay/PickersDay.js +13 -74
  33. package/StaticDateTimePicker/StaticDateTimePicker.js +12 -5
  34. package/YearPicker/PickersYear.d.ts +3 -0
  35. package/YearPicker/PickersYear.js +11 -4
  36. package/YearPicker/YearPicker.d.ts +3 -0
  37. package/YearPicker/YearPicker.js +42 -8
  38. package/index.js +1 -1
  39. package/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.d.ts +8 -0
  40. package/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +26 -4
  41. package/internals/components/CalendarOrClockPicker/useFocusManagement.d.ts +10 -0
  42. package/internals/components/CalendarOrClockPicker/useFocusManagement.js +18 -0
  43. package/internals/components/PickersArrowSwitcher.d.ts +16 -0
  44. package/internals/components/PickersModalDialog.d.ts +2 -2
  45. package/internals/components/PureDateInput.d.ts +4 -0
  46. package/internals/components/PureDateInput.js +1 -1
  47. package/internals/components/wrappers/WrapperProps.d.ts +8 -0
  48. package/internals/hooks/useField/index.d.ts +1 -1
  49. package/internals/hooks/useField/useField.d.ts +2 -2
  50. package/internals/hooks/useField/useField.interfaces.d.ts +24 -20
  51. package/internals/hooks/useField/useField.js +44 -15
  52. package/internals/hooks/useField/useField.utils.d.ts +8 -8
  53. package/internals/hooks/useField/useField.utils.js +14 -52
  54. package/internals/hooks/validation/useDateValidation.d.ts +1 -0
  55. package/internals/hooks/validation/useDateValidation.js +1 -3
  56. package/internals/index.d.ts +0 -2
  57. package/internals/index.js +0 -1
  58. package/internals/models/muiPickersAdapter.d.ts +8 -0
  59. package/internals/models/props/baseToolbarProps.d.ts +0 -1
  60. package/internals-fields/index.d.ts +2 -0
  61. package/internals-fields/index.js +3 -0
  62. package/internals-fields/package.json +6 -0
  63. package/legacy/AdapterDateFns/index.js +76 -1
  64. package/legacy/AdapterDayjs/index.js +74 -1
  65. package/legacy/CalendarPicker/CalendarPicker.js +49 -9
  66. package/legacy/CalendarPicker/DayPicker.js +109 -5
  67. package/legacy/CalendarPicker/useCalendarState.js +4 -3
  68. package/legacy/DateField/useDateField.js +33 -4
  69. package/legacy/DateTimePicker/DateTimePicker.js +2 -1
  70. package/legacy/DateTimePicker/DateTimePickerTabs.js +34 -5
  71. package/legacy/DateTimePicker/DateTimePickerToolbar.js +60 -74
  72. package/legacy/DateTimePicker/index.js +2 -1
  73. package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +15 -4
  74. package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +15 -4
  75. package/legacy/MonthPicker/MonthPicker.js +100 -8
  76. package/legacy/MonthPicker/PickersMonth.js +28 -3
  77. package/legacy/PickersDay/PickersDay.js +22 -75
  78. package/legacy/StaticDateTimePicker/StaticDateTimePicker.js +14 -4
  79. package/legacy/YearPicker/PickersYear.js +16 -3
  80. package/legacy/YearPicker/YearPicker.js +50 -8
  81. package/legacy/index.js +1 -1
  82. package/legacy/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +25 -3
  83. package/legacy/internals/components/CalendarOrClockPicker/useFocusManagement.js +27 -0
  84. package/legacy/internals/components/PureDateInput.js +1 -1
  85. package/legacy/internals/hooks/useField/useField.js +64 -26
  86. package/legacy/internals/hooks/useField/useField.utils.js +14 -52
  87. package/legacy/internals/hooks/validation/useDateValidation.js +1 -3
  88. package/legacy/internals/index.js +0 -1
  89. package/legacy/internals-fields/index.js +3 -0
  90. package/modern/AdapterDateFns/index.js +51 -1
  91. package/modern/AdapterDayjs/index.js +43 -1
  92. package/modern/CalendarPicker/CalendarPicker.js +40 -10
  93. package/modern/CalendarPicker/DayPicker.js +100 -4
  94. package/modern/CalendarPicker/useCalendarState.js +4 -3
  95. package/modern/DateField/useDateField.js +35 -4
  96. package/modern/DateTimePicker/DateTimePicker.js +2 -1
  97. package/modern/DateTimePicker/DateTimePickerTabs.js +34 -5
  98. package/modern/DateTimePicker/DateTimePickerToolbar.js +54 -68
  99. package/modern/DateTimePicker/index.js +2 -1
  100. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
  101. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
  102. package/modern/MonthPicker/MonthPicker.js +87 -10
  103. package/modern/MonthPicker/PickersMonth.js +21 -4
  104. package/modern/PickersDay/PickersDay.js +13 -74
  105. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +12 -5
  106. package/modern/YearPicker/PickersYear.js +11 -4
  107. package/modern/YearPicker/YearPicker.js +42 -8
  108. package/modern/index.js +1 -1
  109. package/modern/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +24 -4
  110. package/modern/internals/components/CalendarOrClockPicker/useFocusManagement.js +18 -0
  111. package/modern/internals/components/PureDateInput.js +1 -1
  112. package/modern/internals/hooks/useField/useField.js +42 -15
  113. package/modern/internals/hooks/useField/useField.utils.js +14 -52
  114. package/modern/internals/hooks/validation/useDateValidation.js +1 -3
  115. package/modern/internals/index.js +0 -1
  116. package/modern/internals-fields/index.js +3 -0
  117. package/node/AdapterDateFns/index.js +57 -6
  118. package/node/AdapterDayjs/index.js +49 -6
  119. package/node/CalendarPicker/CalendarPicker.js +39 -9
  120. package/node/CalendarPicker/DayPicker.js +100 -3
  121. package/node/CalendarPicker/useCalendarState.js +4 -3
  122. package/node/DateField/useDateField.js +35 -3
  123. package/node/DateTimePicker/DateTimePicker.js +2 -1
  124. package/node/DateTimePicker/DateTimePickerTabs.js +32 -4
  125. package/node/DateTimePicker/DateTimePickerToolbar.js +54 -70
  126. package/node/DateTimePicker/index.js +9 -1
  127. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
  128. package/node/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
  129. package/node/MonthPicker/MonthPicker.js +87 -9
  130. package/node/MonthPicker/PickersMonth.js +26 -6
  131. package/node/PickersDay/PickersDay.js +12 -73
  132. package/node/StaticDateTimePicker/StaticDateTimePicker.js +13 -5
  133. package/node/YearPicker/PickersYear.js +11 -4
  134. package/node/YearPicker/YearPicker.js +43 -8
  135. package/node/index.js +1 -1
  136. package/node/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +27 -4
  137. package/node/internals/components/CalendarOrClockPicker/useFocusManagement.js +32 -0
  138. package/node/internals/components/PureDateInput.js +1 -1
  139. package/node/internals/hooks/useField/useField.js +44 -15
  140. package/node/internals/hooks/useField/useField.utils.js +16 -56
  141. package/node/internals/hooks/validation/useDateValidation.js +3 -1
  142. package/node/internals/index.js +0 -26
  143. package/node/internals-fields/index.js +31 -0
  144. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
1
  export { DateField as Unstable_DateField } from './DateField';
2
2
  export { useDateField as unstable_useDateField } from './useDateField';
3
- export type { UseDateFieldProps } from './DateField.interfaces';
3
+ export type { UseDateFieldProps, UseDateFieldComponentProps } from './DateField.interfaces';
@@ -1,2 +1,2 @@
1
1
  import { UseDateFieldProps } from './DateField.interfaces';
2
- export declare const useDateField: <TInputDate, TDate, TProps extends UseDateFieldProps<TInputDate, TDate>>(inProps: TProps) => import("../internals/hooks/useField").UseFieldResponse<TProps & Omit<UseDateFieldProps<TInputDate, TDate>, "minDate" | "maxDate" | "disableFuture" | "disablePast"> & Required<Pick<UseDateFieldProps<TInputDate, TDate>, "minDate" | "maxDate" | "disableFuture" | "disablePast">>>;
2
+ export declare const useDateField: <TInputDate, TDate, TProps extends UseDateFieldProps<TInputDate, TDate>>(inProps: TProps) => import("../internals/hooks/useField").UseFieldResponse<Omit<TProps & Omit<UseDateFieldProps<TInputDate, TDate>, "minDate" | "maxDate" | "disableFuture" | "disablePast"> & Required<Pick<UseDateFieldProps<TInputDate, TDate>, "minDate" | "maxDate" | "disableFuture" | "disablePast">>, "defaultValue" | "onChange" | "onError" | "value" | "format" | "readOnly" | "minDate" | "maxDate" | "disableFuture" | "disablePast" | "shouldDisableDate">>;
@@ -1,7 +1,9 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
1
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "shouldDisableDate", "minDate", "maxDate", "disableFuture", "disablePast"];
2
4
  import { datePickerValueManager } from '../DatePicker/shared';
3
5
  import { useField, splitFormatIntoSections, addPositionPropertiesToSections, createDateStrFromSections } from '../internals/hooks/useField';
4
- import { validateDate } from '../internals/hooks/validation/useDateValidation';
6
+ import { isSameDateError, validateDate } from '../internals/hooks/validation/useDateValidation';
5
7
  import { parseNonNullablePickerDate } from '../internals/utils/date-utils';
6
8
  import { useUtils, useDefaultDates } from '../internals/hooks/useUtils';
7
9
  const dateRangeFieldValueManager = {
@@ -19,7 +21,8 @@ const dateRangeFieldValueManager = {
19
21
  value,
20
22
  update: newActiveDate => newActiveDate
21
23
  }),
22
- hasError: error => error != null
24
+ hasError: error => error != null,
25
+ isSameError: isSameDateError
23
26
  };
24
27
 
25
28
  const useDefaultizedDateField = props => {
@@ -35,9 +38,37 @@ const useDefaultizedDateField = props => {
35
38
  };
36
39
 
37
40
  export const useDateField = inProps => {
38
- const props = useDefaultizedDateField(inProps);
41
+ const _useDefaultizedDateFi = useDefaultizedDateField(inProps),
42
+ {
43
+ value,
44
+ defaultValue,
45
+ format,
46
+ onChange,
47
+ readOnly,
48
+ onError,
49
+ shouldDisableDate,
50
+ minDate,
51
+ maxDate,
52
+ disableFuture,
53
+ disablePast
54
+ } = _useDefaultizedDateFi,
55
+ other = _objectWithoutPropertiesLoose(_useDefaultizedDateFi, _excluded);
56
+
39
57
  return useField({
40
- props,
58
+ forwardedProps: other,
59
+ internalProps: {
60
+ value,
61
+ defaultValue,
62
+ format,
63
+ onChange,
64
+ readOnly,
65
+ onError,
66
+ shouldDisableDate,
67
+ minDate,
68
+ maxDate,
69
+ disableFuture,
70
+ disablePast
71
+ },
41
72
  valueManager: datePickerValueManager,
42
73
  fieldValueManager: dateRangeFieldValueManager,
43
74
  // TODO: Support time validation.
@@ -211,7 +211,8 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
211
211
  getViewSwitchingButtonText: PropTypes.func,
212
212
 
213
213
  /**
214
- * To show tabs.
214
+ * Toggles visibility of date time switching tabs
215
+ * @default false for mobile, true for desktop
215
216
  */
216
217
  hideTabs: PropTypes.bool,
217
218
  ignoreInvalidInputs: PropTypes.bool,
@@ -1,12 +1,28 @@
1
1
  import * as React from 'react';
2
2
  import { CalendarOrClockPickerView } from '../internals/models';
3
3
  export interface DateTimePickerTabsProps {
4
+ /**
5
+ * Date tab icon.
6
+ * @default DateRange
7
+ */
4
8
  dateRangeIcon?: React.ReactNode;
9
+ /**
10
+ * Callback called when tab is clicked
11
+ * @param {CalendarOrClockPickerView} view Picker view that was clicked
12
+ */
5
13
  onChange: (view: CalendarOrClockPickerView) => void;
14
+ /**
15
+ * Time tab icon.
16
+ * @default Time
17
+ */
6
18
  timeIcon?: React.ReactNode;
19
+ /**
20
+ * Open picker view
21
+ */
7
22
  view: CalendarOrClockPickerView;
8
23
  }
9
- /**
10
- * @ignore - internal component.
11
- */
12
- export declare const DateTimePickerTabs: (props: DateTimePickerTabsProps) => JSX.Element;
24
+ declare const DateTimePickerTabs: {
25
+ (props: DateTimePickerTabsProps): JSX.Element;
26
+ propTypes: any;
27
+ };
28
+ export { DateTimePickerTabs };
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import PropTypes from 'prop-types';
3
4
  import Tab from '@mui/material/Tab';
4
5
  import Tabs, { tabsClasses } from '@mui/material/Tabs';
5
6
  import { styled } from '@mui/material/styles';
@@ -38,11 +39,8 @@ const DateTimePickerTabsRoot = styled(Tabs)(({
38
39
  top: 0
39
40
  }
40
41
  }));
41
- /**
42
- * @ignore - internal component.
43
- */
44
42
 
45
- export const DateTimePickerTabs = props => {
43
+ const DateTimePickerTabs = props => {
46
44
  const {
47
45
  dateRangeIcon = /*#__PURE__*/_jsx(DateRange, {}),
48
46
  onChange,
@@ -79,4 +77,35 @@ export const DateTimePickerTabs = props => {
79
77
  })
80
78
  })]
81
79
  });
82
- };
80
+ };
81
+
82
+ process.env.NODE_ENV !== "production" ? DateTimePickerTabs.propTypes = {
83
+ // ----------------------------- Warning --------------------------------
84
+ // | These PropTypes are generated from the TypeScript type definitions |
85
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
86
+ // ----------------------------------------------------------------------
87
+
88
+ /**
89
+ * Date tab icon.
90
+ * @default DateRange
91
+ */
92
+ dateRangeIcon: PropTypes.node,
93
+
94
+ /**
95
+ * Callback called when tab is clicked
96
+ * @param {CalendarOrClockPickerView} view Picker view that was clicked
97
+ */
98
+ onChange: PropTypes.func.isRequired,
99
+
100
+ /**
101
+ * Time tab icon.
102
+ * @default Time
103
+ */
104
+ timeIcon: PropTypes.node,
105
+
106
+ /**
107
+ * Open picker view
108
+ */
109
+ view: PropTypes.oneOf(['day', 'hours', 'minutes', 'month', 'seconds', 'year']).isRequired
110
+ } : void 0;
111
+ export { DateTimePickerTabs };
@@ -1,15 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["ampm", "parsedValue", "dateRangeIcon", "hideTabs", "isMobileKeyboardViewOpen", "onChange", "openView", "setOpenView", "timeIcon", "toggleMobileKeyboardView", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "views"];
3
+ const _excluded = ["ampm", "parsedValue", "isMobileKeyboardViewOpen", "onChange", "openView", "setOpenView", "toggleMobileKeyboardView", "toolbarFormat", "toolbarPlaceholder", "toolbarTitle", "views"];
4
4
  import * as React from 'react';
5
5
  import { styled } from '@mui/material/styles';
6
6
  import { generateUtilityClasses } from '@mui/material';
7
7
  import { PickersToolbarText } from '../internals/components/PickersToolbarText';
8
8
  import { PickersToolbar, pickersToolbarClasses } from '../internals/components/PickersToolbar';
9
9
  import { PickersToolbarButton } from '../internals/components/PickersToolbarButton';
10
- import { DateTimePickerTabs } from './DateTimePickerTabs';
11
10
  import { useLocaleText, useUtils } from '../internals/hooks/useUtils';
12
- import { WrapperVariantContext } from '../internals/components/wrappers/WrapperVariantContext';
13
11
  import { jsx as _jsx } from "react/jsx-runtime";
14
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
13
  export const dateTimePickerToolbarClasses = generateUtilityClasses('MuiDateTimePickerToolbar', ['root', 'dateContainer', 'timeContainer', 'separator']);
@@ -59,12 +57,9 @@ export const DateTimePickerToolbar = props => {
59
57
  const {
60
58
  ampm,
61
59
  parsedValue,
62
- dateRangeIcon,
63
- hideTabs,
64
60
  isMobileKeyboardViewOpen,
65
61
  openView,
66
62
  setOpenView,
67
- timeIcon,
68
63
  toggleMobileKeyboardView,
69
64
  toolbarFormat,
70
65
  toolbarPlaceholder = '––',
@@ -76,8 +71,6 @@ export const DateTimePickerToolbar = props => {
76
71
  const utils = useUtils();
77
72
  const localeText = useLocaleText();
78
73
  const toolbarTitle = toolbarTitleProp != null ? toolbarTitleProp : localeText.dateTimePickerDefaultToolbarTitle;
79
- const wrapperVariant = React.useContext(WrapperVariantContext);
80
- const showTabs = wrapperVariant === 'desktop' ? true : !hideTabs && typeof window !== 'undefined' && window.innerHeight > 667;
81
74
 
82
75
  const formatHours = time => ampm ? utils.format(time, 'hours12h') : utils.format(time, 'hours24h');
83
76
 
@@ -93,70 +86,63 @@ export const DateTimePickerToolbar = props => {
93
86
  return utils.format(parsedValue, 'shortDate');
94
87
  }, [parsedValue, toolbarFormat, toolbarPlaceholder, utils]);
95
88
  const ownerState = props;
96
- return /*#__PURE__*/_jsxs(React.Fragment, {
97
- children: [wrapperVariant !== 'desktop' && /*#__PURE__*/_jsxs(DateTimePickerToolbarRoot, _extends({
98
- toolbarTitle: toolbarTitle,
99
- isMobileKeyboardViewOpen: isMobileKeyboardViewOpen,
100
- toggleMobileKeyboardView: toggleMobileKeyboardView,
101
- className: dateTimePickerToolbarClasses.root
102
- }, other, {
103
- isLandscape: false,
89
+ return /*#__PURE__*/_jsxs(DateTimePickerToolbarRoot, _extends({
90
+ toolbarTitle: toolbarTitle,
91
+ isMobileKeyboardViewOpen: isMobileKeyboardViewOpen,
92
+ toggleMobileKeyboardView: toggleMobileKeyboardView,
93
+ className: dateTimePickerToolbarClasses.root
94
+ }, other, {
95
+ isLandscape: false,
96
+ ownerState: ownerState,
97
+ children: [/*#__PURE__*/_jsxs(DateTimePickerToolbarDateContainer, {
98
+ className: dateTimePickerToolbarClasses.dateContainer,
104
99
  ownerState: ownerState,
105
- children: [/*#__PURE__*/_jsxs(DateTimePickerToolbarDateContainer, {
106
- className: dateTimePickerToolbarClasses.dateContainer,
107
- ownerState: ownerState,
108
- children: [views.includes('year') && /*#__PURE__*/_jsx(PickersToolbarButton, {
109
- tabIndex: -1,
110
- variant: "subtitle1",
111
- onClick: () => setOpenView('year'),
112
- selected: openView === 'year',
113
- value: parsedValue ? utils.format(parsedValue, 'year') : '–'
114
- }), views.includes('day') && /*#__PURE__*/_jsx(PickersToolbarButton, {
115
- tabIndex: -1,
116
- variant: "h4",
117
- onClick: () => setOpenView('day'),
118
- selected: openView === 'day',
119
- value: dateText
100
+ children: [views.includes('year') && /*#__PURE__*/_jsx(PickersToolbarButton, {
101
+ tabIndex: -1,
102
+ variant: "subtitle1",
103
+ onClick: () => setOpenView('year'),
104
+ selected: openView === 'year',
105
+ value: parsedValue ? utils.format(parsedValue, 'year') : '–'
106
+ }), views.includes('day') && /*#__PURE__*/_jsx(PickersToolbarButton, {
107
+ tabIndex: -1,
108
+ variant: "h4",
109
+ onClick: () => setOpenView('day'),
110
+ selected: openView === 'day',
111
+ value: dateText
112
+ })]
113
+ }), /*#__PURE__*/_jsxs(DateTimePickerToolbarTimeContainer, {
114
+ className: dateTimePickerToolbarClasses.timeContainer,
115
+ ownerState: ownerState,
116
+ children: [views.includes('hours') && /*#__PURE__*/_jsx(PickersToolbarButton, {
117
+ variant: "h3",
118
+ onClick: () => setOpenView('hours'),
119
+ selected: openView === 'hours',
120
+ value: parsedValue ? formatHours(parsedValue) : '--'
121
+ }), views.includes('minutes') && /*#__PURE__*/_jsxs(React.Fragment, {
122
+ children: [/*#__PURE__*/_jsx(DateTimePickerToolbarSeparator, {
123
+ variant: "h3",
124
+ value: ":",
125
+ className: dateTimePickerToolbarClasses.separator,
126
+ ownerState: ownerState
127
+ }), /*#__PURE__*/_jsx(PickersToolbarButton, {
128
+ variant: "h3",
129
+ onClick: () => setOpenView('minutes'),
130
+ selected: openView === 'minutes',
131
+ value: parsedValue ? utils.format(parsedValue, 'minutes') : '--'
120
132
  })]
121
- }), /*#__PURE__*/_jsxs(DateTimePickerToolbarTimeContainer, {
122
- className: dateTimePickerToolbarClasses.timeContainer,
123
- ownerState: ownerState,
124
- children: [views.includes('hours') && /*#__PURE__*/_jsx(PickersToolbarButton, {
133
+ }), views.includes('seconds') && /*#__PURE__*/_jsxs(React.Fragment, {
134
+ children: [/*#__PURE__*/_jsx(DateTimePickerToolbarSeparator, {
135
+ variant: "h3",
136
+ value: ":",
137
+ className: dateTimePickerToolbarClasses.separator,
138
+ ownerState: ownerState
139
+ }), /*#__PURE__*/_jsx(PickersToolbarButton, {
125
140
  variant: "h3",
126
- onClick: () => setOpenView('hours'),
127
- selected: openView === 'hours',
128
- value: parsedValue ? formatHours(parsedValue) : '--'
129
- }), views.includes('minutes') && /*#__PURE__*/_jsxs(React.Fragment, {
130
- children: [/*#__PURE__*/_jsx(DateTimePickerToolbarSeparator, {
131
- variant: "h3",
132
- value: ":",
133
- className: dateTimePickerToolbarClasses.separator,
134
- ownerState: ownerState
135
- }), /*#__PURE__*/_jsx(PickersToolbarButton, {
136
- variant: "h3",
137
- onClick: () => setOpenView('minutes'),
138
- selected: openView === 'minutes',
139
- value: parsedValue ? utils.format(parsedValue, 'minutes') : '--'
140
- })]
141
- }), views.includes('seconds') && /*#__PURE__*/_jsxs(React.Fragment, {
142
- children: [/*#__PURE__*/_jsx(DateTimePickerToolbarSeparator, {
143
- variant: "h3",
144
- value: ":",
145
- className: dateTimePickerToolbarClasses.separator,
146
- ownerState: ownerState
147
- }), /*#__PURE__*/_jsx(PickersToolbarButton, {
148
- variant: "h3",
149
- onClick: () => setOpenView('seconds'),
150
- selected: openView === 'seconds',
151
- value: parsedValue ? utils.format(parsedValue, 'seconds') : '--'
152
- })]
141
+ onClick: () => setOpenView('seconds'),
142
+ selected: openView === 'seconds',
143
+ value: parsedValue ? utils.format(parsedValue, 'seconds') : '--'
153
144
  })]
154
145
  })]
155
- })), showTabs && /*#__PURE__*/_jsx(DateTimePickerTabs, {
156
- dateRangeIcon: dateRangeIcon,
157
- timeIcon: timeIcon,
158
- view: openView,
159
- onChange: setOpenView
160
146
  })]
161
- });
147
+ }));
162
148
  };
@@ -1,2 +1,4 @@
1
1
  export { DateTimePicker } from './DateTimePicker';
2
+ export { DateTimePickerTabs } from './DateTimePickerTabs';
2
3
  export type { DateTimePickerProps } from './DateTimePicker';
4
+ export type { DateTimePickerTabsProps } from './DateTimePickerTabs';
@@ -1 +1,2 @@
1
- export { DateTimePicker } from './DateTimePicker';
1
+ export { DateTimePicker } from './DateTimePicker';
2
+ export { DateTimePickerTabs } from './DateTimePickerTabs';
@@ -17,7 +17,8 @@ export interface BaseDateTimePickerProps<TInputDate, TDate> extends ExportedCloc
17
17
  */
18
18
  ampm?: boolean;
19
19
  /**
20
- * To show tabs.
20
+ * Toggles visibility of date time switching tabs
21
+ * @default false for mobile, true for desktop
21
22
  */
22
23
  hideTabs?: boolean;
23
24
  /**
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["onChange", "PaperProps", "PopperProps", "ToolbarComponent", "TransitionComponent", "value", "components", "componentsProps"];
3
+ const _excluded = ["onChange", "PaperProps", "PopperProps", "ToolbarComponent", "TransitionComponent", "value", "components", "componentsProps", "hideTabs"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useDateTimePickerDefaultizedProps, dateTimePickerValueManager } from '../DateTimePicker/shared';
@@ -10,6 +10,7 @@ import { CalendarOrClockPicker } from '../internals/components/CalendarOrClockPi
10
10
  import { useDateTimeValidation } from '../internals/hooks/validation/useDateTimeValidation';
11
11
  import { KeyboardDateInput } from '../internals/components/KeyboardDateInput';
12
12
  import { usePickerState } from '../internals/hooks/usePickerState';
13
+ import { DateTimePickerTabs } from '../DateTimePicker';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
 
15
16
  /**
@@ -36,11 +37,16 @@ export const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function Desk
36
37
  PopperProps,
37
38
  ToolbarComponent = DateTimePickerToolbar,
38
39
  TransitionComponent,
39
- components,
40
- componentsProps
40
+ components: providedComponents,
41
+ componentsProps,
42
+ hideTabs = true
41
43
  } = props,
42
44
  other = _objectWithoutPropertiesLoose(props, _excluded);
43
45
 
46
+ const components = React.useMemo(() => _extends({
47
+ Tabs: DateTimePickerTabs
48
+ }, providedComponents), [providedComponents]);
49
+
44
50
  const AllDateInputProps = _extends({}, inputProps, other, {
45
51
  components,
46
52
  componentsProps,
@@ -62,7 +68,8 @@ export const DesktopDateTimePicker = /*#__PURE__*/React.forwardRef(function Desk
62
68
  ToolbarComponent: ToolbarComponent,
63
69
  DateInputProps: AllDateInputProps,
64
70
  components: components,
65
- componentsProps: componentsProps
71
+ componentsProps: componentsProps,
72
+ hideTabs: hideTabs
66
73
  }, other))
67
74
  }));
68
75
  });
@@ -213,7 +220,8 @@ process.env.NODE_ENV !== "production" ? DesktopDateTimePicker.propTypes = {
213
220
  getViewSwitchingButtonText: PropTypes.func,
214
221
 
215
222
  /**
216
- * To show tabs.
223
+ * Toggles visibility of date time switching tabs
224
+ * @default false for mobile, true for desktop
217
225
  */
218
226
  hideTabs: PropTypes.bool,
219
227
  ignoreInvalidInputs: PropTypes.bool,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["ToolbarComponent", "value", "onChange", "components", "componentsProps"];
3
+ const _excluded = ["ToolbarComponent", "value", "onChange", "components", "componentsProps", "hideTabs"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useDateTimePickerDefaultizedProps, dateTimePickerValueManager } from '../DateTimePicker/shared';
@@ -10,6 +10,7 @@ import { CalendarOrClockPicker } from '../internals/components/CalendarOrClockPi
10
10
  import { useDateTimeValidation } from '../internals/hooks/validation/useDateTimeValidation';
11
11
  import { PureDateInput } from '../internals/components/PureDateInput';
12
12
  import { usePickerState } from '../internals/hooks/usePickerState';
13
+ import { DateTimePickerTabs } from '../DateTimePicker';
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
 
15
16
  /**
@@ -34,11 +35,16 @@ export const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function Mobil
34
35
 
35
36
  const {
36
37
  ToolbarComponent = DateTimePickerToolbar,
37
- components,
38
- componentsProps
38
+ components: providedComponents,
39
+ componentsProps,
40
+ hideTabs = false
39
41
  } = props,
40
42
  other = _objectWithoutPropertiesLoose(props, _excluded);
41
43
 
44
+ const components = React.useMemo(() => _extends({
45
+ Tabs: DateTimePickerTabs
46
+ }, providedComponents), [providedComponents]);
47
+
42
48
  const DateInputProps = _extends({}, inputProps, other, {
43
49
  components,
44
50
  componentsProps,
@@ -57,7 +63,8 @@ export const MobileDateTimePicker = /*#__PURE__*/React.forwardRef(function Mobil
57
63
  ToolbarComponent: ToolbarComponent,
58
64
  DateInputProps: DateInputProps,
59
65
  components: components,
60
- componentsProps: componentsProps
66
+ componentsProps: componentsProps,
67
+ hideTabs: hideTabs
61
68
  }, other))
62
69
  }));
63
70
  });
@@ -213,7 +220,8 @@ process.env.NODE_ENV !== "production" ? MobileDateTimePicker.propTypes = {
213
220
  getViewSwitchingButtonText: PropTypes.func,
214
221
 
215
222
  /**
216
- * To show tabs.
223
+ * Toggles visibility of date time switching tabs
224
+ * @default false for mobile, true for desktop
217
225
  */
218
226
  hideTabs: PropTypes.bool,
219
227
  ignoreInvalidInputs: PropTypes.bool,
@@ -31,6 +31,10 @@ export interface MonthPickerProps<TDate> extends MonthValidationProps<TDate>, Ba
31
31
  * @default false
32
32
  */
33
33
  disableHighlightToday?: boolean;
34
+ autoFocus?: boolean;
35
+ onMonthFocus?: (month: number) => void;
36
+ hasFocus?: boolean;
37
+ onFocusedViewChange?: (newHasFocus: boolean) => void;
34
38
  }
35
39
  export declare function useMonthPickerDefaultizedProps<TDate>(props: MonthPickerProps<TDate>, name: string): DefaultizedProps<MonthPickerProps<TDate>, 'minDate' | 'maxDate' | 'disableFuture' | 'disablePast'>;
36
40
  declare type MonthPickerComponent = (<TDate>(props: MonthPickerProps<TDate> & React.RefAttributes<HTMLDivElement>) => JSX.Element) & {
@@ -1,11 +1,12 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["className", "date", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday"];
3
+ const _excluded = ["className", "date", "disabled", "disableFuture", "disablePast", "maxDate", "minDate", "onChange", "shouldDisableMonth", "readOnly", "disableHighlightToday", "autoFocus", "onMonthFocus", "hasFocus", "onFocusedViewChange"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
7
+ import { useTheme } from '@mui/system';
7
8
  import { styled, useThemeProps } from '@mui/material/styles';
8
- import { unstable_composeClasses as composeClasses } from '@mui/material';
9
+ import { unstable_composeClasses as composeClasses, useControlled, useEventCallback } from '@mui/material';
9
10
  import { PickersMonth } from './PickersMonth';
10
11
  import { useUtils, useNow, useDefaultDates } from '../internals/hooks/useUtils';
11
12
  import { getMonthPickerUtilityClass } from './monthPickerClasses';
@@ -64,14 +65,19 @@ export const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(in
64
65
  onChange,
65
66
  shouldDisableMonth,
66
67
  readOnly,
67
- disableHighlightToday
68
+ disableHighlightToday,
69
+ autoFocus = false,
70
+ onMonthFocus,
71
+ hasFocus,
72
+ onFocusedViewChange
68
73
  } = props,
69
74
  other = _objectWithoutPropertiesLoose(props, _excluded);
70
75
 
71
76
  const ownerState = props;
72
77
  const classes = useUtilityClasses(ownerState);
78
+ const theme = useTheme();
73
79
  const selectedDateOrToday = date != null ? date : now;
74
- const focusedMonth = React.useMemo(() => {
80
+ const selectedMonth = React.useMemo(() => {
75
81
  if (date != null) {
76
82
  return utils.getMonth(date);
77
83
  }
@@ -82,8 +88,8 @@ export const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(in
82
88
 
83
89
  return utils.getMonth(now);
84
90
  }, [now, date, utils, disableHighlightToday]);
85
-
86
- const isMonthDisabled = month => {
91
+ const [focusedMonth, setFocusedMonth] = React.useState(() => selectedMonth || utils.getMonth(now));
92
+ const isMonthDisabled = React.useCallback(month => {
87
93
  const firstEnabledMonth = utils.startOfMonth(disablePast && utils.isAfter(now, minDate) ? now : minDate);
88
94
  const lastEnabledMonth = utils.startOfMonth(disableFuture && utils.isBefore(now, maxDate) ? now : maxDate);
89
95
 
@@ -100,7 +106,7 @@ export const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(in
100
106
  }
101
107
 
102
108
  return shouldDisableMonth(month);
103
- };
109
+ }, [disableFuture, disablePast, maxDate, minDate, now, shouldDisableMonth, utils]);
104
110
 
105
111
  const onMonthSelect = month => {
106
112
  if (readOnly) {
@@ -111,20 +117,87 @@ export const MonthPicker = /*#__PURE__*/React.forwardRef(function MonthPicker(in
111
117
  onChange(newDate, 'finish');
112
118
  };
113
119
 
120
+ const [internalHasFocus, setInternalHasFocus] = useControlled({
121
+ name: 'MonthPicker',
122
+ state: 'hasFocus',
123
+ controlled: hasFocus,
124
+ default: autoFocus
125
+ });
126
+ const changeHasFocus = React.useCallback(newHasFocus => {
127
+ setInternalHasFocus(newHasFocus);
128
+
129
+ if (onFocusedViewChange) {
130
+ onFocusedViewChange(newHasFocus);
131
+ }
132
+ }, [setInternalHasFocus, onFocusedViewChange]);
133
+ const focusMonth = React.useCallback(month => {
134
+ if (!isMonthDisabled(utils.setMonth(selectedDateOrToday, month))) {
135
+ setFocusedMonth(month);
136
+ changeHasFocus(true);
137
+
138
+ if (onMonthFocus) {
139
+ onMonthFocus(month);
140
+ }
141
+ }
142
+ }, [selectedDateOrToday, isMonthDisabled, utils, onMonthFocus, changeHasFocus]);
143
+ React.useEffect(() => {
144
+ setFocusedMonth(prevFocusedMonth => selectedMonth !== null && prevFocusedMonth !== selectedMonth ? selectedMonth : prevFocusedMonth);
145
+ }, [selectedMonth]);
146
+ const handleKeyDown = useEventCallback(event => {
147
+ const monthsInYear = 12;
148
+ const monthsInRow = 3;
149
+
150
+ switch (event.key) {
151
+ case 'ArrowUp':
152
+ focusMonth((monthsInYear + focusedMonth - monthsInRow) % monthsInYear);
153
+ event.preventDefault();
154
+ break;
155
+
156
+ case 'ArrowDown':
157
+ focusMonth((monthsInYear + focusedMonth + monthsInRow) % monthsInYear);
158
+ event.preventDefault();
159
+ break;
160
+
161
+ case 'ArrowLeft':
162
+ focusMonth((monthsInYear + focusedMonth + (theme.direction === 'ltr' ? -1 : 1)) % monthsInYear);
163
+ event.preventDefault();
164
+ break;
165
+
166
+ case 'ArrowRight':
167
+ focusMonth((monthsInYear + focusedMonth + (theme.direction === 'ltr' ? 1 : -1)) % monthsInYear);
168
+ event.preventDefault();
169
+ break;
170
+
171
+ default:
172
+ break;
173
+ }
174
+ });
175
+ const handleMonthFocus = React.useCallback((event, month) => {
176
+ focusMonth(month);
177
+ }, [focusMonth]);
178
+ const handleMonthBlur = React.useCallback(() => {
179
+ changeHasFocus(false);
180
+ }, [changeHasFocus]);
114
181
  const currentMonthNumber = utils.getMonth(now);
115
182
  return /*#__PURE__*/_jsx(MonthPickerRoot, _extends({
116
183
  ref: ref,
117
184
  className: clsx(classes.root, className),
118
- ownerState: ownerState
185
+ ownerState: ownerState,
186
+ onKeyDown: handleKeyDown
119
187
  }, other, {
120
188
  children: utils.getMonthArray(selectedDateOrToday).map(month => {
121
189
  const monthNumber = utils.getMonth(month);
122
190
  const monthText = utils.format(month, 'monthShort');
191
+ const isDisabled = disabled || isMonthDisabled(month);
123
192
  return /*#__PURE__*/_jsx(PickersMonth, {
124
193
  value: monthNumber,
125
- selected: monthNumber === focusedMonth,
194
+ selected: monthNumber === selectedMonth,
195
+ tabIndex: monthNumber === focusedMonth && !isDisabled ? 0 : -1,
196
+ hasFocus: internalHasFocus && monthNumber === focusedMonth,
126
197
  onSelect: onMonthSelect,
127
- disabled: disabled || isMonthDisabled(month),
198
+ onFocus: handleMonthFocus,
199
+ onBlur: handleMonthBlur,
200
+ disabled: isDisabled,
128
201
  "aria-current": currentMonthNumber === monthNumber ? 'date' : undefined,
129
202
  children: monthText
130
203
  }, monthText);
@@ -136,6 +209,7 @@ process.env.NODE_ENV !== "production" ? MonthPicker.propTypes = {
136
209
  // | These PropTypes are generated from the TypeScript type definitions |
137
210
  // | To update them edit the TypeScript types and run "yarn proptypes" |
138
211
  // ----------------------------------------------------------------------
212
+ autoFocus: PropTypes.bool,
139
213
 
140
214
  /**
141
215
  * Override or extend the styles applied to the component.
@@ -174,6 +248,7 @@ process.env.NODE_ENV !== "production" ? MonthPicker.propTypes = {
174
248
  * @default false
175
249
  */
176
250
  disablePast: PropTypes.bool,
251
+ hasFocus: PropTypes.bool,
177
252
 
178
253
  /**
179
254
  * Maximal selectable date. @DateIOType
@@ -189,6 +264,8 @@ process.env.NODE_ENV !== "production" ? MonthPicker.propTypes = {
189
264
  * Callback fired on date change.
190
265
  */
191
266
  onChange: PropTypes.func.isRequired,
267
+ onFocusedViewChange: PropTypes.func,
268
+ onMonthFocus: PropTypes.func,
192
269
 
193
270
  /**
194
271
  * If `true` picker is readonly