@mui/x-date-pickers 6.0.2 → 6.0.3

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 (129) hide show
  1. package/AdapterDateFns/index.js +1 -0
  2. package/AdapterDateFnsJalali/index.js +1 -0
  3. package/AdapterDayjs/index.js +5 -0
  4. package/AdapterLuxon/index.js +1 -0
  5. package/AdapterMoment/index.js +5 -0
  6. package/AdapterMomentHijri/index.js +5 -0
  7. package/AdapterMomentJalaali/index.js +5 -0
  8. package/CHANGELOG.md +58 -5
  9. package/DateField/DateField.js +4 -0
  10. package/DateField/DateField.types.d.ts +2 -2
  11. package/DateField/useDateField.js +5 -3
  12. package/DateTimeField/DateTimeField.js +4 -0
  13. package/DateTimeField/DateTimeField.types.d.ts +2 -2
  14. package/DateTimeField/useDateTimeField.js +5 -3
  15. package/PickersDay/PickersDay.js +4 -4
  16. package/TimeField/TimeField.js +4 -0
  17. package/TimeField/TimeField.types.d.ts +2 -2
  18. package/TimeField/useTimeField.js +5 -3
  19. package/index.d.ts +1 -6
  20. package/index.js +4 -2
  21. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +5 -4
  22. package/internals/hooks/useField/index.d.ts +2 -2
  23. package/internals/hooks/useField/index.js +1 -1
  24. package/internals/hooks/useField/useField.d.ts +1 -1
  25. package/internals/hooks/useField/useField.js +54 -25
  26. package/internals/hooks/useField/useField.types.d.ts +24 -12
  27. package/internals/hooks/useField/useFieldState.d.ts +1 -2
  28. package/internals/hooks/useField/useFieldState.js +1 -6
  29. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +5 -4
  30. package/internals/hooks/usePicker/usePicker.d.ts +2 -1
  31. package/internals/hooks/usePicker/usePicker.types.d.ts +4 -3
  32. package/internals/hooks/usePicker/usePickerValue.d.ts +8 -8
  33. package/internals/hooks/usePicker/usePickerValue.js +7 -11
  34. package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +2 -1
  35. package/internals/index.d.ts +2 -2
  36. package/internals/index.js +2 -2
  37. package/internals/models/fields.d.ts +3 -3
  38. package/internals/utils/date-utils.d.ts +1 -0
  39. package/internals/utils/date-utils.js +6 -0
  40. package/internals/utils/valueManagers.js +4 -5
  41. package/legacy/AdapterDateFns/index.js +1 -0
  42. package/legacy/AdapterDateFnsJalali/index.js +1 -0
  43. package/legacy/AdapterDayjs/index.js +5 -0
  44. package/legacy/AdapterLuxon/index.js +1 -0
  45. package/legacy/AdapterMoment/index.js +5 -0
  46. package/legacy/AdapterMomentHijri/index.js +5 -0
  47. package/legacy/AdapterMomentJalaali/index.js +5 -0
  48. package/legacy/DateField/DateField.js +4 -0
  49. package/legacy/DateField/useDateField.js +4 -2
  50. package/legacy/DateTimeField/DateTimeField.js +4 -0
  51. package/legacy/DateTimeField/useDateTimeField.js +4 -2
  52. package/legacy/PickersDay/PickersDay.js +4 -4
  53. package/legacy/TimeField/TimeField.js +4 -0
  54. package/legacy/TimeField/useTimeField.js +4 -2
  55. package/legacy/index.js +4 -2
  56. package/legacy/internals/hooks/useField/index.js +1 -1
  57. package/legacy/internals/hooks/useField/useField.js +79 -39
  58. package/legacy/internals/hooks/useField/useFieldState.js +1 -8
  59. package/legacy/internals/hooks/usePicker/usePickerValue.js +9 -13
  60. package/legacy/internals/index.js +2 -2
  61. package/legacy/internals/utils/date-utils.js +6 -0
  62. package/legacy/internals/utils/valueManagers.js +3 -8
  63. package/legacy/locales/faIR.js +33 -16
  64. package/legacy/locales/nlNL.js +12 -10
  65. package/legacy/locales/plPL.js +12 -10
  66. package/legacy/models/index.js +1 -0
  67. package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  68. package/locales/faIR.js +13 -16
  69. package/locales/nlNL.js +8 -10
  70. package/locales/plPL.js +8 -10
  71. package/models/index.d.ts +6 -0
  72. package/models/index.js +1 -0
  73. package/models/package.json +6 -0
  74. package/modern/AdapterDateFns/index.js +1 -0
  75. package/modern/AdapterDateFnsJalali/index.js +1 -0
  76. package/modern/AdapterDayjs/index.js +5 -0
  77. package/modern/AdapterLuxon/index.js +1 -0
  78. package/modern/AdapterMoment/index.js +5 -0
  79. package/modern/AdapterMomentHijri/index.js +5 -0
  80. package/modern/AdapterMomentJalaali/index.js +5 -0
  81. package/modern/DateField/DateField.js +4 -0
  82. package/modern/DateField/useDateField.js +5 -3
  83. package/modern/DateTimeField/DateTimeField.js +4 -0
  84. package/modern/DateTimeField/useDateTimeField.js +5 -3
  85. package/modern/PickersDay/PickersDay.js +4 -4
  86. package/modern/TimeField/TimeField.js +4 -0
  87. package/modern/TimeField/useTimeField.js +5 -3
  88. package/modern/index.js +4 -2
  89. package/modern/internals/hooks/useField/index.js +1 -1
  90. package/modern/internals/hooks/useField/useField.js +53 -25
  91. package/modern/internals/hooks/useField/useFieldState.js +1 -6
  92. package/modern/internals/hooks/usePicker/usePickerValue.js +7 -11
  93. package/modern/internals/index.js +2 -2
  94. package/modern/internals/utils/date-utils.js +6 -0
  95. package/modern/internals/utils/valueManagers.js +4 -5
  96. package/modern/locales/faIR.js +13 -16
  97. package/modern/locales/nlNL.js +8 -10
  98. package/modern/locales/plPL.js +8 -10
  99. package/modern/models/index.js +1 -0
  100. package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  101. package/node/AdapterDateFns/index.js +1 -0
  102. package/node/AdapterDateFnsJalali/index.js +1 -0
  103. package/node/AdapterDayjs/index.js +5 -0
  104. package/node/AdapterLuxon/index.js +1 -0
  105. package/node/AdapterMoment/index.js +5 -0
  106. package/node/AdapterMomentHijri/index.js +5 -0
  107. package/node/AdapterMomentJalaali/index.js +5 -0
  108. package/node/DateField/DateField.js +4 -0
  109. package/node/DateField/useDateField.js +5 -3
  110. package/node/DateTimeField/DateTimeField.js +4 -0
  111. package/node/DateTimeField/useDateTimeField.js +5 -3
  112. package/node/PickersDay/PickersDay.js +4 -4
  113. package/node/TimeField/TimeField.js +4 -0
  114. package/node/TimeField/useTimeField.js +5 -3
  115. package/node/index.js +14 -2
  116. package/node/internals/hooks/useField/index.js +0 -6
  117. package/node/internals/hooks/useField/useField.js +52 -24
  118. package/node/internals/hooks/useField/useFieldState.js +1 -6
  119. package/node/internals/hooks/usePicker/usePickerValue.js +7 -11
  120. package/node/internals/index.js +6 -6
  121. package/node/internals/utils/date-utils.js +9 -2
  122. package/node/internals/utils/valueManagers.js +2 -3
  123. package/node/locales/faIR.js +13 -16
  124. package/node/locales/nlNL.js +8 -10
  125. package/node/locales/plPL.js +8 -10
  126. package/node/models/index.js +5 -0
  127. package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  128. package/package.json +2 -2
  129. package/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
@@ -5,9 +5,10 @@ import * as React from 'react';
5
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
6
6
  import useEventCallback from '@mui/utils/useEventCallback';
7
7
  import useForkRef from '@mui/utils/useForkRef';
8
+ import { useTheme } from '@mui/material/styles';
8
9
  import { useValidation } from '../validation/useValidation';
9
10
  import { useUtils } from '../useUtils';
10
- import { adjustSectionValue, isAndroid, cleanString } from './useField.utils';
11
+ import { adjustSectionValue, isAndroid, cleanString, getSectionOrder } from './useField.utils';
11
12
  import { useFieldState } from './useFieldState';
12
13
  import { useFieldCharacterEditing } from './useFieldCharacterEditing';
13
14
  import { getActiveElement } from '../../utils/utils';
@@ -22,7 +23,6 @@ export const useField = params => {
22
23
  updateSectionValue,
23
24
  updateValueFromValueStr,
24
25
  setTempAndroidValueStr,
25
- sectionOrder,
26
26
  sectionsValueBoundaries
27
27
  } = useFieldState(params);
28
28
  const {
@@ -38,7 +38,8 @@ export const useField = params => {
38
38
  inputRef: inputRefProp,
39
39
  internalProps,
40
40
  internalProps: {
41
- readOnly = false
41
+ readOnly = false,
42
+ unstableFieldRef
42
43
  },
43
44
  forwardedProps: {
44
45
  onClick,
@@ -57,6 +58,8 @@ export const useField = params => {
57
58
  const inputRef = React.useRef(null);
58
59
  const handleRef = useForkRef(inputRefProp, inputRef);
59
60
  const focusTimeoutRef = React.useRef(undefined);
61
+ const theme = useTheme();
62
+ const sectionOrder = React.useMemo(() => getSectionOrder(state.sections, theme.direction === 'rtl'), [theme.direction, state.sections]);
60
63
  const syncSelectionFromDOM = () => {
61
64
  var _selectionStart;
62
65
  if (readOnly) {
@@ -144,27 +147,32 @@ export const useField = params => {
144
147
  updateValueFromValueStr(cleanValueStr);
145
148
  return;
146
149
  }
147
- const prevValueStr = cleanString(fieldValueManager.getValueStrFromSections(state.sections));
148
- let startOfDiffIndex = -1;
149
- let endOfDiffIndex = -1;
150
- for (let i = 0; i < prevValueStr.length; i += 1) {
151
- if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
152
- startOfDiffIndex = i;
150
+ let keyPressed;
151
+ if (selectedSectionIndexes.startIndex === 0 && selectedSectionIndexes.endIndex === state.sections.length - 1) {
152
+ keyPressed = cleanValueStr;
153
+ } else {
154
+ const prevValueStr = cleanString(fieldValueManager.getValueStrFromSections(state.sections));
155
+ let startOfDiffIndex = -1;
156
+ let endOfDiffIndex = -1;
157
+ for (let i = 0; i < prevValueStr.length; i += 1) {
158
+ if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
159
+ startOfDiffIndex = i;
160
+ }
161
+ if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
162
+ endOfDiffIndex = i;
163
+ }
153
164
  }
154
- if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
155
- endOfDiffIndex = i;
165
+ const activeSection = state.sections[selectedSectionIndexes.startIndex];
166
+ const hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
167
+ if (hasDiffOutsideOfActiveSection) {
168
+ // TODO: Support if the new date is valid
169
+ return;
156
170
  }
157
- }
158
- const activeSection = state.sections[selectedSectionIndexes.startIndex];
159
- const hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
160
- if (hasDiffOutsideOfActiveSection) {
161
- // TODO: Support if the new date is valid
162
- return;
163
- }
164
171
 
165
- // The active section being selected, the browser has replaced its value with the key pressed by the user.
166
- const activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
167
- const keyPressed = cleanValueStr.slice(activeSection.start, activeSectionEndRelativeToNewValue);
172
+ // The active section being selected, the browser has replaced its value with the key pressed by the user.
173
+ const activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
174
+ keyPressed = cleanValueStr.slice(activeSection.start, activeSectionEndRelativeToNewValue);
175
+ }
168
176
  if (isAndroid() && keyPressed.length === 0) {
169
177
  setTempAndroidValueStr(valueStr);
170
178
  return;
@@ -260,9 +268,11 @@ export const useField = params => {
260
268
  });
261
269
  useEnhancedEffect(() => {
262
270
  if (selectedSectionIndexes == null) {
263
- if (inputRef.current.selectionStart !== 0 || inputRef.current.selectionEnd !== 0) {
264
- // Ensure input selection range is in sync with component selection indexes
265
- inputRef.current.setSelectionRange(0, 0);
271
+ if (inputRef.current.scrollLeft) {
272
+ // Ensure that input content is not marked as selected.
273
+ // setting selection range to 0 causes issues in Safari.
274
+ // https://bugs.webkit.org/show_bug.cgi?id=224425
275
+ inputRef.current.scrollLeft = 0;
266
276
  }
267
277
  return;
268
278
  }
@@ -275,7 +285,11 @@ export const useField = params => {
275
285
  selectionEnd += lastSelectedSection.endSeparator.length;
276
286
  }
277
287
  if (selectionStart !== inputRef.current.selectionStart || selectionEnd !== inputRef.current.selectionEnd) {
288
+ // Fix scroll jumping on iOS browser: https://github.com/mui/mui-x/issues/8321
289
+ const currentScrollTop = inputRef.current.scrollTop;
278
290
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
291
+ // Even reading this variable seems to do the trick, but also setting it just to make use of it
292
+ inputRef.current.scrollTop = currentScrollTop;
279
293
  }
280
294
  });
281
295
  const validationError = useValidation(_extends({}, internalProps, {
@@ -322,7 +336,22 @@ export const useField = params => {
322
336
  return 'tel';
323
337
  }, [selectedSectionIndexes, state.sections]);
324
338
  const inputHasFocus = inputRef.current && inputRef.current === getActiveElement(document);
325
- const shouldShowPlaceholder = !inputHasFocus && (!state.value || valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue));
339
+ const shouldShowPlaceholder = !inputHasFocus && valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue);
340
+ React.useImperativeHandle(unstableFieldRef, () => ({
341
+ getSections: () => state.sections,
342
+ getActiveSectionIndex: () => {
343
+ var _selectionStart2, _selectionEnd;
344
+ const browserStartIndex = (_selectionStart2 = inputRef.current.selectionStart) != null ? _selectionStart2 : 0;
345
+ const browserEndIndex = (_selectionEnd = inputRef.current.selectionEnd) != null ? _selectionEnd : 0;
346
+ if (browserStartIndex === 0 && browserEndIndex === 0) {
347
+ return null;
348
+ }
349
+ const nextSectionIndex = browserStartIndex <= state.sections[0].startInInput ? 1 // Special case if browser index is in invisible characters at the beginning.
350
+ : state.sections.findIndex(section => section.startInInput - section.startSeparator.length > browserStartIndex);
351
+ return nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
352
+ },
353
+ setSelectedSections: activeSectionIndex => setSelectedSections(activeSectionIndex)
354
+ }));
326
355
  return _extends({
327
356
  placeholder: state.placeholder,
328
357
  autoComplete: 'off'
@@ -3,7 +3,7 @@ import { FieldSectionType, MuiPickersAdapter } from '../../models';
3
3
  import type { PickerValueManager } from '../usePicker';
4
4
  import { InferError, Validator } from '../validation/useValidation';
5
5
  import { PickersLocaleText } from '../../../locales/utils/pickersLocaleTextApi';
6
- export interface UseFieldParams<TValue, TDate, TSection extends FieldSection, TForwardedProps extends UseFieldForwardedProps, TInternalProps extends UseFieldInternalProps<any, any>> {
6
+ export interface UseFieldParams<TValue, TDate, TSection extends FieldSection, TForwardedProps extends UseFieldForwardedProps, TInternalProps extends UseFieldInternalProps<any, any, any>> {
7
7
  inputRef?: React.Ref<HTMLInputElement>;
8
8
  forwardedProps: TForwardedProps;
9
9
  internalProps: TInternalProps;
@@ -12,7 +12,7 @@ export interface UseFieldParams<TValue, TDate, TSection extends FieldSection, TF
12
12
  validator: Validator<TValue, TDate, InferError<TInternalProps>, UseFieldValidationProps<TValue, TInternalProps>>;
13
13
  valueType: FieldValueType;
14
14
  }
15
- export interface UseFieldInternalProps<TValue, TError> {
15
+ export interface UseFieldInternalProps<TValue, TSection extends FieldSection, TError> {
16
16
  /**
17
17
  * The selected value.
18
18
  * Used when the component is controlled.
@@ -63,6 +63,28 @@ export interface UseFieldInternalProps<TValue, TError> {
63
63
  * @param {FieldSelectedSections} newValue The new selected sections.
64
64
  */
65
65
  onSelectedSectionsChange?: (newValue: FieldSelectedSections) => void;
66
+ /**
67
+ * The ref object used to imperatively interact with the field.
68
+ */
69
+ unstableFieldRef?: React.Ref<FieldRef<TSection>>;
70
+ }
71
+ export interface FieldRef<TSection extends FieldSection> {
72
+ /**
73
+ * Returns the sections of the current value.
74
+ * @returns {TSection[]} The sections of the current value.
75
+ */
76
+ getSections: () => TSection[];
77
+ /**
78
+ * Returns the index of the active section (the first focused section).
79
+ * If no section is active, returns `null`.
80
+ * @returns {number | null} The index of the active section.
81
+ */
82
+ getActiveSectionIndex: () => number | null;
83
+ /**
84
+ * Updates the selected sections.
85
+ * @param {FieldSelectedSections} selectedSections The sections to select.
86
+ */
87
+ setSelectedSections: (selectedSections: FieldSelectedSections) => void;
66
88
  }
67
89
  export interface UseFieldForwardedProps {
68
90
  onKeyDown?: React.KeyboardEventHandler;
@@ -269,16 +291,6 @@ export interface FieldValueManager<TValue, TDate, TSection extends FieldSection,
269
291
  * @returns {boolean} `true` if the current error is not empty.
270
292
  */
271
293
  hasError: (error: TError) => boolean;
272
- /**
273
- * Return a description of sections display order. This description is useful in RTL mode.
274
- * @template TDate
275
- * @param {MuiPickersAdapter<TDate>} utils The utils to manipulate the date.
276
- * @param {PickersLocaleText<TDate>} localeText The translation object.
277
- * @param {string} format The format from which sections are computed.
278
- * @param {boolean} isRTL Is the field in right-to-left orientation.
279
- * @returns {SectionOrdering} The description of sections order from left to right.
280
- */
281
- getSectionOrder: (utils: MuiPickersAdapter<TDate>, localeText: PickersLocaleText<TDate>, format: string, isRTL: boolean) => SectionOrdering;
282
294
  }
283
295
  export interface UseFieldState<TValue, TSection extends FieldSection> {
284
296
  value: TValue;
@@ -13,7 +13,7 @@ export interface UpdateSectionValueParams<TSection extends FieldSection> {
13
13
  */
14
14
  shouldGoToNextSection: boolean;
15
15
  }
16
- export declare const useFieldState: <TValue, TDate, TSection extends FieldSection, TForwardedProps extends UseFieldForwardedProps, TInternalProps extends UseFieldInternalProps<any, any>>(params: UseFieldParams<TValue, TDate, TSection, TForwardedProps, TInternalProps>) => {
16
+ export declare const useFieldState: <TValue, TDate, TSection extends FieldSection, TForwardedProps extends UseFieldForwardedProps, TInternalProps extends UseFieldInternalProps<any, any, any>>(params: UseFieldParams<TValue, TDate, TSection, TForwardedProps, TInternalProps>) => {
17
17
  state: UseFieldState<TValue, TSection>;
18
18
  selectedSectionIndexes: FieldSelectedSectionsIndexes | null;
19
19
  setSelectedSections: (newSelectedSections: FieldSelectedSections) => void;
@@ -22,6 +22,5 @@ export declare const useFieldState: <TValue, TDate, TSection extends FieldSectio
22
22
  updateSectionValue: ({ activeSection, newSectionValue, shouldGoToNextSection, }: UpdateSectionValueParams<TSection>) => void;
23
23
  updateValueFromValueStr: (valueStr: string) => void;
24
24
  setTempAndroidValueStr: (tempValueStrAndroid: string | null) => void;
25
- sectionOrder: import("./useField.types").SectionOrdering;
26
25
  sectionsValueBoundaries: import("./useField.types").FieldSectionsValueBoundaries<TDate>;
27
26
  };
@@ -1,6 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
- import { useTheme } from '@mui/material/styles';
4
3
  import useControlled from '@mui/utils/useControlled';
5
4
  import { useUtils, useLocaleText, useLocalizationContext } from '../useUtils';
6
5
  import { addPositionPropertiesToSections, splitFormatIntoSections, clampDaySection, mergeDateIntoReferenceDate, getSectionsBoundaries, validateSections, getDateFromDateSections } from './useField.utils';
@@ -9,8 +8,6 @@ export const useFieldState = params => {
9
8
  const utils = useUtils();
10
9
  const localeText = useLocaleText();
11
10
  const adapter = useLocalizationContext();
12
- const theme = useTheme();
13
- const isRTL = theme.direction === 'rtl';
14
11
  const {
15
12
  valueManager,
16
13
  fieldValueManager,
@@ -29,7 +26,6 @@ export const useFieldState = params => {
29
26
  const firstDefaultValue = React.useRef(defaultValue);
30
27
  const valueFromTheOutside = (_ref = valueProp != null ? valueProp : firstDefaultValue.current) != null ? _ref : valueManager.emptyValue;
31
28
  const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(utils), [utils]);
32
- const sectionOrder = React.useMemo(() => fieldValueManager.getSectionOrder(utils, localeText, format, isRTL), [fieldValueManager, format, isRTL, localeText, utils]);
33
29
  const placeholder = React.useMemo(() => fieldValueManager.getValueStrFromSections(fieldValueManager.getSectionsFromValue(utils, localeText, null, valueManager.emptyValue, format)), [fieldValueManager, format, localeText, utils, valueManager.emptyValue]);
34
30
  const [state, setState] = React.useState(() => {
35
31
  const sections = fieldValueManager.getSectionsFromValue(utils, localeText, null, valueFromTheOutside, format);
@@ -217,7 +213,7 @@ export const useFieldState = params => {
217
213
  }));
218
214
  React.useEffect(() => {
219
215
  if (!valueManager.areValuesEqual(utils, state.value, valueFromTheOutside)) {
220
- const sections = fieldValueManager.getSectionsFromValue(utils, localeText, state.sections, valueFromTheOutside, format);
216
+ const sections = fieldValueManager.getSectionsFromValue(utils, localeText, null, valueFromTheOutside, format);
221
217
  setState(prevState => _extends({}, prevState, {
222
218
  value: valueFromTheOutside,
223
219
  referenceValue: fieldValueManager.updateReferenceValue(utils, valueFromTheOutside, prevState.referenceValue),
@@ -244,7 +240,6 @@ export const useFieldState = params => {
244
240
  updateSectionValue,
245
241
  updateValueFromValueStr,
246
242
  setTempAndroidValueStr,
247
- sectionOrder,
248
243
  sectionsValueBoundaries
249
244
  };
250
245
  };
@@ -10,11 +10,12 @@ import { ExportedPickersLayoutSlotsComponent, ExportedPickersLayoutSlotsComponen
10
10
  import { UsePickerValueNonStaticProps } from '../usePicker/usePickerValue';
11
11
  import { UsePickerViewsNonStaticProps, UsePickerViewsProps } from '../usePicker/usePickerViews';
12
12
  import { UncapitalizeObjectKeys } from '../../utils/slots-migration';
13
+ import { FieldSection } from '../useField';
13
14
  export interface UseMobilePickerSlotsComponent<TDate, TView extends DateOrTimeView> extends PickersModalDialogSlotsComponent, ExportedPickersLayoutSlotsComponent<TDate | null, TDate, TView> {
14
15
  /**
15
16
  * Component used to enter the date with the keyboard.
16
17
  */
17
- Field: React.ElementType<BaseSingleInputFieldProps<TDate | null, any>>;
18
+ Field: React.ElementType<BaseSingleInputFieldProps<TDate | null, FieldSection, any>>;
18
19
  /**
19
20
  * Form control with an input to render the value inside the default field.
20
21
  * Receives the same props as `@mui/material/TextField`.
@@ -23,12 +24,12 @@ export interface UseMobilePickerSlotsComponent<TDate, TView extends DateOrTimeVi
23
24
  TextField?: React.ElementType<TextFieldProps>;
24
25
  }
25
26
  export interface ExportedUseMobilePickerSlotsComponentsProps<TDate, TView extends DateOrTimeView> extends PickersModalDialogSlotsComponentsProps, ExportedPickersLayoutSlotsComponentsProps<TDate | null, TDate, TView> {
26
- field?: SlotComponentProps<React.ElementType<BaseSingleInputFieldProps<TDate | null, unknown>>, {}, UsePickerProps<TDate | null, any, any, any, any>>;
27
+ field?: SlotComponentProps<React.ElementType<BaseSingleInputFieldProps<TDate | null, FieldSection, unknown>>, {}, UsePickerProps<TDate | null, any, FieldSection, any, any, any>>;
27
28
  textField?: SlotComponentProps<typeof TextField, {}, Record<string, any>>;
28
29
  }
29
30
  export interface UseMobilePickerSlotsComponentsProps<TDate, TView extends DateOrTimeView> extends ExportedUseMobilePickerSlotsComponentsProps<TDate, TView>, Pick<PickersLayoutSlotsComponentsProps<TDate | null, TDate, TView>, 'toolbar'> {
30
31
  }
31
- export interface MobileOnlyPickerProps<TDate> extends BaseNonStaticPickerProps, BaseSingleInputNonStaticPickerProps, UsePickerValueNonStaticProps<TDate | null>, UsePickerViewsNonStaticProps {
32
+ export interface MobileOnlyPickerProps<TDate> extends BaseNonStaticPickerProps, BaseSingleInputNonStaticPickerProps, UsePickerValueNonStaticProps<TDate | null, FieldSection>, UsePickerViewsNonStaticProps {
32
33
  }
33
34
  export interface UseMobilePickerProps<TDate, TView extends DateOrTimeView, TError, TExternalProps extends UsePickerViewsProps<any, TView, any, any>> extends BasePickerProps<TDate | null, TDate, TView, TError, TExternalProps, {}>, MobileOnlyPickerProps<TDate> {
34
35
  /**
@@ -42,7 +43,7 @@ export interface UseMobilePickerProps<TDate, TView extends DateOrTimeView, TErro
42
43
  */
43
44
  slotProps?: UseMobilePickerSlotsComponentsProps<TDate, TView>;
44
45
  }
45
- export interface UseMobilePickerParams<TDate, TView extends DateOrTimeView, TExternalProps extends UseMobilePickerProps<TDate, TView, any, TExternalProps>> extends Pick<UsePickerParams<TDate | null, TDate, TView, TExternalProps, {}>, 'valueManager' | 'validator'> {
46
+ export interface UseMobilePickerParams<TDate, TView extends DateOrTimeView, TExternalProps extends UseMobilePickerProps<TDate, TView, any, TExternalProps>> extends Pick<UsePickerParams<TDate | null, TDate, TView, FieldSection, TExternalProps, {}>, 'valueManager' | 'validator'> {
46
47
  props: TExternalProps;
47
48
  getOpenDialogAriaText: (date: TDate | null, utils: MuiPickersAdapter<TDate>) => string;
48
49
  }
@@ -1,4 +1,5 @@
1
1
  import { DateOrTimeView } from '../../models';
2
2
  import { UsePickerParams, UsePickerProps, UsePickerResponse } from './usePicker.types';
3
3
  import { InferError } from '../validation/useValidation';
4
- export declare const usePicker: <TValue, TDate, TView extends DateOrTimeView, TExternalProps extends UsePickerProps<TValue, TView, any, any, any>, TAdditionalProps extends {}>({ props, valueManager, wrapperVariant, inputRef, additionalViewProps, validator, autoFocusView, }: UsePickerParams<TValue, TDate, TView, TExternalProps, TAdditionalProps>) => UsePickerResponse<TValue, TView, InferError<TExternalProps>>;
4
+ import { FieldSection } from '../useField';
5
+ export declare const usePicker: <TValue, TDate, TView extends DateOrTimeView, TSection extends FieldSection, TExternalProps extends UsePickerProps<TValue, TView, TSection, any, any, any>, TAdditionalProps extends {}>({ props, valueManager, wrapperVariant, inputRef, additionalViewProps, validator, autoFocusView, }: UsePickerParams<TValue, TDate, TView, TSection, TExternalProps, TAdditionalProps>) => UsePickerResponse<TValue, TView, TSection, InferError<TExternalProps>>;
@@ -2,15 +2,16 @@ import { DateOrTimeView } from '../../models/views';
2
2
  import { UsePickerValueParams, UsePickerValueProps, UsePickerValueBaseProps, UsePickerValueResponse } from './usePickerValue';
3
3
  import { UsePickerViewsProps, UsePickerViewParams, UsePickerViewsResponse, UsePickerViewsBaseProps } from './usePickerViews';
4
4
  import { UsePickerLayoutProps, UsePickerLayoutPropsResponse } from './usePickerLayoutProps';
5
+ import { FieldSection } from '../useField';
5
6
  /**
6
7
  * Props common to all picker headless implementations.
7
8
  */
8
9
  export interface UsePickerBaseProps<TValue, TView extends DateOrTimeView, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueBaseProps<TValue, TError>, UsePickerViewsBaseProps<TValue, TView, TExternalProps, TAdditionalProps>, UsePickerLayoutProps {
9
10
  }
10
- export interface UsePickerProps<TValue, TView extends DateOrTimeView, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueProps<TValue, TError>, UsePickerViewsProps<TValue, TView, TExternalProps, TAdditionalProps>, UsePickerLayoutProps {
11
+ export interface UsePickerProps<TValue, TView extends DateOrTimeView, TSection extends FieldSection, TError, TExternalProps extends UsePickerViewsProps<TValue, TView, any, any>, TAdditionalProps extends {}> extends UsePickerValueProps<TValue, TSection, TError>, UsePickerViewsProps<TValue, TView, TExternalProps, TAdditionalProps>, UsePickerLayoutProps {
11
12
  }
12
- export interface UsePickerParams<TValue, TDate, TView extends DateOrTimeView, TExternalProps extends UsePickerProps<TValue, TView, any, any, any>, TAdditionalProps extends {}> extends Pick<UsePickerValueParams<TValue, TDate, TExternalProps>, 'valueManager' | 'wrapperVariant' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps, TAdditionalProps>, 'additionalViewProps' | 'inputRef' | 'autoFocusView'> {
13
+ export interface UsePickerParams<TValue, TDate, TView extends DateOrTimeView, TSection extends FieldSection, TExternalProps extends UsePickerProps<TValue, TView, TSection, any, any, any>, TAdditionalProps extends {}> extends Pick<UsePickerValueParams<TValue, TDate, TSection, TExternalProps>, 'valueManager' | 'wrapperVariant' | 'validator'>, Pick<UsePickerViewParams<TValue, TView, TExternalProps, TAdditionalProps>, 'additionalViewProps' | 'inputRef' | 'autoFocusView'> {
13
14
  props: TExternalProps;
14
15
  }
15
- export interface UsePickerResponse<TValue, TView extends DateOrTimeView, TError> extends Omit<UsePickerValueResponse<TValue, TError>, 'viewProps' | 'layoutProps'>, Omit<UsePickerViewsResponse<TView>, 'layoutProps'>, UsePickerLayoutPropsResponse<TValue, TView> {
16
+ export interface UsePickerResponse<TValue, TView extends DateOrTimeView, TSection extends FieldSection, TError> extends Omit<UsePickerValueResponse<TValue, TSection, TError>, 'viewProps' | 'layoutProps'>, Omit<UsePickerViewsResponse<TView>, 'layoutProps'>, UsePickerLayoutPropsResponse<TValue, TView> {
16
17
  }
@@ -1,4 +1,4 @@
1
- import { FieldSelectedSections, UseFieldInternalProps } from '../useField';
1
+ import { FieldSection, FieldSelectedSections, UseFieldInternalProps } from '../useField';
2
2
  import { InferError, Validator } from '../validation/useValidation';
3
3
  import { UseFieldValidationProps } from '../useField/useField.types';
4
4
  import { WrapperVariant } from '../../models/common';
@@ -101,7 +101,7 @@ export interface UsePickerValueBaseProps<TValue, TError> {
101
101
  /**
102
102
  * Props used to handle the value of non-static pickers.
103
103
  */
104
- export interface UsePickerValueNonStaticProps<TValue> extends Pick<UseFieldInternalProps<TValue, unknown>, 'selectedSections' | 'onSelectedSectionsChange'> {
104
+ export interface UsePickerValueNonStaticProps<TValue, TSection extends FieldSection> extends Pick<UseFieldInternalProps<TValue, TSection, unknown>, 'selectedSections' | 'onSelectedSectionsChange'> {
105
105
  /**
106
106
  * If `true`, the popover or modal will close after submitting the full date.
107
107
  * @default `true` for desktop, `false` for mobile (based on the chosen wrapper and `desktopModeMediaQuery` prop).
@@ -126,9 +126,9 @@ export interface UsePickerValueNonStaticProps<TValue> extends Pick<UseFieldInter
126
126
  /**
127
127
  * Props used to handle the value of the pickers.
128
128
  */
129
- export interface UsePickerValueProps<TValue, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps<TValue> {
129
+ export interface UsePickerValueProps<TValue, TSection extends FieldSection, TError> extends UsePickerValueBaseProps<TValue, TError>, UsePickerValueNonStaticProps<TValue, TSection> {
130
130
  }
131
- export interface UsePickerValueParams<TValue, TDate, TExternalProps extends UsePickerValueProps<TValue, any>> {
131
+ export interface UsePickerValueParams<TValue, TDate, TSection extends FieldSection, TExternalProps extends UsePickerValueProps<TValue, TSection, any>> {
132
132
  props: TExternalProps;
133
133
  valueManager: PickerValueManager<TValue, TDate, InferError<TExternalProps>>;
134
134
  wrapperVariant: WrapperVariant;
@@ -143,7 +143,7 @@ export interface UsePickerValueActions {
143
143
  onOpen: () => void;
144
144
  onClose: () => void;
145
145
  }
146
- type UsePickerValueFieldResponse<TValue, TError> = Required<Pick<UseFieldInternalProps<TValue, TError>, 'value' | 'onChange' | 'selectedSections' | 'onSelectedSectionsChange'>>;
146
+ type UsePickerValueFieldResponse<TValue, TSection extends FieldSection, TError> = Required<Pick<UseFieldInternalProps<TValue, TSection, TError>, 'value' | 'onChange' | 'selectedSections' | 'onSelectedSectionsChange'>>;
147
147
  /**
148
148
  * Props passed to `usePickerViews`.
149
149
  */
@@ -162,15 +162,15 @@ export interface UsePickerValueLayoutResponse<TValue> extends UsePickerValueActi
162
162
  onChange: (newValue: TValue) => void;
163
163
  isValid: (value: TValue) => boolean;
164
164
  }
165
- export interface UsePickerValueResponse<TValue, TError> {
165
+ export interface UsePickerValueResponse<TValue, TSection extends FieldSection, TError> {
166
166
  open: boolean;
167
167
  actions: UsePickerValueActions;
168
168
  viewProps: UsePickerValueViewsResponse<TValue>;
169
- fieldProps: UsePickerValueFieldResponse<TValue, TError>;
169
+ fieldProps: UsePickerValueFieldResponse<TValue, TSection, TError>;
170
170
  layoutProps: UsePickerValueLayoutResponse<TValue>;
171
171
  }
172
172
  /**
173
173
  * Manage the value lifecycle of all the pickers.
174
174
  */
175
- export declare const usePickerValue: <TValue, TDate, TExternalProps extends UsePickerValueProps<TValue, any>>({ props, valueManager, wrapperVariant, validator, }: UsePickerValueParams<TValue, TDate, TExternalProps>) => UsePickerValueResponse<TValue, InferError<TExternalProps>>;
175
+ export declare const usePickerValue: <TValue, TDate, TSection extends FieldSection, TExternalProps extends UsePickerValueProps<TValue, TSection, any>>({ props, valueManager, wrapperVariant, validator, }: UsePickerValueParams<TValue, TDate, TSection, TExternalProps>) => UsePickerValueResponse<TValue, TSection, InferError<TExternalProps>>;
176
176
  export {};
@@ -25,13 +25,12 @@ export const usePickerValue = ({
25
25
  } = props;
26
26
  const utils = useUtils();
27
27
  const adapter = useLocalizationContext();
28
- const [rawValue, setValue] = useControlled({
28
+ const [value, setValue] = useControlled({
29
29
  controlled: inValue,
30
30
  default: defaultValue != null ? defaultValue : valueManager.emptyValue,
31
31
  name: 'usePickerValue',
32
32
  state: 'value'
33
33
  });
34
- const value = React.useMemo(() => valueManager.cleanValue(utils, rawValue), [valueManager, utils, rawValue]);
35
34
  const [selectedSections, setSelectedSections] = useControlled({
36
35
  controlled: selectedSectionsProp,
37
36
  default: null,
@@ -81,7 +80,7 @@ export const usePickerValue = ({
81
80
  }
82
81
  }
83
82
  });
84
- if (params.forceOnChangeCall || !params.skipOnChangeCall && !valueManager.areValuesEqual(utils, dateState.committed, params.value)) {
83
+ if (!params.skipOnChangeCall && !valueManager.areValuesEqual(utils, dateState.committed, params.value)) {
85
84
  setValue(params.value);
86
85
  if (onChange) {
87
86
  const context = {
@@ -126,18 +125,14 @@ export const usePickerValue = ({
126
125
  // Reset all date in state to the empty value and close picker.
127
126
  setDate({
128
127
  value: valueManager.emptyValue,
129
- action: 'acceptAndClose',
130
- // force `onChange` in cases like input (value) === `Invalid date`
131
- forceOnChangeCall: !valueManager.areValuesEqual(utils, value, valueManager.emptyValue)
128
+ action: 'acceptAndClose'
132
129
  });
133
130
  });
134
131
  const handleAccept = useEventCallback(() => {
135
132
  // Set all date in state to equal the current draft value and close picker.
136
133
  setDate({
137
134
  value: dateState.draft,
138
- action: 'acceptAndClose',
139
- // force `onChange` in cases like input (value) === `Invalid date`
140
- forceOnChangeCall: !valueManager.areValuesEqual(utils, dateState.committed, dateState.draft)
135
+ action: 'acceptAndClose'
141
136
  });
142
137
  });
143
138
  const handleDismiss = useEventCallback(() => {
@@ -230,8 +225,9 @@ export const usePickerValue = ({
230
225
  selectedSections,
231
226
  onSelectedSectionsChange: handleFieldSelectedSectionsChange
232
227
  };
228
+ const viewValue = React.useMemo(() => valueManager.cleanValue(utils, dateState.draft), [utils, valueManager, dateState.draft]);
233
229
  const viewResponse = {
234
- value: dateState.draft,
230
+ value: viewValue,
235
231
  onChange: handleChange,
236
232
  onClose: handleClose,
237
233
  open: isOpen,
@@ -248,7 +244,7 @@ export const usePickerValue = ({
248
244
  return Array.isArray(testedValue) ? validationResponse.every(v => v === null) : validationResponse === null;
249
245
  };
250
246
  const layoutResponse = _extends({}, actions, {
251
- value: dateState.draft,
247
+ value: viewValue,
252
248
  onChange: handleChangeAndCommit,
253
249
  isValid
254
250
  });
@@ -5,6 +5,7 @@ import { BasePickerProps } from '../../models/props/basePickerProps';
5
5
  import { UncapitalizeObjectKeys } from '../../utils/slots-migration';
6
6
  import { UsePickerParams } from '../usePicker';
7
7
  import { UsePickerViewsProps } from '../usePicker/usePickerViews';
8
+ import { FieldSection } from '../useField';
8
9
  export interface UseStaticPickerSlotsComponent<TDate, TView extends DateOrTimeView> extends ExportedPickersLayoutSlotsComponent<TDate | null, TDate, TView> {
9
10
  }
10
11
  export interface UseStaticPickerSlotsComponentsProps<TDate, TView extends DateOrTimeView> extends ExportedPickersLayoutSlotsComponentsProps<TDate | null, TDate, TView> {
@@ -50,7 +51,7 @@ export interface UseStaticPickerProps<TDate, TView extends DateOrTimeView, TErro
50
51
  */
51
52
  slotProps?: UseStaticPickerSlotsComponentsProps<TDate, TView>;
52
53
  }
53
- export interface UseStaticPickerParams<TDate, TView extends DateOrTimeView, TExternalProps extends UseStaticPickerProps<TDate, TView, any, TExternalProps>> extends Pick<UsePickerParams<TDate | null, TDate, TView, TExternalProps, {}>, 'valueManager' | 'validator'> {
54
+ export interface UseStaticPickerParams<TDate, TView extends DateOrTimeView, TExternalProps extends UseStaticPickerProps<TDate, TView, any, TExternalProps>> extends Pick<UsePickerParams<TDate | null, TDate, TView, FieldSection, TExternalProps, {}>, 'valueManager' | 'validator'> {
54
55
  props: TExternalProps;
55
56
  /**
56
57
  * Ref to pass to the root element
@@ -22,7 +22,7 @@ export type { PickersPopperClassKey, PickersPopperClasses, } from './components/
22
22
  export { PickersToolbarButton } from './components/PickersToolbarButton';
23
23
  export { DAY_MARGIN, DIALOG_WIDTH } from './constants/dimensions';
24
24
  export type { DesktopOnlyPickerProps } from './hooks/useDesktopPicker';
25
- export { useField, createDateStrForInputFromSections, addPositionPropertiesToSections, splitFormatIntoSections, getSectionOrder, } from './hooks/useField';
25
+ export { useField, createDateStrForInputFromSections, addPositionPropertiesToSections, splitFormatIntoSections, } from './hooks/useField';
26
26
  export type { UseFieldInternalProps, UseFieldParams, UseFieldResponse, UseFieldForwardedProps, FieldValueManager, FieldSection, FieldChangeHandler, FieldChangeHandlerContext, } from './hooks/useField';
27
27
  export type { MobileOnlyPickerProps } from './hooks/useMobilePicker';
28
28
  export { usePicker } from './hooks/usePicker';
@@ -50,7 +50,7 @@ export type { MuiPickersAdapter } from './models/muiPickersAdapter';
50
50
  export type { DefaultizedProps, MakeOptional } from './models/helpers';
51
51
  export type { DateOrTimeView, DateView, TimeView } from './models/views';
52
52
  export type { WrapperVariant } from './models/common';
53
- export { applyDefaultDate, replaceInvalidDateByNull } from './utils/date-utils';
53
+ export { applyDefaultDate, replaceInvalidDateByNull, areDatesEqual } from './utils/date-utils';
54
54
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, DEFAULT_DESKTOP_MODE_MEDIA_QUERY, } from './utils/utils';
55
55
  export { defaultReduceAnimations } from './utils/defaultReduceAnimations';
56
56
  export { extractValidationProps } from './utils/validation';
@@ -9,7 +9,7 @@ export { pickersArrowSwitcherClasses } from './components/PickersArrowSwitcher/p
9
9
  export { pickersPopperClasses } from './components/pickersPopperClasses';
10
10
  export { PickersToolbarButton } from './components/PickersToolbarButton';
11
11
  export { DAY_MARGIN, DIALOG_WIDTH } from './constants/dimensions';
12
- export { useField, createDateStrForInputFromSections, addPositionPropertiesToSections, splitFormatIntoSections, getSectionOrder } from './hooks/useField';
12
+ export { useField, createDateStrForInputFromSections, addPositionPropertiesToSections, splitFormatIntoSections } from './hooks/useField';
13
13
  export { usePicker } from './hooks/usePicker';
14
14
  export { useStaticPicker } from './hooks/useStaticPicker';
15
15
  export { useLocalizationContext, useDefaultDates, useUtils, useLocaleText, useNow } from './hooks/useUtils';
@@ -18,7 +18,7 @@ export { validateDate } from './hooks/validation/useDateValidation';
18
18
  export { validateTime } from './hooks/validation/useTimeValidation';
19
19
  export { validateDateTime } from './hooks/validation/useDateTimeValidation';
20
20
  export { usePreviousMonthDisabled, useNextMonthDisabled } from './hooks/date-helpers-hooks';
21
- export { applyDefaultDate, replaceInvalidDateByNull } from './utils/date-utils';
21
+ export { applyDefaultDate, replaceInvalidDateByNull, areDatesEqual } from './utils/date-utils';
22
22
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './utils/utils';
23
23
  export { defaultReduceAnimations } from './utils/defaultReduceAnimations';
24
24
  export { extractValidationProps } from './utils/validation';
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { TextFieldProps } from '@mui/material/TextField';
3
- import type { UseFieldInternalProps } from '../hooks/useField';
4
- export interface BaseFieldProps<TValue, TError> extends Omit<UseFieldInternalProps<TValue, TError>, 'format'> {
3
+ import type { FieldSection, UseFieldInternalProps } from '../hooks/useField';
4
+ export interface BaseFieldProps<TValue, TSection extends FieldSection, TError> extends Omit<UseFieldInternalProps<TValue, TSection, TError>, 'format'> {
5
5
  className?: string;
6
6
  format?: string;
7
7
  disabled?: boolean;
@@ -12,7 +12,7 @@ export interface BaseFieldProps<TValue, TError> extends Omit<UseFieldInternalPro
12
12
  * Props the single input field can receive when used inside a picker.
13
13
  * Only contains what the MUI component are passing to the field, not what users can pass using the `props.slotProps.field`.
14
14
  */
15
- export interface BaseSingleInputFieldProps<TValue, TError> extends BaseFieldProps<TValue, TError> {
15
+ export interface BaseSingleInputFieldProps<TValue, TSection extends FieldSection, TError> extends BaseFieldProps<TValue, TSection, TError> {
16
16
  label?: React.ReactNode;
17
17
  id?: string;
18
18
  InputProps?: {
@@ -12,4 +12,5 @@ export declare const findClosestEnabledDate: <TDate>({ date, disableFuture, disa
12
12
  export declare const clamp: <TDate>(utils: MuiPickersAdapter<TDate>, value: TDate, minDate: TDate, maxDate: TDate) => TDate;
13
13
  export declare const replaceInvalidDateByNull: <TDate>(utils: MuiPickersAdapter<TDate>, value: TDate | null) => NonNullable<TDate> | null;
14
14
  export declare const applyDefaultDate: <TDate>(utils: MuiPickersAdapter<TDate>, value: TDate | null | undefined, defaultValue: TDate) => TDate;
15
+ export declare const areDatesEqual: <TDate>(utils: MuiPickersAdapter<TDate>, a: TDate, b: TDate) => boolean;
15
16
  export {};
@@ -63,4 +63,10 @@ export const applyDefaultDate = (utils, value, defaultValue) => {
63
63
  return defaultValue;
64
64
  }
65
65
  return value;
66
+ };
67
+ export const areDatesEqual = (utils, a, b) => {
68
+ if (!utils.isValid(a) && a != null && !utils.isValid(b) && b != null) {
69
+ return true;
70
+ }
71
+ return utils.isEqual(a, b);
66
72
  };
@@ -1,10 +1,10 @@
1
- import { replaceInvalidDateByNull } from './date-utils';
2
- import { addPositionPropertiesToSections, createDateStrForInputFromSections, splitFormatIntoSections, getSectionOrder } from '../hooks/useField/useField.utils';
1
+ import { areDatesEqual, replaceInvalidDateByNull } from './date-utils';
2
+ import { addPositionPropertiesToSections, createDateStrForInputFromSections, splitFormatIntoSections } from '../hooks/useField/useField.utils';
3
3
  export const singleItemValueManager = {
4
4
  emptyValue: null,
5
5
  getTodayValue: utils => utils.date(),
6
6
  cleanValue: replaceInvalidDateByNull,
7
- areValuesEqual: (utils, a, b) => utils.isEqual(a, b),
7
+ areValuesEqual: areDatesEqual,
8
8
  isSameError: (a, b) => a === b,
9
9
  defaultErrorState: null
10
10
  };
@@ -28,6 +28,5 @@ export const singleItemFieldValueManager = {
28
28
  })
29
29
  }),
30
30
  parseValueStr: (valueStr, referenceValue, parseDate) => parseDate(valueStr.trim(), referenceValue),
31
- hasError: error => error != null,
32
- getSectionOrder: (utils, localeText, format, isRTL) => getSectionOrder(splitFormatIntoSections(utils, localeText, format, null), isRTL)
31
+ hasError: error => error != null
33
32
  };
@@ -150,6 +150,7 @@ export var AdapterDateFns = /*#__PURE__*/function (_BaseAdapterDateFns) {
150
150
  return token;
151
151
  }).join('');
152
152
  };
153
+ // Redefined here just to show how it can be written using expandFormat
153
154
  _this.getFormatHelperText = function (format) {
154
155
  return _this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
155
156
  };
@@ -82,6 +82,7 @@ export var AdapterDateFnsJalali = /*#__PURE__*/function (_BaseAdapterDateFnsJa)
82
82
  return token;
83
83
  }).join('');
84
84
  };
85
+ // Redefined here just to show how it can be written using expandFormat
85
86
  _this.getFormatHelperText = function (format) {
86
87
  return _this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
87
88
  };
@@ -87,6 +87,10 @@ export var AdapterDayjs = /*#__PURE__*/function (_BaseAdapterDayjs) {
87
87
  /* istanbul ignore next */
88
88
  return /A|a/.test(_this.getLocaleFormats().LT || '');
89
89
  };
90
+ /**
91
+ * The current getFormatHelperText method uses an outdated format parsing logic.
92
+ * We should use this one in the future to support all localized formats.
93
+ */
90
94
  _this.expandFormat = function (format) {
91
95
  var localeFormats = _this.getLocaleFormats();
92
96
 
@@ -101,6 +105,7 @@ export var AdapterDayjs = /*#__PURE__*/function (_BaseAdapterDayjs) {
101
105
  return a || localeFormats[b] || t(localeFormats[B]);
102
106
  });
103
107
  };
108
+ // Redefined here just to show how it can be written using expandFormat
104
109
  _this.getFormatHelperText = function (format) {
105
110
  return _this.expandFormat(format).replace(/a/gi, '(a|p)m').toLocaleLowerCase();
106
111
  };
@@ -105,6 +105,7 @@ export var AdapterLuxon = /*#__PURE__*/function (_BaseAdapterLuxon) {
105
105
  locale: _this.locale
106
106
  }).replace('yyyyy', 'yyyy');
107
107
  };
108
+ // Redefined here just to show how it can be written using expandFormat
108
109
  _this.getFormatHelperText = function (format) {
109
110
  return _this.expandFormat(format).replace(/(a)/g, '(a|p)m').toLocaleLowerCase();
110
111
  };