@mui/x-date-pickers 9.0.0-alpha.2 → 9.0.0-alpha.4

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 (48) hide show
  1. package/CHANGELOG.md +246 -1
  2. package/DateCalendar/PickersSlideTransition.js +7 -13
  3. package/DateCalendar/PickersSlideTransition.mjs +7 -13
  4. package/DateField/DateField.js +4 -4
  5. package/DateField/DateField.mjs +4 -4
  6. package/DateTimeField/DateTimeField.js +4 -4
  7. package/DateTimeField/DateTimeField.mjs +4 -4
  8. package/DigitalClock/DigitalClock.js +3 -1
  9. package/DigitalClock/DigitalClock.mjs +3 -1
  10. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +44 -7
  11. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.mjs +44 -7
  12. package/TimeField/TimeField.js +4 -4
  13. package/TimeField/TimeField.mjs +4 -4
  14. package/hooks/useSplitFieldProps.d.mts +1 -1
  15. package/hooks/useSplitFieldProps.d.ts +1 -1
  16. package/hooks/useSplitFieldProps.js +1 -1
  17. package/hooks/useSplitFieldProps.mjs +1 -1
  18. package/index.js +1 -1
  19. package/index.mjs +1 -1
  20. package/internals/components/PickerPopper/PickerPopper.js +17 -2
  21. package/internals/components/PickerPopper/PickerPopper.mjs +17 -2
  22. package/internals/components/PickersModalDialog.js +7 -4
  23. package/internals/components/PickersModalDialog.mjs +7 -4
  24. package/internals/hooks/useField/useField.types.d.mts +1 -1
  25. package/internals/hooks/useField/useField.types.d.ts +1 -1
  26. package/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +2 -2
  27. package/internals/hooks/useField/useFieldInternalPropsWithDefaults.mjs +2 -2
  28. package/internals/hooks/useField/useFieldV6TextField.js +4 -3
  29. package/internals/hooks/useField/useFieldV6TextField.mjs +4 -3
  30. package/internals/hooks/useField/useFieldV7TextField.js +4 -3
  31. package/internals/hooks/useField/useFieldV7TextField.mjs +4 -3
  32. package/internals/hooks/useNullableFieldPrivateContext.d.mts +2 -1
  33. package/internals/hooks/useNullableFieldPrivateContext.d.ts +2 -1
  34. package/internals/hooks/usePicker/usePicker.js +13 -8
  35. package/internals/hooks/usePicker/usePicker.mjs +13 -8
  36. package/internals/hooks/usePicker/usePicker.types.d.mts +2 -1
  37. package/internals/hooks/usePicker/usePicker.types.d.ts +2 -1
  38. package/internals/index.d.mts +1 -0
  39. package/internals/index.d.ts +1 -0
  40. package/internals/index.js +7 -0
  41. package/internals/index.mjs +1 -0
  42. package/internals/utils/isElementInteractive.d.mts +1 -0
  43. package/internals/utils/isElementInteractive.d.ts +1 -0
  44. package/internals/utils/isElementInteractive.js +34 -0
  45. package/internals/utils/isElementInteractive.mjs +28 -0
  46. package/models/fields.d.mts +5 -1
  47. package/models/fields.d.ts +5 -1
  48. package/package.json +50 -50
@@ -111,6 +111,10 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
111
111
  * @default true
112
112
  */
113
113
  enableAccessibleFieldDOMStructure: PropTypes.bool,
114
+ /**
115
+ * The ref object used to imperatively interact with the field.
116
+ */
117
+ fieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
114
118
  /**
115
119
  * If `true`, the component is displayed in focused state.
116
120
  */
@@ -314,10 +318,6 @@ process.env.NODE_ENV !== "production" ? TimeField.propTypes = {
314
318
  * @default The timezone of the `value` or `defaultValue` prop is defined, 'default' otherwise.
315
319
  */
316
320
  timezone: PropTypes.string,
317
- /**
318
- * The ref object used to imperatively interact with the field.
319
- */
320
- unstableFieldRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
321
321
  /**
322
322
  * The selected value.
323
323
  * Used when the component is controlled.
@@ -1,6 +1,6 @@
1
1
  import { DATE_TIME_VALIDATION_PROP_NAMES, DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES } from "../validation/extractValidationProps.mjs";
2
2
  import { PickerValueType } from "../models/common.mjs";
3
- declare const SHARED_FIELD_INTERNAL_PROP_NAMES: readonly ["value", "defaultValue", "referenceDate", "format", "formatDensity", "onChange", "timezone", "onError", "shouldRespectLeadingZeros", "selectedSections", "onSelectedSectionsChange", "unstableFieldRef", "unstableStartFieldRef", "unstableEndFieldRef", "enableAccessibleFieldDOMStructure", "disabled", "readOnly", "dateSeparator", "autoFocus", "focused"];
3
+ declare const SHARED_FIELD_INTERNAL_PROP_NAMES: readonly ["value", "defaultValue", "referenceDate", "format", "formatDensity", "onChange", "timezone", "onError", "shouldRespectLeadingZeros", "selectedSections", "onSelectedSectionsChange", "fieldRef", "startFieldRef", "endFieldRef", "enableAccessibleFieldDOMStructure", "disabled", "readOnly", "dateSeparator", "autoFocus", "focused"];
4
4
  export type InternalPropNames<TValueType extends PickerValueType> = (typeof SHARED_FIELD_INTERNAL_PROP_NAMES)[number] | (TValueType extends 'date' | 'date-time' ? (typeof DATE_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'time' | 'date-time' ? (typeof TIME_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'date-time' ? (typeof DATE_TIME_VALIDATION_PROP_NAMES)[number] : never);
5
5
  /**
6
6
  * Split the props received by the field component into:
@@ -1,6 +1,6 @@
1
1
  import { DATE_TIME_VALIDATION_PROP_NAMES, DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES } from "../validation/extractValidationProps.js";
2
2
  import { PickerValueType } from "../models/common.js";
3
- declare const SHARED_FIELD_INTERNAL_PROP_NAMES: readonly ["value", "defaultValue", "referenceDate", "format", "formatDensity", "onChange", "timezone", "onError", "shouldRespectLeadingZeros", "selectedSections", "onSelectedSectionsChange", "unstableFieldRef", "unstableStartFieldRef", "unstableEndFieldRef", "enableAccessibleFieldDOMStructure", "disabled", "readOnly", "dateSeparator", "autoFocus", "focused"];
3
+ declare const SHARED_FIELD_INTERNAL_PROP_NAMES: readonly ["value", "defaultValue", "referenceDate", "format", "formatDensity", "onChange", "timezone", "onError", "shouldRespectLeadingZeros", "selectedSections", "onSelectedSectionsChange", "fieldRef", "startFieldRef", "endFieldRef", "enableAccessibleFieldDOMStructure", "disabled", "readOnly", "dateSeparator", "autoFocus", "focused"];
4
4
  export type InternalPropNames<TValueType extends PickerValueType> = (typeof SHARED_FIELD_INTERNAL_PROP_NAMES)[number] | (TValueType extends 'date' | 'date-time' ? (typeof DATE_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'time' | 'date-time' ? (typeof TIME_VALIDATION_PROP_NAMES)[number] : never) | (TValueType extends 'date-time' ? (typeof DATE_TIME_VALIDATION_PROP_NAMES)[number] : never);
5
5
  /**
6
6
  * Split the props received by the field component into:
@@ -10,7 +10,7 @@ exports.useSplitFieldProps = void 0;
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
  var React = _interopRequireWildcard(require("react"));
12
12
  var _extractValidationProps = require("../validation/extractValidationProps");
13
- const SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'referenceDate', 'format', 'formatDensity', 'onChange', 'timezone', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'unstableFieldRef', 'unstableStartFieldRef', 'unstableEndFieldRef', 'enableAccessibleFieldDOMStructure', 'disabled', 'readOnly', 'dateSeparator', 'autoFocus', 'focused'];
13
+ const SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'referenceDate', 'format', 'formatDensity', 'onChange', 'timezone', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'fieldRef', 'startFieldRef', 'endFieldRef', 'enableAccessibleFieldDOMStructure', 'disabled', 'readOnly', 'dateSeparator', 'autoFocus', 'focused'];
14
14
  /**
15
15
  * Split the props received by the field component into:
16
16
  * - `internalProps` which are used by the various hooks called by the field component.
@@ -3,7 +3,7 @@
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import * as React from 'react';
5
5
  import { DATE_TIME_VALIDATION_PROP_NAMES, DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES } from "../validation/extractValidationProps.mjs";
6
- const SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'referenceDate', 'format', 'formatDensity', 'onChange', 'timezone', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'unstableFieldRef', 'unstableStartFieldRef', 'unstableEndFieldRef', 'enableAccessibleFieldDOMStructure', 'disabled', 'readOnly', 'dateSeparator', 'autoFocus', 'focused'];
6
+ const SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'referenceDate', 'format', 'formatDensity', 'onChange', 'timezone', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'fieldRef', 'startFieldRef', 'endFieldRef', 'enableAccessibleFieldDOMStructure', 'disabled', 'readOnly', 'dateSeparator', 'autoFocus', 'focused'];
7
7
  /**
8
8
  * Split the props received by the field component into:
9
9
  * - `internalProps` which are used by the various hooks called by the field component.
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v9.0.0-alpha.2
2
+ * @mui/x-date-pickers v9.0.0-alpha.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v9.0.0-alpha.2
2
+ * @mui/x-date-pickers v9.0.0-alpha.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -21,6 +21,7 @@ var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallb
21
21
  var _ownerDocument = _interopRequireDefault(require("@mui/utils/ownerDocument"));
22
22
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
23
23
  var _styles = require("@mui/material/styles");
24
+ var _isElementInteractive = require("../../utils/isElementInteractive");
24
25
  var _pickerPopperClasses = require("./pickerPopperClasses");
25
26
  var _utils = require("../../utils/utils");
26
27
  var _usePickerPrivateContext = require("../../hooks/usePickerPrivateContext");
@@ -213,6 +214,13 @@ const PickerPopperPaperWrapper = /*#__PURE__*/React.forwardRef((props, ref) => {
213
214
  }));
214
215
  });
215
216
  if (process.env.NODE_ENV !== "production") PickerPopperPaperWrapper.displayName = "PickerPopperPaperWrapper";
217
+ const isEventTargetInteractive = eventTarget => {
218
+ const element = eventTarget instanceof HTMLElement ? eventTarget : null;
219
+ if (!element) {
220
+ return false;
221
+ }
222
+ return (0, _isElementInteractive.isElementInteractive)(element);
223
+ };
216
224
  function PickerPopper(inProps) {
217
225
  const props = (0, _styles.useThemeProps)({
218
226
  props: inProps,
@@ -284,6 +292,14 @@ function PickerPopper(inProps) {
284
292
  dismissViews();
285
293
  });
286
294
  } else {
295
+ // Get all the targets of this event.
296
+ const eventTargets = event.composedPath();
297
+ // https://github.com/mui/mui-x/pull/13434
298
+ // Check if the click is on an interactive element.
299
+ // If it is, we don't want to refocus the last focused element.
300
+ if (eventTargets.some(isEventTargetInteractive)) {
301
+ lastFocusedElementRef.current = null;
302
+ }
287
303
  dismissViews();
288
304
  }
289
305
  });
@@ -330,8 +346,7 @@ function PickerPopper(inProps) {
330
346
  // which would force screen readers to read too old label
331
347
  ,
332
348
  disableRestoreFocus: true,
333
- disableEnforceFocus: viewContainerRole === 'tooltip',
334
- isEnabled: () => true
349
+ disableEnforceFocus: viewContainerRole === 'tooltip'
335
350
  }, slotProps?.desktopTrapFocus, {
336
351
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Transition, (0, _extends2.default)({}, TransitionProps, slotProps?.desktopTransition, {
337
352
  onExited: event => {
@@ -15,6 +15,7 @@ import useEventCallback from '@mui/utils/useEventCallback';
15
15
  import ownerDocument from '@mui/utils/ownerDocument';
16
16
  import composeClasses from '@mui/utils/composeClasses';
17
17
  import { styled, useThemeProps } from '@mui/material/styles';
18
+ import { isElementInteractive } from "../../utils/isElementInteractive.mjs";
18
19
  import { getPickerPopperUtilityClass } from "./pickerPopperClasses.mjs";
19
20
  import { executeInTheNextEventLoopTick, getActiveElement } from "../../utils/utils.mjs";
20
21
  import { usePickerPrivateContext } from "../../hooks/usePickerPrivateContext.mjs";
@@ -206,6 +207,13 @@ const PickerPopperPaperWrapper = /*#__PURE__*/React.forwardRef((props, ref) => {
206
207
  }));
207
208
  });
208
209
  if (process.env.NODE_ENV !== "production") PickerPopperPaperWrapper.displayName = "PickerPopperPaperWrapper";
210
+ const isEventTargetInteractive = eventTarget => {
211
+ const element = eventTarget instanceof HTMLElement ? eventTarget : null;
212
+ if (!element) {
213
+ return false;
214
+ }
215
+ return isElementInteractive(element);
216
+ };
209
217
  export function PickerPopper(inProps) {
210
218
  const props = useThemeProps({
211
219
  props: inProps,
@@ -277,6 +285,14 @@ export function PickerPopper(inProps) {
277
285
  dismissViews();
278
286
  });
279
287
  } else {
288
+ // Get all the targets of this event.
289
+ const eventTargets = event.composedPath();
290
+ // https://github.com/mui/mui-x/pull/13434
291
+ // Check if the click is on an interactive element.
292
+ // If it is, we don't want to refocus the last focused element.
293
+ if (eventTargets.some(isEventTargetInteractive)) {
294
+ lastFocusedElementRef.current = null;
295
+ }
280
296
  dismissViews();
281
297
  }
282
298
  });
@@ -323,8 +339,7 @@ export function PickerPopper(inProps) {
323
339
  // which would force screen readers to read too old label
324
340
  ,
325
341
  disableRestoreFocus: true,
326
- disableEnforceFocus: viewContainerRole === 'tooltip',
327
- isEnabled: () => true
342
+ disableEnforceFocus: viewContainerRole === 'tooltip'
328
343
  }, slotProps?.desktopTrapFocus, {
329
344
  children: /*#__PURE__*/_jsx(Transition, _extends({}, TransitionProps, slotProps?.desktopTransition, {
330
345
  onExited: event => {
@@ -48,7 +48,6 @@ function PickersModalDialog(props) {
48
48
  onPopperExited
49
49
  } = (0, _usePickerPrivateContext.usePickerPrivateContext)();
50
50
  const Dialog = slots?.dialog ?? PickersModalDialogRoot;
51
- const Transition = slots?.mobileTransition ?? _Fade.default;
52
51
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Dialog, (0, _extends2.default)({
53
52
  open: open,
54
53
  onClose: () => {
@@ -56,10 +55,14 @@ function PickersModalDialog(props) {
56
55
  onPopperExited?.();
57
56
  }
58
57
  }, slotProps?.dialog, {
59
- TransitionComponent: Transition,
60
- TransitionProps: slotProps?.mobileTransition,
61
58
  PaperComponent: slots?.mobilePaper,
62
- PaperProps: slotProps?.mobilePaper,
59
+ slots: (0, _extends2.default)({
60
+ transition: slots?.mobileTransition ?? _Fade.default
61
+ }, slotProps?.dialog?.slots),
62
+ slotProps: (0, _extends2.default)({
63
+ transition: slotProps?.mobileTransition,
64
+ paper: slotProps?.mobilePaper
65
+ }, slotProps?.dialog?.slotProps),
63
66
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersModalDialogContent, {
64
67
  children: children
65
68
  })
@@ -40,7 +40,6 @@ export function PickersModalDialog(props) {
40
40
  onPopperExited
41
41
  } = usePickerPrivateContext();
42
42
  const Dialog = slots?.dialog ?? PickersModalDialogRoot;
43
- const Transition = slots?.mobileTransition ?? Fade;
44
43
  return /*#__PURE__*/_jsx(Dialog, _extends({
45
44
  open: open,
46
45
  onClose: () => {
@@ -48,10 +47,14 @@ export function PickersModalDialog(props) {
48
47
  onPopperExited?.();
49
48
  }
50
49
  }, slotProps?.dialog, {
51
- TransitionComponent: Transition,
52
- TransitionProps: slotProps?.mobileTransition,
53
50
  PaperComponent: slots?.mobilePaper,
54
- PaperProps: slotProps?.mobilePaper,
51
+ slots: _extends({
52
+ transition: slots?.mobileTransition ?? Fade
53
+ }, slotProps?.dialog?.slots),
54
+ slotProps: _extends({
55
+ transition: slotProps?.mobileTransition,
56
+ paper: slotProps?.mobilePaper
57
+ }, slotProps?.dialog?.slotProps),
55
58
  children: /*#__PURE__*/_jsx(PickersModalDialogContent, {
56
59
  children: children
57
60
  })
@@ -75,7 +75,7 @@ export interface UseFieldInternalProps<TValue extends PickerValidValue, TEnableA
75
75
  /**
76
76
  * The ref object used to imperatively interact with the field.
77
77
  */
78
- unstableFieldRef?: React.Ref<FieldRef<TValue>>;
78
+ fieldRef?: React.Ref<FieldRef<TValue>>;
79
79
  /**
80
80
  * @default true
81
81
  */
@@ -75,7 +75,7 @@ export interface UseFieldInternalProps<TValue extends PickerValidValue, TEnableA
75
75
  /**
76
76
  * The ref object used to imperatively interact with the field.
77
77
  */
78
- unstableFieldRef?: React.Ref<FieldRef<TValue>>;
78
+ fieldRef?: React.Ref<FieldRef<TValue>>;
79
79
  /**
80
80
  * @default true
81
81
  */
@@ -26,7 +26,7 @@ function useFieldInternalPropsWithDefaults(parameters) {
26
26
  } = parameters;
27
27
  const pickerContext = (0, _useNullablePickerContext.useNullablePickerContext)();
28
28
  const fieldPrivateContext = (0, _useNullableFieldPrivateContext.useNullableFieldPrivateContext)();
29
- const handleFieldRef = (0, _useForkRef.default)(internalProps.unstableFieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.fieldRef);
29
+ const handleFieldRef = (0, _useForkRef.default)(internalProps.fieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.internalFieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.fieldRef);
30
30
  const setValue = pickerContext?.setValue;
31
31
  const handleChangeFromPicker = React.useCallback((newValue, ctx) => {
32
32
  return setValue?.(newValue, {
@@ -51,7 +51,7 @@ function useFieldInternalPropsWithDefaults(parameters) {
51
51
  enableAccessibleFieldDOMStructure: fieldPrivateContext.enableAccessibleFieldDOMStructure,
52
52
  selectedSections: fieldPrivateContext.selectedSections,
53
53
  onSelectedSectionsChange: fieldPrivateContext.onSelectedSectionsChange,
54
- unstableFieldRef: handleFieldRef
54
+ fieldRef: handleFieldRef
55
55
  }, internalProps);
56
56
  }
57
57
  return internalProps;
@@ -19,7 +19,7 @@ export function useFieldInternalPropsWithDefaults(parameters) {
19
19
  } = parameters;
20
20
  const pickerContext = useNullablePickerContext();
21
21
  const fieldPrivateContext = useNullableFieldPrivateContext();
22
- const handleFieldRef = useForkRef(internalProps.unstableFieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.fieldRef);
22
+ const handleFieldRef = useForkRef(internalProps.fieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.internalFieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.fieldRef);
23
23
  const setValue = pickerContext?.setValue;
24
24
  const handleChangeFromPicker = React.useCallback((newValue, ctx) => {
25
25
  return setValue?.(newValue, {
@@ -44,7 +44,7 @@ export function useFieldInternalPropsWithDefaults(parameters) {
44
44
  enableAccessibleFieldDOMStructure: fieldPrivateContext.enableAccessibleFieldDOMStructure,
45
45
  selectedSections: fieldPrivateContext.selectedSections,
46
46
  onSelectedSectionsChange: fieldPrivateContext.onSelectedSectionsChange,
47
- unstableFieldRef: handleFieldRef
47
+ fieldRef: handleFieldRef
48
48
  }, internalProps);
49
49
  }
50
50
  return internalProps;
@@ -90,7 +90,7 @@ const useFieldV6TextField = parameters => {
90
90
  disabled = false,
91
91
  autoFocus = false,
92
92
  focused,
93
- unstableFieldRef
93
+ fieldRef
94
94
  } = internalPropsWithDefaults;
95
95
  const inputRef = React.useRef(null);
96
96
  const handleRef = (0, _useForkRef.default)(inputRefProp, inputRef);
@@ -374,7 +374,7 @@ const useFieldV6TextField = parameters => {
374
374
  }, [activeSectionIndex, state.sections]);
375
375
  const inputHasFocus = inputRef.current && inputRef.current === (0, _utils.getActiveElement)(inputRef.current);
376
376
  const shouldShowPlaceholder = !inputHasFocus && areAllSectionsEmpty;
377
- React.useImperativeHandle(unstableFieldRef, () => ({
377
+ React.useImperativeHandle(fieldRef, () => ({
378
378
  getSections: () => state.sections,
379
379
  getActiveSectionIndex: () => {
380
380
  const browserStartIndex = inputRef.current.selectionStart ?? 0;
@@ -388,7 +388,8 @@ const useFieldV6TextField = parameters => {
388
388
  },
389
389
  setSelectedSections: newSelectedSections => setSelectedSections(newSelectedSections),
390
390
  focusField,
391
- isFieldFocused: () => isFieldFocused(inputRef)
391
+ isFieldFocused: () => isFieldFocused(inputRef),
392
+ clearValue
392
393
  }));
393
394
  return (0, _extends2.default)({}, forwardedProps, {
394
395
  error,
@@ -82,7 +82,7 @@ export const useFieldV6TextField = parameters => {
82
82
  disabled = false,
83
83
  autoFocus = false,
84
84
  focused,
85
- unstableFieldRef
85
+ fieldRef
86
86
  } = internalPropsWithDefaults;
87
87
  const inputRef = React.useRef(null);
88
88
  const handleRef = useForkRef(inputRefProp, inputRef);
@@ -366,7 +366,7 @@ export const useFieldV6TextField = parameters => {
366
366
  }, [activeSectionIndex, state.sections]);
367
367
  const inputHasFocus = inputRef.current && inputRef.current === getActiveElement(inputRef.current);
368
368
  const shouldShowPlaceholder = !inputHasFocus && areAllSectionsEmpty;
369
- React.useImperativeHandle(unstableFieldRef, () => ({
369
+ React.useImperativeHandle(fieldRef, () => ({
370
370
  getSections: () => state.sections,
371
371
  getActiveSectionIndex: () => {
372
372
  const browserStartIndex = inputRef.current.selectionStart ?? 0;
@@ -380,7 +380,8 @@ export const useFieldV6TextField = parameters => {
380
380
  },
381
381
  setSelectedSections: newSelectedSections => setSelectedSections(newSelectedSections),
382
382
  focusField,
383
- isFieldFocused: () => isFieldFocused(inputRef)
383
+ isFieldFocused: () => isFieldFocused(inputRef),
384
+ clearValue
384
385
  }));
385
386
  return _extends({}, forwardedProps, {
386
387
  error,
@@ -59,7 +59,7 @@ const useFieldV7TextField = parameters => {
59
59
  readOnly = false,
60
60
  autoFocus = false,
61
61
  focused: focusedProp,
62
- unstableFieldRef
62
+ fieldRef
63
63
  } = internalPropsWithDefaults;
64
64
  const sectionListRef = React.useRef(null);
65
65
  const handleSectionListRef = (0, _useForkRef.default)(sectionListRefProp, sectionListRef);
@@ -219,7 +219,7 @@ Learn more about the field accessible DOM structure on the MUI documentation: ht
219
219
  stateResponse
220
220
  });
221
221
  });
222
- React.useImperativeHandle(unstableFieldRef, () => ({
222
+ React.useImperativeHandle(fieldRef, () => ({
223
223
  getSections: () => state.sections,
224
224
  getActiveSectionIndex: () => getActiveSectionIndex(sectionListRef),
225
225
  setSelectedSections: newSelectedSections => {
@@ -232,7 +232,8 @@ Learn more about the field accessible DOM structure on the MUI documentation: ht
232
232
  setSelectedSections(newSelectedSections);
233
233
  },
234
234
  focusField,
235
- isFieldFocused: () => isFieldFocused(sectionListRef)
235
+ isFieldFocused: () => isFieldFocused(sectionListRef),
236
+ clearValue
236
237
  }));
237
238
  return (0, _extends2.default)({}, forwardedProps, rootProps, {
238
239
  onBlur: handleRootBlur,
@@ -52,7 +52,7 @@ export const useFieldV7TextField = parameters => {
52
52
  readOnly = false,
53
53
  autoFocus = false,
54
54
  focused: focusedProp,
55
- unstableFieldRef
55
+ fieldRef
56
56
  } = internalPropsWithDefaults;
57
57
  const sectionListRef = React.useRef(null);
58
58
  const handleSectionListRef = useForkRef(sectionListRefProp, sectionListRef);
@@ -212,7 +212,7 @@ Learn more about the field accessible DOM structure on the MUI documentation: ht
212
212
  stateResponse
213
213
  });
214
214
  });
215
- React.useImperativeHandle(unstableFieldRef, () => ({
215
+ React.useImperativeHandle(fieldRef, () => ({
216
216
  getSections: () => state.sections,
217
217
  getActiveSectionIndex: () => getActiveSectionIndex(sectionListRef),
218
218
  setSelectedSections: newSelectedSections => {
@@ -225,7 +225,8 @@ Learn more about the field accessible DOM structure on the MUI documentation: ht
225
225
  setSelectedSections(newSelectedSections);
226
226
  },
227
227
  focusField,
228
- isFieldFocused: () => isFieldFocused(sectionListRef)
228
+ isFieldFocused: () => isFieldFocused(sectionListRef),
229
+ clearValue
229
230
  }));
230
231
  return _extends({}, forwardedProps, rootProps, {
231
232
  onBlur: handleRootBlur,
@@ -5,5 +5,6 @@ import { PickerRangeValue, PickerValue } from "../models/index.mjs";
5
5
  export declare const PickerFieldPrivateContext: React.Context<PickerFieldPrivateContextValue | null>;
6
6
  export declare function useNullableFieldPrivateContext(): PickerFieldPrivateContextValue | null;
7
7
  export interface PickerFieldPrivateContextValue extends Pick<UseFieldInternalProps<any, any, any>, 'formatDensity' | 'enableAccessibleFieldDOMStructure' | 'selectedSections' | 'onSelectedSectionsChange'> {
8
- fieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
8
+ internalFieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
9
+ fieldRef?: React.RefObject<FieldRef<any> | null>;
9
10
  }
@@ -5,5 +5,6 @@ import { PickerRangeValue, PickerValue } from "../models/index.js";
5
5
  export declare const PickerFieldPrivateContext: React.Context<PickerFieldPrivateContextValue | null>;
6
6
  export declare function useNullableFieldPrivateContext(): PickerFieldPrivateContextValue | null;
7
7
  export interface PickerFieldPrivateContextValue extends Pick<UseFieldInternalProps<any, any, any>, 'formatDensity' | 'enableAccessibleFieldDOMStructure' | 'selectedSections' | 'onSelectedSectionsChange'> {
8
- fieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
8
+ internalFieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
9
+ fieldRef?: React.RefObject<FieldRef<any> | null>;
9
10
  }
@@ -84,7 +84,7 @@ const usePicker = ({
84
84
  */
85
85
  const [triggerElement, triggerRef] = React.useState(null);
86
86
  const popupRef = React.useRef(null);
87
- const fieldRef = React.useRef(null);
87
+ const internalFieldRef = React.useRef(null);
88
88
  const rootRefObject = React.useRef(null);
89
89
  const rootRef = (0, _useForkRef.default)(ref, rootRefObject);
90
90
  const {
@@ -119,9 +119,14 @@ const usePicker = ({
119
119
  autoFocus: autoFocusView,
120
120
  getStepNavigation
121
121
  });
122
- const clearValue = (0, _useEventCallback.default)(() => setValue(valueManager.emptyValue, {
123
- source: 'view'
124
- }));
122
+ const clearValue = (0, _useEventCallback.default)(() => {
123
+ if (value === null && internalFieldRef.current?.clearValue) {
124
+ internalFieldRef.current.clearValue();
125
+ }
126
+ setValue(valueManager.emptyValue, {
127
+ source: 'view'
128
+ });
129
+ });
125
130
  const setValueToToday = (0, _useEventCallback.default)(() => setValue(valueManager.getTodayValue(adapter, timezone, valueType), {
126
131
  source: 'view'
127
132
  }));
@@ -168,10 +173,10 @@ const usePicker = ({
168
173
  if (currentViewMode === 'field' && state.open) {
169
174
  setOpen(false);
170
175
  setTimeout(() => {
171
- fieldRef?.current?.setSelectedSections(view);
176
+ internalFieldRef?.current?.setSelectedSections(view);
172
177
  // focusing the input before the range selection is done
173
178
  // calling it outside of timeout results in an inconsistent behavior between Safari And Chrome
174
- fieldRef?.current?.focusField(view);
179
+ internalFieldRef?.current?.focusField(view);
175
180
  });
176
181
  }
177
182
  }, [view]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -273,8 +278,8 @@ const usePicker = ({
273
278
  enableAccessibleFieldDOMStructure,
274
279
  selectedSections,
275
280
  onSelectedSectionsChange,
276
- fieldRef
277
- }), [formatDensity, enableAccessibleFieldDOMStructure, selectedSections, onSelectedSectionsChange, fieldRef]);
281
+ internalFieldRef
282
+ }), [formatDensity, enableAccessibleFieldDOMStructure, selectedSections, onSelectedSectionsChange, internalFieldRef]);
278
283
  const isValidContextValue = testedValue => {
279
284
  const error = validator({
280
285
  adapter,
@@ -77,7 +77,7 @@ export const usePicker = ({
77
77
  */
78
78
  const [triggerElement, triggerRef] = React.useState(null);
79
79
  const popupRef = React.useRef(null);
80
- const fieldRef = React.useRef(null);
80
+ const internalFieldRef = React.useRef(null);
81
81
  const rootRefObject = React.useRef(null);
82
82
  const rootRef = useForkRef(ref, rootRefObject);
83
83
  const {
@@ -112,9 +112,14 @@ export const usePicker = ({
112
112
  autoFocus: autoFocusView,
113
113
  getStepNavigation
114
114
  });
115
- const clearValue = useEventCallback(() => setValue(valueManager.emptyValue, {
116
- source: 'view'
117
- }));
115
+ const clearValue = useEventCallback(() => {
116
+ if (value === null && internalFieldRef.current?.clearValue) {
117
+ internalFieldRef.current.clearValue();
118
+ }
119
+ setValue(valueManager.emptyValue, {
120
+ source: 'view'
121
+ });
122
+ });
118
123
  const setValueToToday = useEventCallback(() => setValue(valueManager.getTodayValue(adapter, timezone, valueType), {
119
124
  source: 'view'
120
125
  }));
@@ -161,10 +166,10 @@ export const usePicker = ({
161
166
  if (currentViewMode === 'field' && state.open) {
162
167
  setOpen(false);
163
168
  setTimeout(() => {
164
- fieldRef?.current?.setSelectedSections(view);
169
+ internalFieldRef?.current?.setSelectedSections(view);
165
170
  // focusing the input before the range selection is done
166
171
  // calling it outside of timeout results in an inconsistent behavior between Safari And Chrome
167
- fieldRef?.current?.focusField(view);
172
+ internalFieldRef?.current?.focusField(view);
168
173
  });
169
174
  }
170
175
  }, [view]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -266,8 +271,8 @@ export const usePicker = ({
266
271
  enableAccessibleFieldDOMStructure,
267
272
  selectedSections,
268
273
  onSelectedSectionsChange,
269
- fieldRef
270
- }), [formatDensity, enableAccessibleFieldDOMStructure, selectedSections, onSelectedSectionsChange, fieldRef]);
274
+ internalFieldRef
275
+ }), [formatDensity, enableAccessibleFieldDOMStructure, selectedSections, onSelectedSectionsChange, internalFieldRef]);
271
276
  const isValidContextValue = testedValue => {
272
277
  const error = validator({
273
278
  adapter,
@@ -1,3 +1,4 @@
1
+ import type * as React from 'react';
1
2
  import { SxProps } from '@mui/system';
2
3
  import { Theme } from '@mui/material/styles';
3
4
  import { InferError, OnErrorProps, PickerChangeHandlerContext, PickerOwnerState, PickerValidDate, PickerValueType, TimezoneProps } from "../../../models/index.mjs";
@@ -68,7 +69,7 @@ export interface UsePickerBaseProps<TValue extends PickerValidValue, TView exten
68
69
  /**
69
70
  * Props used to handle the value of non-static Pickers.
70
71
  */
71
- export interface UsePickerNonStaticProps extends Omit<PickerFieldPrivateContextValue, 'fieldRef'> {
72
+ export interface UsePickerNonStaticProps extends Omit<PickerFieldPrivateContextValue, 'internalFieldRef' | 'fieldRef'> {
72
73
  /**
73
74
  * If `true`, the Picker will close after submitting the full date.
74
75
  * @default false
@@ -1,3 +1,4 @@
1
+ import type * as React from 'react';
1
2
  import { SxProps } from '@mui/system';
2
3
  import { Theme } from '@mui/material/styles';
3
4
  import { InferError, OnErrorProps, PickerChangeHandlerContext, PickerOwnerState, PickerValidDate, PickerValueType, TimezoneProps } from "../../../models/index.js";
@@ -68,7 +69,7 @@ export interface UsePickerBaseProps<TValue extends PickerValidValue, TView exten
68
69
  /**
69
70
  * Props used to handle the value of non-static Pickers.
70
71
  */
71
- export interface UsePickerNonStaticProps extends Omit<PickerFieldPrivateContextValue, 'fieldRef'> {
72
+ export interface UsePickerNonStaticProps extends Omit<PickerFieldPrivateContextValue, 'internalFieldRef' | 'fieldRef'> {
72
73
  /**
73
74
  * If `true`, the Picker will close after submitting the full date.
74
75
  * @default false
@@ -64,6 +64,7 @@ export { resolveTimeViewsResponse, resolveDateTimeFormat } from "./utils/date-ti
64
64
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, mergeSx, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from "./utils/utils.mjs";
65
65
  export { useReduceAnimations } from "./hooks/useReduceAnimations.mjs";
66
66
  export { applyDefaultViewProps } from "./utils/views.mjs";
67
+ export { isElementInteractive } from "./utils/isElementInteractive.mjs";
67
68
  export { DayCalendar } from "../DateCalendar/DayCalendar.mjs";
68
69
  export type { DayCalendarProps, DayCalendarSlots, DayCalendarSlotProps, ExportedDayCalendarProps } from "../DateCalendar/DayCalendar.mjs";
69
70
  export type { ExportedDateCalendarProps } from "../DateCalendar/DateCalendar.types.mjs";
@@ -64,6 +64,7 @@ export { resolveTimeViewsResponse, resolveDateTimeFormat } from "./utils/date-ti
64
64
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, mergeSx, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from "./utils/utils.js";
65
65
  export { useReduceAnimations } from "./hooks/useReduceAnimations.js";
66
66
  export { applyDefaultViewProps } from "./utils/views.js";
67
+ export { isElementInteractive } from "./utils/isElementInteractive.js";
67
68
  export { DayCalendar } from "../DateCalendar/DayCalendar.js";
68
69
  export type { DayCalendarProps, DayCalendarSlots, DayCalendarSlotProps, ExportedDayCalendarProps } from "../DateCalendar/DayCalendar.js";
69
70
  export type { ExportedDateCalendarProps } from "../DateCalendar/DateCalendar.types.js";
@@ -201,6 +201,12 @@ Object.defineProperty(exports, "isDatePickerView", {
201
201
  return _dateUtils.isDatePickerView;
202
202
  }
203
203
  });
204
+ Object.defineProperty(exports, "isElementInteractive", {
205
+ enumerable: true,
206
+ get: function () {
207
+ return _isElementInteractive.isElementInteractive;
208
+ }
209
+ });
204
210
  Object.defineProperty(exports, "isInternalTimeView", {
205
211
  enumerable: true,
206
212
  get: function () {
@@ -464,6 +470,7 @@ var _dateTimeUtils = require("./utils/date-time-utils");
464
470
  var _utils = require("./utils/utils");
465
471
  var _useReduceAnimations = require("./hooks/useReduceAnimations");
466
472
  var _views = require("./utils/views");
473
+ var _isElementInteractive = require("./utils/isElementInteractive");
467
474
  var _DayCalendar = require("../DateCalendar/DayCalendar");
468
475
  var _useCalendarState = require("../DateCalendar/useCalendarState");
469
476
  var _DateTimePickerToolbar = require("../DateTimePicker/DateTimePickerToolbar");
@@ -33,6 +33,7 @@ export { resolveTimeViewsResponse, resolveDateTimeFormat } from "./utils/date-ti
33
33
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, mergeSx, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from "./utils/utils.mjs";
34
34
  export { useReduceAnimations } from "./hooks/useReduceAnimations.mjs";
35
35
  export { applyDefaultViewProps } from "./utils/views.mjs";
36
+ export { isElementInteractive } from "./utils/isElementInteractive.mjs";
36
37
  export { DayCalendar } from "../DateCalendar/DayCalendar.mjs";
37
38
  export { useCalendarState } from "../DateCalendar/useCalendarState.mjs";
38
39
  export { DateTimePickerToolbarOverrideContext } from "../DateTimePicker/DateTimePickerToolbar.mjs";
@@ -0,0 +1 @@
1
+ export declare function isElementInteractive(element: HTMLElement): boolean;
@@ -0,0 +1 @@
1
+ export declare function isElementInteractive(element: HTMLElement): boolean;