@mui/x-date-pickers 8.0.0-alpha.13 → 8.0.0-alpha.14

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 (197) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/DatePicker/shared.d.ts +1 -1
  3. package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  4. package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  5. package/DateTimePicker/DateTimePickerToolbar.js +1 -1
  6. package/DateTimePicker/shared.d.ts +18 -10
  7. package/DateTimePicker/shared.js +23 -2
  8. package/DesktopDateTimePicker/DesktopDateTimePicker.js +2 -11
  9. package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  10. package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  11. package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  12. package/MobileDateTimePicker/MobileDateTimePicker.js +61 -6
  13. package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  14. package/PickersTextField/PickersTextField.js +3 -1
  15. package/StaticDateTimePicker/StaticDateTimePicker.js +60 -6
  16. package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  17. package/TimePicker/shared.d.ts +1 -1
  18. package/esm/DatePicker/shared.d.ts +1 -1
  19. package/esm/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  20. package/esm/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  21. package/esm/DateTimePicker/DateTimePickerToolbar.js +1 -1
  22. package/esm/DateTimePicker/shared.d.ts +18 -10
  23. package/esm/DateTimePicker/shared.js +23 -2
  24. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
  25. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  26. package/esm/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  27. package/esm/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  28. package/esm/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
  29. package/esm/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  30. package/esm/PickersTextField/PickersTextField.js +3 -1
  31. package/esm/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
  32. package/esm/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  33. package/esm/TimePicker/shared.d.ts +1 -1
  34. package/esm/index.js +1 -1
  35. package/esm/internals/components/PickerFieldUI.js +6 -2
  36. package/esm/internals/components/PickerPopper/PickerPopper.js +3 -3
  37. package/esm/internals/components/PickerProvider.d.ts +137 -6
  38. package/esm/internals/components/PickerProvider.js +1 -1
  39. package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  40. package/esm/internals/hooks/useField/useField.js +7 -8
  41. package/esm/internals/hooks/useField/useField.types.d.ts +46 -43
  42. package/esm/internals/hooks/useField/useField.utils.js +4 -1
  43. package/esm/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  44. package/esm/internals/hooks/useField/useFieldState.d.ts +2 -1
  45. package/esm/internals/hooks/useField/useFieldState.js +136 -83
  46. package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -1
  47. package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -1
  48. package/esm/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  49. package/esm/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  50. package/esm/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  51. package/esm/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
  52. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  53. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
  54. package/esm/internals/hooks/usePicker/index.d.ts +1 -3
  55. package/esm/internals/hooks/usePicker/usePicker.d.ts +5 -5
  56. package/esm/internals/hooks/usePicker/usePicker.js +276 -34
  57. package/esm/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  58. package/esm/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  59. package/esm/internals/hooks/useValueWithTimezone.d.ts +1 -1
  60. package/esm/internals/index.d.ts +3 -6
  61. package/esm/internals/models/manager.d.ts +108 -4
  62. package/esm/internals/models/props/basePickerProps.d.ts +2 -2
  63. package/esm/internals/models/props/time.d.ts +1 -1
  64. package/esm/internals/utils/date-time-utils.d.ts +2 -2
  65. package/esm/internals/utils/valueManagers.d.ts +1 -1
  66. package/esm/internals/utils/valueManagers.js +10 -18
  67. package/esm/managers/useDateManager.d.ts +3 -4
  68. package/esm/managers/useDateTimeManager.d.ts +3 -4
  69. package/esm/managers/useTimeManager.d.ts +3 -4
  70. package/esm/models/adapters.d.ts +2 -1
  71. package/esm/models/manager.d.ts +4 -5
  72. package/esm/validation/useValidation.d.ts +1 -1
  73. package/index.js +1 -1
  74. package/internals/components/PickerFieldUI.js +6 -2
  75. package/internals/components/PickerPopper/PickerPopper.js +3 -3
  76. package/internals/components/PickerProvider.d.ts +137 -6
  77. package/internals/components/PickerProvider.js +1 -1
  78. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  79. package/internals/hooks/useField/useField.js +7 -8
  80. package/internals/hooks/useField/useField.types.d.ts +46 -43
  81. package/internals/hooks/useField/useField.utils.js +4 -1
  82. package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  83. package/internals/hooks/useField/useFieldState.d.ts +2 -1
  84. package/internals/hooks/useField/useFieldState.js +135 -82
  85. package/internals/hooks/useField/useFieldV6TextField.js +1 -1
  86. package/internals/hooks/useField/useFieldV7TextField.js +2 -1
  87. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  88. package/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  89. package/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  90. package/internals/hooks/usePicker/hooks/useOrientation.js +42 -0
  91. package/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  92. package/internals/hooks/usePicker/{usePickerValue.js → hooks/useValueAndOpenStates.js} +97 -114
  93. package/internals/hooks/usePicker/index.d.ts +1 -3
  94. package/internals/hooks/usePicker/usePicker.d.ts +5 -5
  95. package/internals/hooks/usePicker/usePicker.js +278 -34
  96. package/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  97. package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  98. package/internals/hooks/useValueWithTimezone.d.ts +1 -1
  99. package/internals/index.d.ts +3 -6
  100. package/internals/models/manager.d.ts +108 -4
  101. package/internals/models/props/basePickerProps.d.ts +2 -2
  102. package/internals/models/props/time.d.ts +1 -1
  103. package/internals/utils/date-time-utils.d.ts +2 -2
  104. package/internals/utils/valueManagers.d.ts +1 -1
  105. package/internals/utils/valueManagers.js +10 -18
  106. package/managers/useDateManager.d.ts +3 -4
  107. package/managers/useDateTimeManager.d.ts +3 -4
  108. package/managers/useTimeManager.d.ts +3 -4
  109. package/models/adapters.d.ts +2 -1
  110. package/models/manager.d.ts +4 -5
  111. package/modern/DatePicker/shared.d.ts +1 -1
  112. package/modern/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  113. package/modern/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  114. package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
  115. package/modern/DateTimePicker/shared.d.ts +18 -10
  116. package/modern/DateTimePicker/shared.js +23 -2
  117. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
  118. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  119. package/modern/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  120. package/modern/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  121. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
  122. package/modern/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  123. package/modern/PickersTextField/PickersTextField.js +3 -1
  124. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
  125. package/modern/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  126. package/modern/TimePicker/shared.d.ts +1 -1
  127. package/modern/index.js +1 -1
  128. package/modern/internals/components/PickerFieldUI.js +6 -2
  129. package/modern/internals/components/PickerPopper/PickerPopper.js +3 -3
  130. package/modern/internals/components/PickerProvider.d.ts +137 -6
  131. package/modern/internals/components/PickerProvider.js +1 -1
  132. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  133. package/modern/internals/hooks/useField/useField.js +7 -8
  134. package/modern/internals/hooks/useField/useField.types.d.ts +46 -43
  135. package/modern/internals/hooks/useField/useField.utils.js +4 -1
  136. package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  137. package/modern/internals/hooks/useField/useFieldState.d.ts +2 -1
  138. package/modern/internals/hooks/useField/useFieldState.js +136 -83
  139. package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
  140. package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
  141. package/modern/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  142. package/modern/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  143. package/modern/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  144. package/modern/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
  145. package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  146. package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
  147. package/modern/internals/hooks/usePicker/index.d.ts +1 -3
  148. package/modern/internals/hooks/usePicker/usePicker.d.ts +5 -5
  149. package/modern/internals/hooks/usePicker/usePicker.js +276 -34
  150. package/modern/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  151. package/modern/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  152. package/modern/internals/hooks/useValueWithTimezone.d.ts +1 -1
  153. package/modern/internals/index.d.ts +3 -6
  154. package/modern/internals/models/manager.d.ts +108 -4
  155. package/modern/internals/models/props/basePickerProps.d.ts +2 -2
  156. package/modern/internals/models/props/time.d.ts +1 -1
  157. package/modern/internals/utils/date-time-utils.d.ts +2 -2
  158. package/modern/internals/utils/valueManagers.d.ts +1 -1
  159. package/modern/internals/utils/valueManagers.js +10 -18
  160. package/modern/managers/useDateManager.d.ts +3 -4
  161. package/modern/managers/useDateTimeManager.d.ts +3 -4
  162. package/modern/managers/useTimeManager.d.ts +3 -4
  163. package/modern/models/adapters.d.ts +2 -1
  164. package/modern/models/manager.d.ts +4 -5
  165. package/modern/validation/useValidation.d.ts +1 -1
  166. package/package.json +1 -1
  167. package/tsconfig.build.tsbuildinfo +1 -1
  168. package/validation/useValidation.d.ts +1 -1
  169. package/esm/internals/hooks/useOpenState.d.ts +0 -14
  170. package/esm/internals/hooks/useOpenState.js +0 -37
  171. package/esm/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  172. package/esm/internals/hooks/usePicker/usePickerProvider.js +0 -125
  173. package/esm/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  174. package/esm/internals/hooks/usePicker/usePickerValue.js +0 -226
  175. package/esm/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  176. package/esm/internals/hooks/usePicker/usePickerValue.types.js +0 -1
  177. package/esm/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  178. package/esm/internals/hooks/usePicker/usePickerViews.js +0 -188
  179. package/internals/hooks/useOpenState.d.ts +0 -14
  180. package/internals/hooks/useOpenState.js +0 -46
  181. package/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  182. package/internals/hooks/usePicker/usePickerProvider.js +0 -135
  183. package/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  184. package/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  185. package/internals/hooks/usePicker/usePickerValue.types.js +0 -5
  186. package/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  187. package/internals/hooks/usePicker/usePickerViews.js +0 -195
  188. package/modern/internals/hooks/useOpenState.d.ts +0 -14
  189. package/modern/internals/hooks/useOpenState.js +0 -37
  190. package/modern/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  191. package/modern/internals/hooks/usePicker/usePickerProvider.js +0 -125
  192. package/modern/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  193. package/modern/internals/hooks/usePicker/usePickerValue.js +0 -226
  194. package/modern/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  195. package/modern/internals/hooks/usePicker/usePickerValue.types.js +0 -1
  196. package/modern/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  197. package/modern/internals/hooks/usePicker/usePickerViews.js +0 -188
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v8.0.0-alpha.13
2
+ * @mui/x-date-pickers v8.0.0-alpha.14
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -168,7 +168,9 @@ function PickerFieldUI(props) {
168
168
  disabled: triggerStatus === 'disabled',
169
169
  onClick: handleClickOpeningButton,
170
170
  'aria-label': openPickerAriaLabel,
171
- edge: clearButtonPosition === 'start' && openPickerButtonPosition === 'start' ? undefined : openPickerButtonPosition
171
+ edge:
172
+ // open button is always rendered at the edge
173
+ textFieldProps.variant !== 'standard' ? openPickerButtonPosition : false
172
174
  },
173
175
  ownerState
174
176
  }),
@@ -190,7 +192,9 @@ function PickerFieldUI(props) {
190
192
  tabIndex: -1,
191
193
  onClick: onClear,
192
194
  disabled: fieldResponse.disabled || fieldResponse.readOnly,
193
- edge: clearButtonPosition === 'end' && openPickerButtonPosition === 'end' ? undefined : clearButtonPosition
195
+ edge:
196
+ // clear button can only be at the edge if it's position differs from the open button
197
+ textFieldProps.variant !== 'standard' && clearButtonPosition !== openPickerButtonPosition ? clearButtonPosition : false
194
198
  },
195
199
  ownerState
196
200
  }),
@@ -227,7 +227,7 @@ function PickerPopper(inProps) {
227
227
  } = (0, _hooks.usePickerContext)();
228
228
  const {
229
229
  dismissViews,
230
- doesTheCurrentViewHasAnUI,
230
+ getCurrentViewMode,
231
231
  viewContainerRole
232
232
  } = (0, _usePickerPrivateContext.usePickerPrivateContext)();
233
233
  React.useEffect(() => {
@@ -243,7 +243,7 @@ function PickerPopper(inProps) {
243
243
  }, [dismissViews, open]);
244
244
  const lastFocusedElementRef = React.useRef(null);
245
245
  React.useEffect(() => {
246
- if (viewContainerRole === 'tooltip' || !doesTheCurrentViewHasAnUI()) {
246
+ if (viewContainerRole === 'tooltip' || getCurrentViewMode() === 'field') {
247
247
  return;
248
248
  }
249
249
  if (open) {
@@ -257,7 +257,7 @@ function PickerPopper(inProps) {
257
257
  }
258
258
  });
259
259
  }
260
- }, [open, viewContainerRole, doesTheCurrentViewHasAnUI]);
260
+ }, [open, viewContainerRole, getCurrentViewMode]);
261
261
  const classes = useUtilityClasses(classesProp);
262
262
  const {
263
263
  ownerState: pickerOwnerState,
@@ -1,12 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { SxProps } from '@mui/system';
3
3
  import { Theme } from '@mui/material/styles';
4
- import { PickerOwnerState } from "../../models/index.js";
4
+ import { PickerChangeImportance, PickerOwnerState, PickersTimezone } from "../../models/index.js";
5
5
  import { PickersInputLocaleText } from "../../locales/index.js";
6
6
  import { DateOrTimeViewWithMeridiem, PickerOrientation, PickerValidValue, PickerVariant } from "../models/index.js";
7
- import type { UsePickerValueActionsContextValue, UsePickerValueContextValue, UsePickerValuePrivateContextValue } from '../hooks/usePicker/usePickerValue.types';
8
- import { UsePickerViewsActionsContextValue, UsePickerViewsContextValue, UsePickerViewsPrivateContextValue } from "../hooks/usePicker/usePickerViews.js";
9
7
  import { PickerFieldPrivateContextValue } from "../hooks/useNullableFieldPrivateContext.js";
8
+ import type { PickersShortcutsItemContext } from '../../PickersShortcuts';
10
9
  export declare const PickerActionsContext: React.Context<PickerActionsContextValue<any, any, any> | null>;
11
10
  export declare const PickerPrivateContext: React.Context<PickerPrivateContextValue>;
12
11
  /**
@@ -26,7 +25,24 @@ export interface PickerProviderProps<TValue extends PickerValidValue> {
26
25
  localeText: PickersInputLocaleText | undefined;
27
26
  children: React.ReactNode;
28
27
  }
29
- export interface PickerContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends UsePickerValueContextValue<TValue, TError>, UsePickerViewsContextValue<TView> {
28
+ export interface PickerContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError> extends PickerActionsContextValue<TValue, TView, TError> {
29
+ /**
30
+ * The current value of the picker.
31
+ */
32
+ value: TValue;
33
+ /**
34
+ * The timezone to use when rendering the dates.
35
+ * If a `timezone` prop is provided, it will be used.
36
+ * If the `value` prop contains a valid date, its timezone will be used.
37
+ * If no `value` prop is provided, but the `defaultValue` contains a valid date, its timezone will be used.
38
+ * If no `value` or `defaultValue` is provided, but the `referenceDate` is provided, its timezone will be used.
39
+ * Otherwise, the timezone will be the default one of your date library.
40
+ */
41
+ timezone: PickersTimezone;
42
+ /**
43
+ * Whether the picker is open.
44
+ */
45
+ open: boolean;
30
46
  /**
31
47
  * Whether the picker is disabled.
32
48
  */
@@ -41,6 +57,25 @@ export interface PickerContextValue<TValue extends PickerValidValue, TView exten
41
57
  * If the picker does not have a field (if it is a static picker) or is not open, the view should be focused.
42
58
  */
43
59
  autoFocus: boolean;
60
+ /**
61
+ * The views that the picker has to render.
62
+ * It is equal to the picker `views` prop—if defined.
63
+ * Otherwise, a default set of views is provided based on the component you are using:
64
+ * - Date Pickers: ['year', 'day']
65
+ * - Time Pickers: ['hours', 'minutes']
66
+ * - Date Time Pickers: ['year', 'day', 'hours', 'minutes']
67
+ * - Date Range Pickers: ['day']
68
+ * - Date Time Range Pickers: ['day', 'hours', 'minutes']
69
+ */
70
+ views: readonly TView[];
71
+ /**
72
+ * The currently rendered view.
73
+ */
74
+ view: TView | null;
75
+ /**
76
+ * The view showed when first opening the picker.
77
+ */
78
+ initialView: TView | null;
44
79
  /**
45
80
  * The responsive variant of the picker.
46
81
  * It is equal to "desktop" when using a desktop picker (like <DesktopDatePicker />).
@@ -122,8 +157,85 @@ export interface PickerContextValue<TValue extends PickerValidValue, TView exten
122
157
  */
123
158
  rootRef: React.ForwardedRef<HTMLDivElement> | undefined;
124
159
  }
125
- export interface PickerActionsContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError = string | null> extends UsePickerValueActionsContextValue<TValue, TError>, UsePickerViewsActionsContextValue<TView> {}
126
- export interface PickerPrivateContextValue extends UsePickerValuePrivateContextValue, UsePickerViewsPrivateContextValue {
160
+ export interface PickerActionsContextValue<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TError = string | null> {
161
+ /**
162
+ * Set the current value of the picker.
163
+ * @param {TValue} value The new value of the picker.
164
+ * @param {SetValueActionOptions<TError>} options The options to customize the behavior of this update.
165
+ */
166
+ setValue: (value: TValue, options?: SetValueActionOptions<TError>) => void;
167
+ /**
168
+ * Set the current open state of the Picker.
169
+ * It can be a function that will receive the current open state as parameter.
170
+ * ```ts
171
+ * setOpen(true); // Opens the picker.
172
+ * setOpen(false); // Closes the picker.
173
+ * setOpen((prevOpen) => !prevOpen); // Toggles the open state.
174
+ * ```
175
+ * @param {React.SetStateAction<boolean>} action The new open state of the Picker.
176
+ */
177
+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;
178
+ /**
179
+ * Set the current view.
180
+ * @template TView
181
+ * @param {TView} view The view to render
182
+ */
183
+ setView: (view: TView) => void;
184
+ /**
185
+ * Set the current value of the picker to be empty.
186
+ * The value will be `null` on single pickers and `[null, null]` on range pickers.
187
+ */
188
+ clearValue: () => void;
189
+ /**
190
+ * Set the current value of the picker to be the current date.
191
+ * The value will be `today` on single pickers and `[today, today]` on range pickers.
192
+ * With `today` being the current date, with its time set to `00:00:00` on Date Pickers and its time set to the current time on Time and Date Pickers.
193
+ */
194
+ setValueToToday: () => void;
195
+ /**
196
+ * Accept the current value of the picker.
197
+ * Will call `onAccept` if defined.
198
+ * If the picker is re-opened, this value will be the one used to initialize the views.
199
+ */
200
+ acceptValueChanges: () => void;
201
+ /**
202
+ * Cancel the changes made to the current value of the picker.
203
+ * The value will be reset to the last accepted value.
204
+ */
205
+ cancelValueChanges: () => void;
206
+ }
207
+ export interface SetValueActionOptions<TError = string | null> {
208
+ /**
209
+ * The importance of the change when picking a value:
210
+ * - "accept": fires `onChange`, fires `onAccept` and closes the picker.
211
+ * - "set": fires `onChange` but do not fire `onAccept` and does not close the picker.
212
+ * @default "accept"
213
+ */
214
+ changeImportance?: PickerChangeImportance;
215
+ /**
216
+ * The validation error associated to the current value.
217
+ * If not defined, the validation will be computed by the picker.
218
+ */
219
+ validationError?: TError;
220
+ /**
221
+ * The shortcut that triggered this change.
222
+ * It should not be defined if the change does not come from a shortcut.
223
+ */
224
+ shortcut?: PickersShortcutsItemContext;
225
+ /**
226
+ * Whether the value should call `onChange` and `onAccept` when the value is not controlled and has never been modified.
227
+ * If `true`, the `onChange` and `onAccept` callback will only be fired if the value has been modified (and is not equal to the last published value).
228
+ * If `false`, the `onChange` and `onAccept` callback will be fired when the value has never been modified (`onAccept` only if `changeImportance` is set to "accept").
229
+ * @default false
230
+ */
231
+ skipPublicationIfPristine?: boolean;
232
+ /**
233
+ * Whether the picker should close.
234
+ * @default changeImportance === "accept"
235
+ */
236
+ shouldClose?: boolean;
237
+ }
238
+ export interface PickerPrivateContextValue {
127
239
  /**
128
240
  * The ownerState of the picker.
129
241
  */
@@ -137,4 +249,23 @@ export interface PickerPrivateContextValue extends UsePickerValuePrivateContextV
137
249
  * The id of the label element.
138
250
  */
139
251
  labelId: string | undefined;
252
+ dismissViews: () => void;
253
+ /**
254
+ * Whether at least one view has an UI (it has a view renderer associated).
255
+ */
256
+ hasUIView: boolean;
257
+ /**
258
+ * Return the mode of the current view.
259
+ * @returns {boolean} The mode of the current view.
260
+ */
261
+ getCurrentViewMode: () => 'UI' | 'field';
262
+ /**
263
+ * The aria role associated with the view container.
264
+ * It is equal to "dialog" when the view is rendered inside a `@mui/material/Dialog`.
265
+ * It is equal to "dialog" when the view is rendered inside a `@mui/material/Popper` and the focus is trapped inside the view.
266
+ * It is equal to "tooltip" when the view is rendered inside a `@mui/material/Popper` and the focus remains inside the field.
267
+ * It is always equal to null if the picker does not have a field (static pickers).
268
+ * It is always equal to null if the component you are accessing the context from is not wrapped by a picker.
269
+ */
270
+ viewContainerRole: 'dialog' | 'tooltip' | null;
140
271
  }
@@ -24,7 +24,7 @@ const PickerPrivateContext = exports.PickerPrivateContext = /*#__PURE__*/React.c
24
24
  },
25
25
  dismissViews: () => {},
26
26
  hasUIView: true,
27
- doesTheCurrentViewHasAnUI: () => true,
27
+ getCurrentViewMode: () => 'UI',
28
28
  rootRefObject: {
29
29
  current: null
30
30
  },
@@ -2,14 +2,11 @@ import * as React from 'react';
2
2
  import { MakeRequired, SlotComponentPropsFromProps } from '@mui/x-internals/types';
3
3
  import { BasePickerProps } from "../../models/props/basePickerProps.js";
4
4
  import { PickerPopperSlots, PickerPopperSlotProps } from "../../components/PickerPopper/PickerPopper.js";
5
- import { UsePickerParams } from "../usePicker/index.js";
5
+ import { UsePickerParameters, UsePickerNonStaticProps, UsePickerProps } from "../usePicker/index.js";
6
6
  import { PickerFieldSlotProps, PickerOwnerState } from "../../../models/index.js";
7
7
  import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from "../../../PickersLayout/PickersLayout.types.js";
8
- import { UsePickerValueNonStaticProps } from "../usePicker/usePickerValue.types.js";
9
- import { UsePickerViewsProps } from "../usePicker/usePickerViews.js";
10
8
  import { DateOrTimeViewWithMeridiem, PickerValue } from "../../models/index.js";
11
9
  import { PickerFieldUISlotsFromContext, PickerFieldUISlotPropsFromContext } from "../../components/PickerFieldUI.js";
12
- import { UsePickerProviderNonStaticProps } from "../usePicker/usePickerProvider.js";
13
10
  export interface UseDesktopPickerSlots extends Pick<PickerPopperSlots, 'desktopPaper' | 'desktopTransition' | 'desktopTrapFocus' | 'popper'>, ExportedPickersLayoutSlots<PickerValue>, PickerFieldUISlotsFromContext {
14
11
  /**
15
12
  * Component used to enter the date with the keyboard.
@@ -20,14 +17,14 @@ export interface ExportedUseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStru
20
17
  field?: SlotComponentPropsFromProps<PickerFieldSlotProps<PickerValue, TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
21
18
  }
22
19
  export interface UseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue>, 'toolbar'> {}
23
- export interface DesktopOnlyPickerProps extends UsePickerValueNonStaticProps, UsePickerProviderNonStaticProps {
20
+ export interface DesktopOnlyPickerProps extends UsePickerNonStaticProps {
24
21
  /**
25
22
  * If `true`, the `input` element is focused during the first mount.
26
23
  * @default false
27
24
  */
28
25
  autoFocus?: boolean;
29
26
  }
30
- export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerViewsProps<PickerValue, TView, any>> extends BasePickerProps<PickerValue, any, TError, TExternalProps>, MakeRequired<DesktopOnlyPickerProps, 'format'> {
27
+ export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerProps<PickerValue, TView, TError, any>> extends BasePickerProps<PickerValue, any, TError, TExternalProps>, MakeRequired<DesktopOnlyPickerProps, 'format'> {
31
28
  /**
32
29
  * Overridable component slots.
33
30
  * @default {}
@@ -39,6 +36,6 @@ export interface UseDesktopPickerProps<TView extends DateOrTimeViewWithMeridiem,
39
36
  */
40
37
  slotProps?: UseDesktopPickerSlotProps<TEnableAccessibleFieldDOMStructure>;
41
38
  }
42
- export interface UseDesktopPickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseDesktopPickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParams<PickerValue, TView, TExternalProps>, 'valueManager' | 'valueType' | 'validator' | 'rendererInterceptor' | 'ref'> {
39
+ export interface UseDesktopPickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseDesktopPickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParameters<PickerValue, TView, TExternalProps>, 'valueManager' | 'valueType' | 'validator' | 'rendererInterceptor' | 'ref'> {
43
40
  props: TExternalProps;
44
41
  }
@@ -37,7 +37,6 @@ const useField = params => {
37
37
  onClear
38
38
  },
39
39
  fieldValueManager,
40
- valueManager,
41
40
  validator,
42
41
  getOpenPickerButtonAriaLabel: getOpenDialogAriaText
43
42
  } = params;
@@ -45,6 +44,7 @@ const useField = params => {
45
44
  const stateResponse = (0, _useFieldState.useFieldState)(params);
46
45
  const {
47
46
  state,
47
+ value,
48
48
  activeSectionIndex,
49
49
  parsedSelectedSections,
50
50
  setSelectedSections,
@@ -67,7 +67,7 @@ const useField = params => {
67
67
  const {
68
68
  resetCharacterQuery
69
69
  } = characterEditingResponse;
70
- const areAllSectionsEmpty = valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue);
70
+ const areAllSectionsEmpty = React.useMemo(() => state.sections.every(section => section.value === ''), [state.sections]);
71
71
  const useFieldTextField = enableAccessibleFieldDOMStructure ? _useFieldV7TextField.useFieldV7TextField : _useFieldV6TextField.useFieldV6TextField;
72
72
  const sectionOrder = React.useMemo(() => (0, _useField.getSectionOrder)(state.sections, isRtl && !enableAccessibleFieldDOMStructure), [state.sections, isRtl, enableAccessibleFieldDOMStructure]);
73
73
  const {
@@ -157,12 +157,11 @@ const useField = params => {
157
157
  setSelectedSections(activeSectionIndex);
158
158
  }
159
159
  const activeSection = state.sections[activeSectionIndex];
160
- const activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);
161
- const newSectionValue = (0, _useField.adjustSectionValue)(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, activeDateManager.date, {
160
+ const newSectionValue = (0, _useField.adjustSectionValue)(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, fieldValueManager.getDateFromSection(value, activeSection), {
162
161
  minutesStep
163
162
  });
164
163
  updateSectionValue({
165
- activeSection,
164
+ section: activeSection,
166
165
  newSectionValue,
167
166
  shouldGoToNextSection: false
168
167
  });
@@ -179,7 +178,7 @@ const useField = params => {
179
178
  props: internalProps,
180
179
  validator,
181
180
  timezone,
182
- value: state.value,
181
+ value,
183
182
  onError: internalProps.onError
184
183
  });
185
184
  const inputError = React.useMemo(() => {
@@ -233,8 +232,8 @@ const useField = params => {
233
232
  };
234
233
  const localizationContext = (0, _useUtils.useLocalizationContext)();
235
234
  const openPickerAriaLabel = React.useMemo(() => getOpenDialogAriaText((0, _extends2.default)({}, localizationContext, {
236
- value: state.value
237
- })), [getOpenDialogAriaText, state.value, localizationContext]);
235
+ value
236
+ })), [getOpenDialogAriaText, value, localizationContext]);
238
237
  const commonAdditionalProps = {
239
238
  disabled,
240
239
  readOnly,
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { FieldSectionType, FieldSection, FieldSelectedSections, MuiPickersAdapter, TimezoneProps, FieldSectionContentType, PickerValidDate, FieldRef, OnErrorProps, InferError, InferFieldSection, PickerValueType } from "../../../models/index.js";
3
- import type { PickerValueManager } from '../usePicker';
3
+ import type { PickerValueManager } from '../../models';
4
4
  import type { Validator } from '../../../validation';
5
5
  import type { UseFieldStateResponse } from './useFieldState';
6
6
  import type { UseFieldCharacterEditingResponse } from './useFieldCharacterEditing';
@@ -165,47 +165,17 @@ export type FieldChangeHandler<TValue extends PickerValidValue, TError> = (value
165
165
  export interface FieldChangeHandlerContext<TError> {
166
166
  validationError: TError;
167
167
  }
168
- /**
169
- * Object used to access and update the active date (i.e: the date containing the active section).
170
- * Mainly useful in the range fields where we need to update the date containing the active section without impacting the other one.
171
- */
172
- interface FieldActiveDateManager<TValue extends PickerValidValue> {
173
- /**
174
- * Active date from `state.value`.
175
- */
176
- date: PickerValidDate | null;
177
- /**
178
- * Active date from the `state.referenceValue`.
179
- */
180
- referenceDate: PickerValidDate;
181
- /**
182
- * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
183
- * @param {InferFieldSection<TValue>[]} sections The sections of the full value.
184
- * @returns {InferFieldSection<TValue>[]} The sections of the active date.
185
- * Get the sections of the active date.
186
- */
187
- getSections: (sections: InferFieldSection<TValue>[]) => InferFieldSection<TValue>[];
188
- /**
189
- * Creates the new value and reference value based on the new active date and the current state.
190
- * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
191
- * @param {PickerValidDate | null} newActiveDate The new value of the date containing the active section.
192
- * @returns {Pick<UseFieldState<TValue>, 'value' | 'referenceValue'>} The new value and reference value to publish and store in the state.
193
- */
194
- getNewValuesFromNewActiveDate: (newActiveDate: PickerValidDate | null) => Pick<UseFieldState<TValue>, 'value' | 'referenceValue'>;
195
- }
196
168
  export type FieldParsedSelectedSections = number | 'all' | null;
197
169
  export interface FieldValueManager<TValue extends PickerValidValue> {
198
170
  /**
199
171
  * Creates the section list from the current value.
200
172
  * The `prevSections` are used on the range fields to avoid losing the sections of a partially filled date when editing the other date.
201
173
  * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
202
- * @param {MuiPickersAdapter} utils The utils to manipulate the date.
203
174
  * @param {TValue} value The current value to generate sections from.
204
- * @param {InferFieldSection<TValue>[] | null} fallbackSections The sections to use as a fallback if a date is null or invalid.
205
- * @param {(date: PickerValidDate) => FieldSection[]} getSectionsFromDate Returns the sections of the given date.
175
+ * @param {(date: PickerValidDate | null) => FieldSection[]} getSectionsFromDate Returns the sections of the given date.
206
176
  * @returns {InferFieldSection<TValue>[]} The new section list.
207
177
  */
208
- getSectionsFromValue: (utils: MuiPickersAdapter, value: TValue, fallbackSections: InferFieldSection<TValue>[] | null, getSectionsFromDate: (date: PickerValidDate) => FieldSection[]) => InferFieldSection<TValue>[];
178
+ getSectionsFromValue: (value: TValue, getSectionsFromDate: (date: PickerValidDate | null) => FieldSection[]) => InferFieldSection<TValue>[];
209
179
  /**
210
180
  * Creates the string value to render in the input based on the current section list.
211
181
  * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
@@ -222,15 +192,6 @@ export interface FieldValueManager<TValue extends PickerValidValue> {
222
192
  * @returns {string} The string value to render in the input.
223
193
  */
224
194
  getV7HiddenInputValueFromSections: (sections: InferFieldSection<TValue>[]) => string;
225
- /**
226
- * Returns the manager of the active date.
227
- * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
228
- * @param {MuiPickersAdapter} utils The utils to manipulate the date.
229
- * @param {UseFieldState<TValue>} state The current state of the field.
230
- * @param {InferFieldSection<TValue>} activeSection The active section.
231
- * @returns {FieldActiveDateManager<TValue>} The manager of the active date.
232
- */
233
- getActiveDateManager: (utils: MuiPickersAdapter, state: UseFieldState<TValue>, activeSection: InferFieldSection<TValue>) => FieldActiveDateManager<TValue>;
234
195
  /**
235
196
  * Parses a string version (most of the time coming from the input).
236
197
  * This method should only be used when the change does not come from a single section.
@@ -251,9 +212,51 @@ export interface FieldValueManager<TValue extends PickerValidValue> {
251
212
  * @returns {TValue} The new reference value with no invalid date.
252
213
  */
253
214
  updateReferenceValue: (utils: MuiPickersAdapter, value: TValue, prevReferenceValue: InferNonNullablePickerValue<TValue>) => InferNonNullablePickerValue<TValue>;
215
+ /**
216
+ * Extract from the given value the date that contains the given section.
217
+ * @param {TValue} value The value to extract the date from.
218
+ * @param {InferFieldSection<TValue>} section The section to get the date from.
219
+ * @returns {PickerValidDate | null} The date that contains the section.
220
+ */
221
+ getDateFromSection: (value: TValue, section: InferFieldSection<TValue>) => PickerValidDate | null;
222
+ /**
223
+ * Get the sections of the date that contains the given section.
224
+ * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
225
+ * @param {InferFieldSection<TValue>[]} sections The sections of the full value.
226
+ * @param {InferFieldSection<TValue>} section A section of the date from which we want to get all the sections.
227
+ * @returns {InferFieldSection<TValue>[]} The sections of the date that contains the section.
228
+ */
229
+ getDateSectionsFromValue: (sections: InferFieldSection<TValue>[], section: InferFieldSection<TValue>) => InferFieldSection<TValue>[];
230
+ /**
231
+ * Creates a new value based on the provided date and the current value.
232
+ * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
233
+ * @param {TValue} value The value to update the date in.
234
+ * @param {InferFieldSection<TValue>} section A section of the date we want to update in the value.
235
+ * @param {PickerValidDate | null} date The date that contains the section.
236
+ * @returns {TValue} The updated value.
237
+ */
238
+ updateDateInValue: (value: TValue, section: InferFieldSection<TValue>, date: PickerValidDate | null) => TValue;
239
+ /**
240
+ * @template TValue The value type. It will be the same type as `value` or `null`. It can be in `[start, end]` format in case of range value.
241
+ * @param {InferFieldSection<TValue>[]} sections The sections of the full value.
242
+ * @param {InferFieldSection<TValue>} section A section of the date from which we want to clear all the sections.
243
+ * @returns {InferFieldSection<TValue>[]} The sections of the full value with all the sections of the target date cleared.
244
+ */
245
+ clearDateSections: (sections: InferFieldSection<TValue>[], section: InferFieldSection<TValue>) => InferFieldSection<TValue>[];
254
246
  }
255
247
  export interface UseFieldState<TValue extends PickerValidValue> {
256
- value: TValue;
248
+ /**
249
+ * Last value returned by `useControlledValueWithTimezone`.
250
+ */
251
+ lastValue: TValue | undefined;
252
+ /**
253
+ * Last value of the parameters used to generate the sections.
254
+ */
255
+ lastSectionsDependencies: {
256
+ format: string;
257
+ isRtl: boolean;
258
+ locale: any;
259
+ };
257
260
  /**
258
261
  * Non-nullable value used to keep trace of the timezone and the date parts not present in the format.
259
262
  * It is updated whenever we have a valid date (for the range picker we update only the portion of the range that is valid).
@@ -471,8 +471,11 @@ const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTran
471
471
  }
472
472
  case 'weekDay':
473
473
  {
474
+ let dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
475
+ if (section.hasLeadingZerosInInput) {
476
+ dayInWeekStrOfActiveDate = cleanLeadingZeros(dayInWeekStrOfActiveDate, section.maxLength);
477
+ }
474
478
  const formattedDaysInWeek = getDaysInWeekStr(utils, section.format);
475
- const dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
476
479
  const dayInWeekOfActiveDate = formattedDaysInWeek.indexOf(dayInWeekStrOfActiveDate);
477
480
  const dayInWeekOfNewSectionValue = formattedDaysInWeek.indexOf(section.value);
478
481
  const diff = dayInWeekOfNewSectionValue - dayInWeekOfActiveDate;
@@ -243,7 +243,7 @@ const useFieldCharacterEditing = ({
243
243
  return applyQuery(params, getFirstSectionValueMatchingWithQuery, queryValue => (0, _useField.isStringNumber)(queryValue, localizedDigits));
244
244
  };
245
245
  const applyCharacterEditing = (0, _useEventCallback.default)(params => {
246
- const activeSection = sections[params.sectionIndex];
246
+ const section = sections[params.sectionIndex];
247
247
  const isNumericEditing = (0, _useField.isStringNumber)(params.keyPressed, localizedDigits);
248
248
  const response = isNumericEditing ? applyNumericEditing((0, _extends2.default)({}, params, {
249
249
  keyPressed: (0, _useField.applyLocalizedDigits)(params.keyPressed, localizedDigits)
@@ -253,7 +253,7 @@ const useFieldCharacterEditing = ({
253
253
  return;
254
254
  }
255
255
  updateSectionValue({
256
- activeSection,
256
+ section,
257
257
  newSectionValue: response.sectionValue,
258
258
  shouldGoToNextSection: response.shouldGoToNextSection
259
259
  });
@@ -5,7 +5,7 @@ export interface UpdateSectionValueParams<TValue extends PickerValidValue> {
5
5
  /**
6
6
  * The section on which we want to apply the new value.
7
7
  */
8
- activeSection: InferFieldSection<TValue>;
8
+ section: InferFieldSection<TValue>;
9
9
  /**
10
10
  * Value to apply to the active section.
11
11
  */
@@ -17,6 +17,7 @@ export interface UpdateSectionValueParams<TValue extends PickerValidValue> {
17
17
  }
18
18
  export interface UseFieldStateResponse<TValue extends PickerValidValue> {
19
19
  state: UseFieldState<TValue>;
20
+ value: TValue;
20
21
  activeSectionIndex: number | null;
21
22
  parsedSelectedSections: FieldParsedSelectedSections;
22
23
  setSelectedSections: (sections: FieldSelectedSections) => void;