@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 +1,7 @@
1
- export { default as AdapterDateFns } from '@date-io/date-fns';
1
+ import BaseAdapterDateFns from '@date-io/date-fns';
2
+ import { MuiFormatTokenMap, MuiPickerFieldAdapter } from '../internals/models';
3
+ export declare class AdapterDateFns extends BaseAdapterDateFns implements MuiPickerFieldAdapter<Date> {
4
+ formatTokenMap: MuiFormatTokenMap;
5
+ expandFormat: (format: string) => string;
6
+ getFormatHelperText: (format: string) => string;
7
+ }
@@ -1 +1,51 @@
1
- export { default as AdapterDateFns } from '@date-io/date-fns';
1
+ import BaseAdapterDateFns from '@date-io/date-fns';
2
+ import defaultLocale from 'date-fns/locale/en-US'; // @ts-ignore
3
+
4
+ import longFormatters from 'date-fns/_lib/format/longFormatters';
5
+ const formatTokenMap = {
6
+ y: 'year',
7
+ yy: 'year',
8
+ yyy: 'year',
9
+ yyyy: 'year',
10
+ MMMM: 'month',
11
+ MM: 'month',
12
+ DD: 'day',
13
+ d: 'day',
14
+ dd: 'day',
15
+ H: 'hour',
16
+ HH: 'hour',
17
+ h: 'hour',
18
+ hh: 'hour',
19
+ mm: 'minute',
20
+ ss: 'second',
21
+ a: 'am-pm',
22
+ aa: 'am-pm',
23
+ aaa: 'am-pm'
24
+ };
25
+ export class AdapterDateFns extends BaseAdapterDateFns {
26
+ constructor(...args) {
27
+ super(...args);
28
+ this.formatTokenMap = formatTokenMap;
29
+
30
+ this.expandFormat = format => {
31
+ const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
32
+
33
+ return format.match(longFormatRegexp).map(token => {
34
+ const firstCharacter = token[0];
35
+
36
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
37
+ const longFormatter = longFormatters[firstCharacter];
38
+ const locale = this.locale || defaultLocale;
39
+ return longFormatter(token, locale.formatLong, {});
40
+ }
41
+
42
+ return token;
43
+ }).join('');
44
+ };
45
+
46
+ this.getFormatHelperText = format => {
47
+ return this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
48
+ };
49
+ }
50
+
51
+ }
@@ -1 +1,12 @@
1
- export { default as AdapterDayjs } from '@date-io/dayjs';
1
+ import { Dayjs } from 'dayjs';
2
+ import BaseAdapterDayjs from '@date-io/dayjs';
3
+ import { MuiFormatTokenMap, MuiPickerFieldAdapter } from '../internals/models';
4
+ export declare class AdapterDayjs extends BaseAdapterDayjs implements MuiPickerFieldAdapter<Dayjs> {
5
+ formatTokenMap: MuiFormatTokenMap;
6
+ /**
7
+ * The current getFormatHelperText method uses an outdated format parsing logic.
8
+ * We should use this one in the future to support all localized formats.
9
+ */
10
+ expandFormat: (format: string) => string;
11
+ getFormatHelperText: (format: string) => string;
12
+ }
@@ -1 +1,45 @@
1
- export { default as AdapterDayjs } from '@date-io/dayjs';
1
+ import BaseAdapterDayjs from '@date-io/dayjs';
2
+ const formatTokenMap = {
3
+ YY: 'year',
4
+ YYYY: 'year',
5
+ M: 'month',
6
+ MM: 'month',
7
+ MMM: 'month',
8
+ MMMM: 'month',
9
+ D: 'day',
10
+ DD: 'day',
11
+ H: 'hour',
12
+ HH: 'hour',
13
+ h: 'hour',
14
+ hh: 'hour',
15
+ m: 'minute',
16
+ mm: 'minute',
17
+ s: 'second',
18
+ ss: 'second',
19
+ A: 'am-pm',
20
+ a: 'am-pm'
21
+ };
22
+ export class AdapterDayjs extends BaseAdapterDayjs {
23
+ constructor(...args) {
24
+ super(...args);
25
+ this.formatTokenMap = formatTokenMap;
26
+
27
+ this.expandFormat = format => {
28
+ var _this$rawDayJsInstanc;
29
+
30
+ const localeFormats = (_this$rawDayJsInstanc = this.rawDayJsInstance.Ls[this.locale || 'en']) == null ? void 0 : _this$rawDayJsInstanc.formats; // @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
31
+
32
+ const t = formatBis => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));
33
+
34
+ return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, a, b) => {
35
+ const B = b && b.toUpperCase();
36
+ return a || localeFormats[b] || t(localeFormats[B]);
37
+ });
38
+ };
39
+
40
+ this.getFormatHelperText = format => {
41
+ return this.expandFormat(format).replace(/a/gi, '(a|p)m').toLocaleLowerCase();
42
+ };
43
+ }
44
+
45
+ }
package/CHANGELOG.md CHANGED
@@ -3,6 +3,83 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 5.17.0
7
+
8
+ _Sep 2, 2022_
9
+
10
+ 🎉 We are excited to finally introduce a stable release (v5.0.0) for the `@mui/x-date-pickers` and `@mui/x-date-pickers-pro` packages!
11
+
12
+ If you are still using picker components from the `lab`, take a look at the [migration guide](https://mui.com/x/react-date-pickers/migration-lab/).
13
+
14
+ We'd like to offer a big thanks to the 9 contributors who made this release possible. Here are some highlights ✨:
15
+
16
+ - 🎁 Implement Lazy loading (#5214) @DanailH
17
+
18
+ Pro users now can try the experimental lazy loading feature.
19
+ In a few steps, you can load your data on demand, as the rows are displayed.
20
+
21
+ To enable this feature, add `experimentalFeatures={{ lazyLoading: true }}`.
22
+ Lazy Loading requires a few other settings.
23
+ See the [documentation](https://mui.com/x/react-data-grid/row-updates/#lazy-loading) to explore the example in detail.
24
+
25
+ - 🚀 Improve `pickers` focus management (#5820) @alexfauquette
26
+ - 🎉 Enable disabling `day` on date range picker depending on `position` (#5773) @alexfauquette
27
+ - ✨ Various improvements
28
+ - 📚 Documentation improvements
29
+ - 🐞 Bugfixes
30
+
31
+ ### `@mui/x-data-grid@v5.17.0` / `@mui/x-data-grid-pro@v5.17.0` / `@mui/x-data-grid-premium@v5.17.0`
32
+
33
+ #### Changes
34
+
35
+ - [DataGrid] Add `sort` prop to columns panel slot (#5888) @gavbrennan
36
+ - [DataGrid] Do not throw if `fieldToFocus` cannot be found (#5871) @cherniavskii
37
+ - [DataGrid] Support `getRowId` in the `replaceRows` method (#5988) @flaviendelangle
38
+ - [DataGridPro] Add class name to row with open detail panel (#5924) @m4theushw
39
+ - [DataGridPro] Fix crash when using `pinnedRows` + `getRowClassName` props and `rows=[]` (#5851) @cherniavskii
40
+ - [DataGridPro] Fix filtering with inactive filter items (#5993) @alexfauquette
41
+ - [DataGridPro] Implement Lazy loading (#5214) @DanailH
42
+ - [DataGridPro] Support pinned columns and dynamic row height (#5782) @m4theushw
43
+ - [DataGridPremium] Add state initializer for column groups (#5963) @alexfauquette
44
+ - [DataGridPremium] Update grouping when `groupingValueGetter` changes (#5919) @flaviendelangle
45
+ - [DataGridPremium] Use the aggregated value on tree data real groups (#5953) @flaviendelangle
46
+
47
+ ### `@mui/x-date-pickers@v5.0.0` / `@mui/x-date-pickers-pro@v5.0.0`
48
+
49
+ #### Changes
50
+
51
+ - [DatePicker] Improve focus management (#5820) @alexfauquette
52
+ - [DateRangePicker] Enable disabling `day` depending on `position` (#5773) @alexfauquette
53
+ - [DateTimePicker] Create a new `tabs` component slot (#5972) @LukasTy
54
+ - [pickers] Do not forward validation props to the DOM on field components (#5971) @flaviendelangle
55
+ - [pickers] Do not hardcode `date-fns` elements in field components (#5975) @flaviendelangle
56
+ - [pickers] Do not require `date-fns` in `@mui/x-date-pickers-pro` (#5941) @flaviendelangle
57
+ - [pickers] Fix mobile picker not opening on label click (#5651) @LukasTy
58
+ - [pickers] Improve DOM event management on `useField` (#5901) @flaviendelangle
59
+ - [pickers] Include `community` package `themeAugmentation` in `pro` package types (#5969) @LukasTy
60
+ - [pickers] Rename `DateRangeField` into `SingleInputDateRangeField` (#5961) @flaviendelangle
61
+ - [pickers] Support `isSameError` on field components (#5984) @flaviendelangle
62
+
63
+ ### Docs
64
+
65
+ - [docs] Add `description` and `default` to pickers slots (#5893) @alexfauquette
66
+ - [docs] Fix typo (#5945) @wettopa
67
+ - [docs] Fix typo `onYearPicker` to `onYearChange` (#5954) @alexfauquette
68
+ - [docs] Update `GridCellParams`'s `value` description (#5849) @cherniavskii
69
+ - [docs] Update `README.md` to match Introduction section of the docs (#5754) @samuelsycamore
70
+
71
+ ### Core
72
+
73
+ - [core] Fix typo (#5990) @flaviendelangle
74
+ - [core] Remove old babel resolve rule (#5939) @oliviertassinari
75
+ - [core] Remove outdated TODO (#5956) @flaviendelangle
76
+ - [core] Upgrade monorepo (#5960) @cherniavskii
77
+ - [core] Fix statics (#5986) @DanailH
78
+ - [core] Remove unused dependencies (#5937) @oliviertassinari
79
+ - [license] Remove CLI (#5757) @flaviendelangle
80
+ - [test] Fix time zone sensitive test (#5955) @LukasTy
81
+ - [test] Use `userEvent.mousePress` instead of `fireClickEvent` (#5920) @cherniavskii
82
+
6
83
  ## 5.16.0
7
84
 
8
85
  _Aug 25, 2022_
@@ -585,7 +662,7 @@ We'd like to offer a big thanks to the 15 contributors who made this release pos
585
662
 
586
663
  **MonthPicker**: The prop `onMonthChange` has been removed, you can use `onChange` instead since every change is a month change
587
664
 
588
- **YearPicker**: The prop `onYearPicker` has been removed, you can use `onChange` instead since every change is a year change
665
+ **YearPicker**: The prop `onYearChange` has been removed, you can use `onChange` instead since every change is a year change
589
666
 
590
667
  **DayPicker**: The prop `isDateDisabled` has been removed, you can now use the same validation props as for the other components (`maxDate`, `minDate`, `shouldDisableDate`, `disableFuture` and `disablePast`)
591
668
 
@@ -11,6 +11,7 @@ export interface CalendarPickerSlotsComponent extends PickersCalendarHeaderSlots
11
11
  export interface CalendarPickerSlotsComponentsProps extends PickersCalendarHeaderSlotsComponentsProps {
12
12
  }
13
13
  export interface CalendarPickerProps<TDate> extends ExportedDayPickerProps<TDate>, BaseDateValidationProps<TDate>, DayValidationProps<TDate>, YearValidationProps<TDate>, MonthValidationProps<TDate>, ExportedCalendarHeaderProps<TDate> {
14
+ autoFocus?: boolean;
14
15
  className?: string;
15
16
  classes?: Partial<CalendarPickerClasses>;
16
17
  /**
@@ -85,8 +86,10 @@ export interface CalendarPickerProps<TDate> extends ExportedDayPickerProps<TDate
85
86
  * @returns {void|Promise} -
86
87
  */
87
88
  onMonthChange?: (month: TDate) => void | Promise<void>;
89
+ focusedView?: CalendarPickerView | null;
90
+ onFocusedViewChange?: (view: CalendarPickerView) => (newHasFocus: boolean) => void;
88
91
  }
89
- export declare type ExportedCalendarPickerProps<TDate> = Omit<CalendarPickerProps<TDate>, 'date' | 'view' | 'views' | 'openTo' | 'onChange' | 'changeView' | 'slideDirection' | 'currentMonth' | 'className' | 'classes' | 'components' | 'componentsProps'>;
92
+ export declare type ExportedCalendarPickerProps<TDate> = Omit<CalendarPickerProps<TDate>, 'date' | 'view' | 'views' | 'openTo' | 'onChange' | 'changeView' | 'slideDirection' | 'currentMonth' | 'className' | 'classes' | 'components' | 'componentsProps' | 'onFocusedViewChange' | 'focusedView'>;
90
93
  export declare type CalendarPickerDefaultizedProps<TDate> = DefaultizedProps<CalendarPickerProps<TDate>, 'views' | 'openTo' | 'loading' | 'reduceAnimations' | 'renderLoading' | keyof BaseDateValidationProps<TDate>>;
91
94
  declare type CalendarPickerComponent = (<TDate>(props: CalendarPickerProps<TDate> & React.RefAttributes<HTMLDivElement>) => JSX.Element) & {
92
95
  propTypes?: any;
@@ -1,12 +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 = ["autoFocus", "onViewChange", "date", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday"];
3
+ const _excluded = ["autoFocus", "onViewChange", "date", "disableFuture", "disablePast", "defaultCalendarMonth", "onChange", "onYearChange", "onMonthChange", "reduceAnimations", "shouldDisableDate", "shouldDisableMonth", "shouldDisableYear", "view", "views", "openTo", "className", "disabled", "readOnly", "minDate", "maxDate", "disableHighlightToday", "focusedView", "onFocusedViewChange"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import clsx from 'clsx';
7
7
  import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import { unstable_composeClasses as composeClasses } from '@mui/material';
9
- import { unstable_useId as useId } from '@mui/material/utils';
9
+ import { useControlled, unstable_useId as useId, useEventCallback } from '@mui/material/utils';
10
10
  import { MonthPicker } from '../MonthPicker/MonthPicker';
11
11
  import { useCalendarState } from './useCalendarState';
12
12
  import { useDefaultDates, useUtils } from '../internals/hooks/useUtils';
@@ -109,7 +109,9 @@ export const CalendarPicker = /*#__PURE__*/React.forwardRef(function CalendarPic
109
109
  readOnly,
110
110
  minDate,
111
111
  maxDate,
112
- disableHighlightToday
112
+ disableHighlightToday,
113
+ focusedView,
114
+ onFocusedViewChange
113
115
  } = props,
114
116
  other = _objectWithoutPropertiesLoose(props, _excluded);
115
117
 
@@ -163,10 +165,8 @@ export const CalendarPicker = /*#__PURE__*/React.forwardRef(function CalendarPic
163
165
  changeMonth(startOfMonth);
164
166
  }
165
167
 
166
- changeFocusedDay(closestEnabledDate);
167
- }, [changeFocusedDay, disableFuture, disablePast, isDateDisabled, maxDate, minDate, onChange, onMonthChange, changeMonth, openNext, utils]); // TODO: Use same behavior as `handleDateMonthChange` to avoid selecting a date in another year.
168
- // Needs startOfYear / endOfYear methods in adapter.
169
-
168
+ changeFocusedDay(closestEnabledDate, true);
169
+ }, [changeFocusedDay, disableFuture, disablePast, isDateDisabled, maxDate, minDate, onChange, onMonthChange, changeMonth, openNext, utils]);
170
170
  const handleDateYearChange = React.useCallback((newDate, selectionState) => {
171
171
  const startOfYear = utils.startOfYear(newDate);
172
172
  const endOfYear = utils.endOfYear(newDate);
@@ -188,7 +188,7 @@ export const CalendarPicker = /*#__PURE__*/React.forwardRef(function CalendarPic
188
188
  changeMonth(startOfYear);
189
189
  }
190
190
 
191
- changeFocusedDay(closestEnabledDate);
191
+ changeFocusedDay(closestEnabledDate, true);
192
192
  }, [changeFocusedDay, disableFuture, disablePast, isDateDisabled, maxDate, minDate, onChange, onYearChange, openNext, utils, changeMonth]);
193
193
  const onSelectedDayChange = React.useCallback((day, isFinish) => {
194
194
  if (date && day) {
@@ -238,6 +238,27 @@ export const CalendarPicker = /*#__PURE__*/React.forwardRef(function CalendarPic
238
238
  disabled
239
239
  };
240
240
  const gridLabelId = `${id}-grid-label`;
241
+ const [internalFocusedView, setInternalFocusedView] = useControlled({
242
+ name: 'DayPicker',
243
+ state: 'focusedView',
244
+ controlled: focusedView,
245
+ default: autoFocus ? openView : null
246
+ });
247
+ const hasFocus = internalFocusedView !== null;
248
+ const handleFocusedViewChange = useEventCallback(eventView => newHasFocus => {
249
+ if (onFocusedViewChange) {
250
+ // Use the calendar or clock logic
251
+ onFocusedViewChange(eventView)(newHasFocus);
252
+ return;
253
+ } // If alone, do the local modifications
254
+
255
+
256
+ if (newHasFocus) {
257
+ setInternalFocusedView(eventView);
258
+ } else {
259
+ setInternalFocusedView(prevView => prevView === eventView ? null : prevView);
260
+ }
261
+ });
241
262
  return /*#__PURE__*/_jsxs(CalendarPickerRoot, {
242
263
  ref: ref,
243
264
  className: clsx(classes.root, className),
@@ -268,12 +289,17 @@ export const CalendarPicker = /*#__PURE__*/React.forwardRef(function CalendarPic
268
289
  autoFocus: autoFocus,
269
290
  date: date,
270
291
  onChange: handleDateYearChange,
271
- shouldDisableYear: shouldDisableYear
292
+ shouldDisableYear: shouldDisableYear,
293
+ hasFocus: hasFocus,
294
+ onFocusedViewChange: handleFocusedViewChange('year')
272
295
  })), openView === 'month' && /*#__PURE__*/_jsx(MonthPicker, _extends({}, baseDateValidationProps, commonViewProps, {
296
+ autoFocus: autoFocus,
297
+ hasFocus: hasFocus,
273
298
  className: className,
274
299
  date: date,
275
300
  onChange: handleDateMonthChange,
276
- shouldDisableMonth: shouldDisableMonth
301
+ shouldDisableMonth: shouldDisableMonth,
302
+ onFocusedViewChange: handleFocusedViewChange('month')
277
303
  })), openView === 'day' && /*#__PURE__*/_jsx(DayPicker, _extends({}, other, calendarState, baseDateValidationProps, commonViewProps, {
278
304
  autoFocus: autoFocus,
279
305
  onMonthSwitchingAnimationEnd: onMonthSwitchingAnimationEnd,
@@ -282,6 +308,8 @@ export const CalendarPicker = /*#__PURE__*/React.forwardRef(function CalendarPic
282
308
  selectedDays: [date],
283
309
  onSelectedDaysChange: onSelectedDayChange,
284
310
  shouldDisableDate: shouldDisableDate,
311
+ hasFocus: hasFocus,
312
+ onFocusedViewChange: handleFocusedViewChange('day'),
285
313
  gridLabelId: gridLabelId
286
314
  }))]
287
315
  })
@@ -346,6 +374,7 @@ process.env.NODE_ENV !== "production" ? CalendarPicker.propTypes = {
346
374
  * @default false
347
375
  */
348
376
  disablePast: PropTypes.bool,
377
+ focusedView: PropTypes.oneOf(['day', 'month', 'year']),
349
378
 
350
379
  /**
351
380
  * Get aria-label text for switching between views button.
@@ -382,6 +411,7 @@ process.env.NODE_ENV !== "production" ? CalendarPicker.propTypes = {
382
411
  * Callback fired on date change
383
412
  */
384
413
  onChange: PropTypes.func.isRequired,
414
+ onFocusedViewChange: PropTypes.func,
385
415
 
386
416
  /**
387
417
  * Callback firing on month change @DateIOType.
@@ -4,7 +4,6 @@ import { PickerOnChangeFn } from '../internals/hooks/useViews';
4
4
  import { SlideDirection, SlideTransitionProps } from './PickersSlideTransition';
5
5
  import { BaseDateValidationProps, DayValidationProps } from '../internals/hooks/validation/models';
6
6
  export interface ExportedDayPickerProps<TDate> extends Pick<PickersDayProps<TDate>, 'disableHighlightToday' | 'showDaysOutsideCurrentMonth'> {
7
- autoFocus?: boolean;
8
7
  /**
9
8
  * If `true` renders `LoadingComponent` in calendar instead of calendar view.
10
9
  * Can be used to preload information and show it in calendar.
@@ -49,6 +48,8 @@ export interface DayPickerProps<TDate> extends ExportedDayPickerProps<TDate>, Da
49
48
  reduceAnimations: boolean;
50
49
  slideDirection: SlideDirection;
51
50
  TransitionProps?: Partial<SlideTransitionProps>;
51
+ hasFocus?: boolean;
52
+ onFocusedViewChange?: (newHasFocus: boolean) => void;
52
53
  gridLabelId?: string;
53
54
  }
54
55
  /**
@@ -1,12 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import Typography from '@mui/material/Typography';
4
- import { styled } from '@mui/material/styles';
4
+ import { styled, useTheme } from '@mui/material/styles';
5
5
  import { PickersDay } from '../PickersDay/PickersDay';
6
6
  import { useUtils, useNow } from '../internals/hooks/useUtils';
7
7
  import { DAY_SIZE, DAY_MARGIN } from '../internals/constants/dimensions';
8
8
  import { PickersSlideTransition } from './PickersSlideTransition';
9
9
  import { useIsDayDisabled } from '../internals/hooks/validation/useDateValidation';
10
+ import { findClosestEnabledDate } from '../internals/utils/date-utils';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
13
 
@@ -55,7 +56,6 @@ export function DayPicker(props) {
55
56
  const now = useNow();
56
57
  const utils = useUtils();
57
58
  const {
58
- autoFocus,
59
59
  onFocusedDayChange,
60
60
  className,
61
61
  currentMonth,
@@ -82,6 +82,8 @@ export function DayPicker(props) {
82
82
  maxDate,
83
83
  shouldDisableDate,
84
84
  dayOfWeekFormatter = defaultDayOfWeekFormatter,
85
+ hasFocus,
86
+ onFocusedViewChange,
85
87
  gridLabelId
86
88
  } = props;
87
89
  const isDateDisabled = useIsDayDisabled({
@@ -91,6 +93,12 @@ export function DayPicker(props) {
91
93
  disablePast,
92
94
  disableFuture
93
95
  });
96
+ const [internalFocusedDay, setInternalFocusedDay] = React.useState(() => focusedDay || now);
97
+ const changeHasFocus = React.useCallback(newHasFocus => {
98
+ if (onFocusedViewChange) {
99
+ onFocusedViewChange(newHasFocus);
100
+ }
101
+ }, [onFocusedViewChange]);
94
102
  const handleDaySelect = React.useCallback((day, isFinish = 'finish') => {
95
103
  if (readOnly) {
96
104
  return;
@@ -98,6 +106,72 @@ export function DayPicker(props) {
98
106
 
99
107
  onSelectedDaysChange(day, isFinish);
100
108
  }, [onSelectedDaysChange, readOnly]);
109
+ const focusDay = React.useCallback(day => {
110
+ if (!isDateDisabled(day)) {
111
+ onFocusedDayChange(day);
112
+ setInternalFocusedDay(day);
113
+ changeHasFocus(true);
114
+ }
115
+ }, [isDateDisabled, onFocusedDayChange, changeHasFocus]);
116
+ const theme = useTheme();
117
+
118
+ function handleKeyDown(event, day) {
119
+ switch (event.key) {
120
+ case 'ArrowUp':
121
+ focusDay(utils.addDays(day, -7));
122
+ event.preventDefault();
123
+ break;
124
+
125
+ case 'ArrowDown':
126
+ focusDay(utils.addDays(day, 7));
127
+ event.preventDefault();
128
+ break;
129
+
130
+ case 'ArrowLeft':
131
+ focusDay(utils.addDays(day, theme.direction === 'ltr' ? -1 : 1));
132
+ event.preventDefault();
133
+ break;
134
+
135
+ case 'ArrowRight':
136
+ focusDay(utils.addDays(day, theme.direction === 'ltr' ? 1 : -1));
137
+ event.preventDefault();
138
+ break;
139
+
140
+ case 'Home':
141
+ focusDay(utils.startOfWeek(day));
142
+ event.preventDefault();
143
+ break;
144
+
145
+ case 'End':
146
+ focusDay(utils.endOfWeek(day));
147
+ event.preventDefault();
148
+ break;
149
+
150
+ case 'PageUp':
151
+ focusDay(utils.getNextMonth(day));
152
+ event.preventDefault();
153
+ break;
154
+
155
+ case 'PageDown':
156
+ focusDay(utils.getPreviousMonth(day));
157
+ event.preventDefault();
158
+ break;
159
+
160
+ default:
161
+ break;
162
+ }
163
+ }
164
+
165
+ function handleFocus(event, day) {
166
+ focusDay(day);
167
+ }
168
+
169
+ function handleBlur(event, day) {
170
+ if (hasFocus && utils.isSameDay(internalFocusedDay, day)) {
171
+ changeHasFocus(false);
172
+ }
173
+ }
174
+
101
175
  const currentMonthNumber = utils.getMonth(currentMonth);
102
176
  const validSelectedDays = selectedDays.filter(day => !!day).map(day => utils.startOfDay(day)); // need a new ref whenever the `key` of the transition changes: http://reactcommunity.org/react-transition-group/transition/#Transition-prop-nodeRef.
103
177
 
@@ -105,6 +179,24 @@ export function DayPicker(props) {
105
179
 
106
180
  const slideNodeRef = React.useMemo(() => /*#__PURE__*/React.createRef(), [transitionKey]);
107
181
  const startOfCurrentWeek = utils.startOfWeek(now);
182
+ const focusableDay = React.useMemo(() => {
183
+ const startOfMonth = utils.startOfMonth(currentMonth);
184
+ const endOfMonth = utils.endOfMonth(currentMonth);
185
+
186
+ if (isDateDisabled(internalFocusedDay) || utils.isAfterDay(internalFocusedDay, endOfMonth) || utils.isBeforeDay(internalFocusedDay, startOfMonth)) {
187
+ return findClosestEnabledDate({
188
+ utils,
189
+ date: internalFocusedDay,
190
+ minDate: startOfMonth,
191
+ maxDate: endOfMonth,
192
+ disablePast,
193
+ disableFuture,
194
+ isDateDisabled
195
+ });
196
+ }
197
+
198
+ return internalFocusedDay;
199
+ }, [currentMonth, disableFuture, disablePast, internalFocusedDay, isDateDisabled, utils]);
108
200
  return /*#__PURE__*/_jsxs("div", {
109
201
  role: "grid",
110
202
  "aria-labelledby": gridLabelId,
@@ -136,6 +228,7 @@ export function DayPicker(props) {
136
228
  children: utils.getWeekArray(currentMonth).map(week => /*#__PURE__*/_jsx(PickersCalendarWeek, {
137
229
  role: "row",
138
230
  children: week.map(day => {
231
+ const isFocusableDay = focusableDay !== null && utils.isSameDay(day, focusableDay);
139
232
  const isSelected = validSelectedDays.some(selectedDay => utils.isSameDay(selectedDay, day));
140
233
  const isToday = utils.isSameDay(day, now);
141
234
  const pickersDayProps = {
@@ -143,14 +236,17 @@ export function DayPicker(props) {
143
236
  day,
144
237
  isAnimating: isMonthSwitchingAnimating,
145
238
  disabled: disabled || isDateDisabled(day),
146
- autoFocus: autoFocus && focusedDay !== null && utils.isSameDay(day, focusedDay),
239
+ autoFocus: hasFocus && isFocusableDay,
147
240
  today: isToday,
148
241
  outsideCurrentMonth: utils.getMonth(day) !== currentMonthNumber,
149
242
  selected: isSelected,
150
243
  disableHighlightToday,
151
244
  showDaysOutsideCurrentMonth,
152
- onDayFocus: onFocusedDayChange,
245
+ onKeyDown: handleKeyDown,
246
+ onFocus: handleFocus,
247
+ onBlur: handleBlur,
153
248
  onDaySelect: handleDaySelect,
249
+ tabIndex: isFocusableDay ? 0 : -1,
154
250
  role: 'gridcell',
155
251
  'aria-selected': isSelected
156
252
  };
@@ -6,7 +6,15 @@ import { ExportedArrowSwitcherProps, PickersArrowSwitcherSlotsComponent, Pickers
6
6
  import { CalendarPickerView } from '../internals/models';
7
7
  export declare type ExportedCalendarHeaderProps<TDate> = Pick<PickersCalendarHeaderProps<TDate>, 'getViewSwitchingButtonText' | 'leftArrowButtonText' | 'rightArrowButtonText'>;
8
8
  export interface PickersCalendarHeaderSlotsComponent extends PickersArrowSwitcherSlotsComponent {
9
+ /**
10
+ * Button displayed to switch between different calendar views.
11
+ * @default IconButton
12
+ */
9
13
  SwitchViewButton: React.ElementType;
14
+ /**
15
+ * Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is 'year'.
16
+ * @default ArrowDropDown
17
+ */
10
18
  SwitchViewIcon: React.ElementType;
11
19
  }
12
20
  export interface PickersCalendarHeaderComponentsPropsOverrides {
@@ -14,18 +14,24 @@ interface ChangeMonthPayload<TDate> {
14
14
  direction: SlideDirection;
15
15
  newMonth: TDate;
16
16
  }
17
+ interface ChangeFocusedDayPayload<TDate> {
18
+ focusedDay: TDate | null;
19
+ /**
20
+ * The update does not trigger month switching animation.
21
+ * For example: when selecting month from the month view.
22
+ */
23
+ withoutMonthSwitchingAnimation?: boolean;
24
+ }
17
25
  export declare const createCalendarStateReducer: <TDate extends unknown>(reduceAnimations: boolean, disableSwitchToMonthOnDayFocus: boolean, utils: MuiPickersAdapter<TDate>) => (state: CalendarState<TDate>, action: {
18
26
  type: "finishMonthSwitchingAnimation";
19
- } | ReducerAction<"changeMonth", ChangeMonthPayload<TDate>> | ReducerAction<"changeFocusedDay", {
20
- focusedDay: TDate | null;
21
- }>) => CalendarState<TDate>;
27
+ } | ReducerAction<"changeMonth", ChangeMonthPayload<TDate>> | ReducerAction<"changeFocusedDay", ChangeFocusedDayPayload<TDate>>) => CalendarState<TDate>;
22
28
  interface CalendarStateInput<TDate> extends Pick<CalendarPickerDefaultizedProps<TDate>, 'date' | 'defaultCalendarMonth' | 'disableFuture' | 'disablePast' | 'minDate' | 'maxDate' | 'onMonthChange' | 'reduceAnimations' | 'shouldDisableDate'> {
23
29
  disableSwitchToMonthOnDayFocus?: boolean;
24
30
  }
25
31
  export declare const useCalendarState: <TDate extends unknown>({ date, defaultCalendarMonth, disableFuture, disablePast, disableSwitchToMonthOnDayFocus, maxDate, minDate, onMonthChange, reduceAnimations, shouldDisableDate, }: CalendarStateInput<TDate>) => {
26
32
  calendarState: CalendarState<TDate>;
27
33
  changeMonth: (newDate: TDate) => void;
28
- changeFocusedDay: (newFocusedDate: TDate | null) => void;
34
+ changeFocusedDay: (newFocusedDate: TDate | null, withoutMonthSwitchingAnimation?: boolean) => void;
29
35
  isDateDisabled: (day: TDate | null) => boolean;
30
36
  onMonthSwitchingAnimationEnd: () => void;
31
37
  handleChangeMonth: (payload: ChangeMonthPayload<TDate>) => void;
@@ -25,7 +25,7 @@ export const createCalendarStateReducer = (reduceAnimations, disableSwitchToMont
25
25
  const needMonthSwitch = action.focusedDay != null && !disableSwitchToMonthOnDayFocus && !utils.isSameMonth(state.currentMonth, action.focusedDay);
26
26
  return _extends({}, state, {
27
27
  focusedDay: action.focusedDay,
28
- isMonthSwitchingAnimating: needMonthSwitch && !reduceAnimations,
28
+ isMonthSwitchingAnimating: needMonthSwitch && !reduceAnimations && !action.withoutMonthSwitchingAnimation,
29
29
  currentMonth: needMonthSwitch ? utils.startOfMonth(action.focusedDay) : state.currentMonth,
30
30
  slideDirection: action.focusedDay != null && utils.isAfterDay(action.focusedDay, state.currentMonth) ? 'left' : 'right'
31
31
  });
@@ -91,11 +91,12 @@ export const useCalendarState = ({
91
91
  type: 'finishMonthSwitchingAnimation'
92
92
  });
93
93
  }, []);
94
- const changeFocusedDay = React.useCallback(newFocusedDate => {
94
+ const changeFocusedDay = React.useCallback((newFocusedDate, withoutMonthSwitchingAnimation) => {
95
95
  if (!isDateDisabled(newFocusedDate)) {
96
96
  dispatch({
97
97
  type: 'changeFocusedDay',
98
- focusedDay: newFocusedDate
98
+ focusedDay: newFocusedDate,
99
+ withoutMonthSwitchingAnimation
99
100
  });
100
101
  }
101
102
  }, [isDateDisabled]);
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { PickersArrowSwitcherSlotsComponent, PickersArrowSwitcherSlotsComponentsProps } from '../internals/components/PickersArrowSwitcher';
2
3
  import { PickerOnChangeFn } from '../internals/hooks/useViews';
3
4
  import { ExportedTimeValidationProps } from '../internals/hooks/validation/useTimeValidation';
4
5
  import { ClockPickerView, MuiPickersAdapter } from '../internals/models';
@@ -33,17 +34,11 @@ export interface ExportedClockPickerProps<TDate> extends ExportedTimeValidationP
33
34
  */
34
35
  getClockLabelText?: (view: ClockPickerView, time: TDate | null, adapter: MuiPickersAdapter<TDate>) => string;
35
36
  }
36
- export interface ClockPickerSlotsComponent {
37
- LeftArrowButton: React.ElementType;
38
- LeftArrowIcon: React.ElementType;
39
- RightArrowButton: React.ElementType;
40
- RightArrowIcon: React.ElementType;
37
+ export interface ClockPickerSlotsComponent extends PickersArrowSwitcherSlotsComponent {
41
38
  }
42
39
  export interface ClockPickerComponentsPropsOverrides {
43
40
  }
44
- export interface ClockPickerSlotsComponentsProps {
45
- leftArrowButton: React.SVGAttributes<SVGSVGElement> & ClockPickerComponentsPropsOverrides;
46
- rightArrowButton: React.SVGAttributes<SVGSVGElement> & ClockPickerComponentsPropsOverrides;
41
+ export interface ClockPickerSlotsComponentsProps extends PickersArrowSwitcherSlotsComponentsProps {
47
42
  }
48
43
  export interface ClockPickerProps<TDate> extends ExportedClockPickerProps<TDate> {
49
44
  className?: string;
@@ -1,9 +1,9 @@
1
1
  import { TextFieldProps } from '@mui/material/TextField';
2
- import { UseFieldProps } from '../internals/hooks/useField';
2
+ import { UseFieldInternalProps } from '../internals/hooks/useField';
3
3
  import { DateValidationError, DateValidationProps } from '../internals/hooks/validation/useDateValidation';
4
4
  import { DefaultizedProps } from '../internals/models/helpers';
5
- export interface UseDateFieldProps<TInputDate, TDate> extends UseFieldProps<TInputDate | null, TDate | null, DateValidationError>, Partial<Omit<DateValidationProps<TInputDate, TDate>, 'value'>> {
5
+ export interface UseDateFieldProps<TInputDate, TDate> extends UseFieldInternalProps<TInputDate | null, TDate | null, DateValidationError>, Partial<Omit<DateValidationProps<TInputDate, TDate>, 'value'>> {
6
6
  }
7
7
  export declare type UseDateFieldDefaultizedProps<TInputDate, TDate> = DefaultizedProps<UseDateFieldProps<TInputDate, TDate>, 'minDate' | 'maxDate' | 'disableFuture' | 'disablePast'>;
8
- export interface DateFieldProps<TInputDate, TDate> extends Omit<TextFieldProps, 'value' | 'defaultValue' | 'onChange' | 'onError'>, UseDateFieldProps<TInputDate, TDate> {
9
- }
8
+ export declare type UseDateFieldComponentProps<TInputDate, TDate, ChildProps extends {}> = Omit<ChildProps, 'value' | 'defaultValue' | 'onChange' | 'onError'> & UseDateFieldProps<TInputDate, TDate>;
9
+ export declare type DateFieldProps<TInputDate, TDate> = UseDateFieldComponentProps<TInputDate, TDate, TextFieldProps>;