@mui/x-date-pickers 8.17.0 → 8.19.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 (52) hide show
  1. package/CHANGELOG.md +213 -0
  2. package/DatePicker/DatePicker.js +8 -2
  3. package/DateTimePicker/DateTimePicker.js +8 -2
  4. package/DateTimePicker/DateTimePickerToolbar.js +2 -1
  5. package/DesktopDatePicker/DesktopDatePicker.js +8 -2
  6. package/DesktopDateTimePicker/DesktopDateTimePicker.js +8 -2
  7. package/DesktopTimePicker/DesktopTimePicker.js +8 -2
  8. package/MobileDatePicker/MobileDatePicker.js +8 -2
  9. package/MobileDateTimePicker/MobileDateTimePicker.js +8 -2
  10. package/MobileTimePicker/MobileTimePicker.js +8 -2
  11. package/PickersShortcuts/PickersShortcuts.js +2 -1
  12. package/StaticDatePicker/StaticDatePicker.js +8 -2
  13. package/StaticDateTimePicker/StaticDateTimePicker.js +8 -2
  14. package/StaticTimePicker/StaticTimePicker.js +8 -2
  15. package/TimePicker/TimePicker.js +8 -2
  16. package/TimePicker/TimePickerToolbar.js +2 -1
  17. package/esm/DatePicker/DatePicker.js +8 -2
  18. package/esm/DateTimePicker/DateTimePicker.js +8 -2
  19. package/esm/DateTimePicker/DateTimePickerToolbar.js +2 -1
  20. package/esm/DesktopDatePicker/DesktopDatePicker.js +8 -2
  21. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +8 -2
  22. package/esm/DesktopTimePicker/DesktopTimePicker.js +8 -2
  23. package/esm/MobileDatePicker/MobileDatePicker.js +8 -2
  24. package/esm/MobileDateTimePicker/MobileDateTimePicker.js +8 -2
  25. package/esm/MobileTimePicker/MobileTimePicker.js +8 -2
  26. package/esm/PickersShortcuts/PickersShortcuts.js +2 -1
  27. package/esm/StaticDatePicker/StaticDatePicker.js +8 -2
  28. package/esm/StaticDateTimePicker/StaticDateTimePicker.js +8 -2
  29. package/esm/StaticTimePicker/StaticTimePicker.js +8 -2
  30. package/esm/TimePicker/TimePicker.js +8 -2
  31. package/esm/TimePicker/TimePickerToolbar.js +2 -1
  32. package/esm/index.js +1 -1
  33. package/esm/internals/components/PickerProvider.d.ts +8 -0
  34. package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -2
  35. package/esm/internals/hooks/useField/useFieldState.js +19 -10
  36. package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -0
  37. package/esm/internals/hooks/useMobilePicker/useMobilePicker.js +2 -2
  38. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +14 -2
  39. package/esm/internals/hooks/usePicker/usePicker.js +13 -5
  40. package/esm/internals/hooks/usePicker/usePicker.types.d.ts +8 -2
  41. package/esm/models/pickers.d.ts +8 -0
  42. package/index.js +1 -1
  43. package/internals/components/PickerProvider.d.ts +8 -0
  44. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -2
  45. package/internals/hooks/useField/useFieldState.js +19 -10
  46. package/internals/hooks/useField/useFieldV6TextField.js +1 -0
  47. package/internals/hooks/useMobilePicker/useMobilePicker.js +2 -2
  48. package/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +14 -2
  49. package/internals/hooks/usePicker/usePicker.js +13 -5
  50. package/internals/hooks/usePicker/usePicker.types.d.ts +8 -2
  51. package/models/pickers.d.ts +8 -0
  52. package/package.json +3 -3
@@ -112,6 +112,7 @@ function useValueAndOpenStates(parameters) {
112
112
  skipPublicationIfPristine = false,
113
113
  validationError,
114
114
  shortcut,
115
+ source,
115
116
  shouldClose = changeImportance === 'accept'
116
117
  } = options ?? {};
117
118
  let shouldFireOnChange;
@@ -134,8 +135,18 @@ function useValueAndOpenStates(parameters) {
134
135
  let cachedContext = null;
135
136
  const getContext = () => {
136
137
  if (!cachedContext) {
138
+ let inferredSource;
139
+ if (source) {
140
+ inferredSource = source;
141
+ } else if (shortcut) {
142
+ inferredSource = 'view';
143
+ } else {
144
+ // Default to unknown when not explicitly tagged by a picker call site
145
+ inferredSource = 'unknown';
146
+ }
137
147
  cachedContext = {
138
- validationError: validationError == null ? getValidationErrorForNewValue(newValue) : validationError
148
+ validationError: validationError == null ? getValidationErrorForNewValue(newValue) : validationError,
149
+ source: inferredSource
139
150
  };
140
151
  if (shortcut) {
141
152
  cachedContext.shortcut = shortcut;
@@ -172,7 +183,8 @@ function useValueAndOpenStates(parameters) {
172
183
  return;
173
184
  }
174
185
  setValue(newValue, {
175
- changeImportance: selectionState === 'finish' && closeOnSelect ? 'accept' : 'set'
186
+ changeImportance: selectionState === 'finish' && closeOnSelect ? 'accept' : 'set',
187
+ source: 'view'
176
188
  });
177
189
  });
178
190
 
@@ -118,15 +118,23 @@ const usePicker = ({
118
118
  autoFocus: autoFocusView,
119
119
  getStepNavigation
120
120
  });
121
- const clearValue = (0, _useEventCallback.default)(() => setValue(valueManager.emptyValue));
122
- const setValueToToday = (0, _useEventCallback.default)(() => setValue(valueManager.getTodayValue(adapter, timezone, valueType)));
123
- const acceptValueChanges = (0, _useEventCallback.default)(() => setValue(value));
121
+ const clearValue = (0, _useEventCallback.default)(() => setValue(valueManager.emptyValue, {
122
+ source: 'view'
123
+ }));
124
+ const setValueToToday = (0, _useEventCallback.default)(() => setValue(valueManager.getTodayValue(adapter, timezone, valueType), {
125
+ source: 'view'
126
+ }));
127
+ const acceptValueChanges = (0, _useEventCallback.default)(() => setValue(value, {
128
+ source: 'view'
129
+ }));
124
130
  const cancelValueChanges = (0, _useEventCallback.default)(() => setValue(state.lastCommittedValue, {
125
- skipPublicationIfPristine: true
131
+ skipPublicationIfPristine: true,
132
+ source: 'view'
126
133
  }));
127
134
  const dismissViews = (0, _useEventCallback.default)(() => {
128
135
  setValue(value, {
129
- skipPublicationIfPristine: true
136
+ skipPublicationIfPristine: true,
137
+ source: 'view'
130
138
  });
131
139
  });
132
140
  const {
@@ -28,7 +28,10 @@ export interface UsePickerBaseProps<TValue extends PickerValidValue, TView exten
28
28
  * @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.
29
29
  * @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
30
30
  * @param {TValue} value The new value.
31
- * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
31
+ * @param {FieldChangeHandlerContext<TError>} context Context about this change:
32
+ * - `validationError`: validation result of the current value
33
+ * - `source`: source of the change. One of 'field' | 'view' | 'unknown'
34
+ * - `shortcut` (optional): the shortcut metadata if the change was triggered by a shortcut selection
32
35
  */
33
36
  onChange?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
34
37
  /**
@@ -36,7 +39,10 @@ export interface UsePickerBaseProps<TValue extends PickerValidValue, TView exten
36
39
  * @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.
37
40
  * @template TError The validation error type. It will be either `string` or a `null`. It can be in `[start, end]` format in case of range value.
38
41
  * @param {TValue} value The value that was just accepted.
39
- * @param {FieldChangeHandlerContext<TError>} context The context containing the validation result of the current value.
42
+ * @param {FieldChangeHandlerContext<TError>} context Context about this acceptance:
43
+ * - `validationError`: validation result of the current value
44
+ * - `source`: source of the acceptance. One of 'field' | 'picker' | 'unknown'
45
+ * - `shortcut` (optional): the shortcut metadata if the value was accepted via a shortcut selection
40
46
  */
41
47
  onAccept?: (value: TValue, context: PickerChangeHandlerContext<TError>) => void;
42
48
  /**
@@ -2,6 +2,14 @@ import { PickerOrientation, PickerVariant } from "../internals/models/common.js"
2
2
  import type { PickersShortcutsItemContext } from "../PickersShortcuts/index.js";
3
3
  export interface PickerChangeHandlerContext<TError> {
4
4
  validationError: TError;
5
+ /**
6
+ * Source of the change that triggered `onChange` or `onAccept`.
7
+ * Simplified to one of the following values:
8
+ * - 'field' (changes coming from the text field)
9
+ * - 'view' (any interaction inside the picker UI: views, toolbar, action bar, shortcuts, etc.)
10
+ * - 'unknown' (unspecified or third-party triggers)
11
+ */
12
+ source: 'field' | 'view' | 'unknown';
5
13
  /**
6
14
  * Shortcut causing this `onChange` or `onAccept` call.
7
15
  * If the call has not been caused by a shortcut selection, this property will be `undefined`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-date-pickers",
3
- "version": "8.17.0",
3
+ "version": "8.19.0",
4
4
  "author": "MUI Team",
5
5
  "description": "The community edition of the MUI X Date and Time Picker components.",
6
6
  "license": "MIT",
@@ -34,12 +34,12 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@babel/runtime": "^7.28.4",
37
- "@mui/utils": "^7.3.3",
37
+ "@mui/utils": "^7.3.5",
38
38
  "@types/react-transition-group": "^4.4.12",
39
39
  "clsx": "^2.1.1",
40
40
  "prop-types": "^15.8.1",
41
41
  "react-transition-group": "^4.4.5",
42
- "@mui/x-internals": "8.17.0"
42
+ "@mui/x-internals": "8.19.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@emotion/react": "^11.9.0",