@mui/x-date-pickers 7.0.0-beta.7 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/AdapterDateFns/AdapterDateFns.js +1 -1
  2. package/AdapterDateFnsBase/AdapterDateFnsBase.js +1 -2
  3. package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +2 -4
  4. package/AdapterDateFnsV3/AdapterDateFnsV3.js +1 -1
  5. package/AdapterDayjs/AdapterDayjs.js +2 -4
  6. package/AdapterLuxon/AdapterLuxon.js +12 -9
  7. package/AdapterMoment/AdapterMoment.js +5 -6
  8. package/CHANGELOG.md +195 -12
  9. package/DateCalendar/DateCalendar.js +14 -16
  10. package/DateCalendar/DayCalendar.js +5 -6
  11. package/DateField/DateField.js +3 -4
  12. package/DatePicker/DatePicker.js +1 -1
  13. package/DatePicker/shared.d.ts +2 -1
  14. package/DatePicker/shared.js +3 -5
  15. package/DateTimeField/DateTimeField.js +3 -4
  16. package/DateTimePicker/DateTimePicker.js +1 -1
  17. package/DateTimePicker/DateTimePickerToolbar.js +1 -1
  18. package/DateTimePicker/shared.d.ts +2 -1
  19. package/DateTimePicker/shared.js +11 -13
  20. package/DesktopDatePicker/DesktopDatePicker.js +7 -11
  21. package/DesktopDateTimePicker/DesktopDateTimePicker.js +72 -37
  22. package/DesktopDateTimePicker/DesktopDateTimePickerLayout.d.ts +12 -0
  23. package/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +101 -0
  24. package/DesktopDateTimePicker/index.d.ts +1 -0
  25. package/DesktopDateTimePicker/index.js +2 -1
  26. package/DesktopTimePicker/DesktopTimePicker.js +8 -12
  27. package/DigitalClock/DigitalClock.js +2 -3
  28. package/LocalizationProvider/LocalizationProvider.js +1 -2
  29. package/MobileDatePicker/MobileDatePicker.js +6 -10
  30. package/MobileDateTimePicker/MobileDateTimePicker.js +8 -12
  31. package/MobileTimePicker/MobileTimePicker.js +6 -10
  32. package/MonthCalendar/MonthCalendar.js +4 -4
  33. package/MonthCalendar/PickersMonth.js +1 -2
  34. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -1
  35. package/MultiSectionDigitalClock/MultiSectionDigitalClock.utils.js +1 -1
  36. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +3 -5
  37. package/PickersActionBar/PickersActionBar.js +1 -1
  38. package/PickersCalendarHeader/PickersCalendarHeader.js +4 -5
  39. package/PickersLayout/usePickerLayout.js +8 -9
  40. package/PickersSectionList/PickersSectionList.js +9 -11
  41. package/PickersTextField/PickersFilledInput/PickersFilledInput.js +2 -3
  42. package/PickersTextField/PickersInput/PickersInput.js +1 -1
  43. package/PickersTextField/PickersInputBase/PickersInputBase.js +4 -5
  44. package/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +2 -2
  45. package/README.md +1 -1
  46. package/StaticDatePicker/StaticDatePicker.js +4 -5
  47. package/StaticDateTimePicker/StaticDateTimePicker.js +6 -7
  48. package/StaticTimePicker/StaticTimePicker.js +3 -4
  49. package/TimeClock/TimeClock.js +1 -1
  50. package/TimeField/TimeField.js +2 -3
  51. package/TimePicker/shared.d.ts +2 -1
  52. package/TimePicker/shared.js +5 -7
  53. package/YearCalendar/YearCalendar.js +5 -6
  54. package/hooks/useClearableField.js +6 -7
  55. package/index.js +1 -1
  56. package/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.js +8 -9
  57. package/internals/components/PickersModalDialog.js +6 -7
  58. package/internals/components/PickersPopper.js +13 -16
  59. package/internals/components/PickersToolbar.js +9 -12
  60. package/internals/hooks/date-helpers-hooks.js +1 -1
  61. package/internals/hooks/defaultizedFieldProps.js +15 -18
  62. package/internals/hooks/useClockReferenceDate.js +1 -1
  63. package/internals/hooks/useDesktopPicker/index.d.ts +1 -1
  64. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +11 -12
  65. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +2 -2
  66. package/internals/hooks/useField/buildSectionsFromFormat.js +35 -31
  67. package/internals/hooks/useField/useField.js +2 -2
  68. package/internals/hooks/useField/useField.utils.js +4 -7
  69. package/internals/hooks/useField/useFieldCharacterEditing.js +1 -2
  70. package/internals/hooks/useField/useFieldState.js +1 -1
  71. package/internals/hooks/useField/useFieldV6TextField.js +9 -15
  72. package/internals/hooks/useField/useFieldV7TextField.js +9 -11
  73. package/internals/hooks/useMobilePicker/useMobilePicker.js +7 -8
  74. package/internals/hooks/useOpenState.js +1 -1
  75. package/internals/hooks/usePicker/index.d.ts +1 -0
  76. package/internals/hooks/usePicker/usePickerViews.d.ts +4 -2
  77. package/internals/hooks/usePicker/usePickerViews.js +1 -2
  78. package/internals/hooks/useStaticPicker/useStaticPicker.js +13 -17
  79. package/internals/hooks/useValueWithTimezone.js +5 -6
  80. package/internals/hooks/useViews.js +3 -4
  81. package/internals/index.d.ts +1 -1
  82. package/internals/models/validation.d.ts +1 -1
  83. package/internals/utils/convertFieldResponseIntoMuiTextFieldProps.js +3 -3
  84. package/internals/utils/date-time-utils.js +2 -5
  85. package/internals/utils/fields.js +1 -1
  86. package/internals/utils/getDefaultReferenceDate.js +2 -6
  87. package/internals/utils/views.js +1 -1
  88. package/locales/csCZ.js +1 -4
  89. package/locales/daDK.js +1 -4
  90. package/locales/deDE.js +1 -4
  91. package/locales/huHU.js +1 -4
  92. package/locales/jaJP.js +1 -4
  93. package/locales/roRO.js +1 -4
  94. package/locales/skSK.js +1 -4
  95. package/modern/AdapterLuxon/AdapterLuxon.js +9 -4
  96. package/modern/DateCalendar/DateCalendar.js +1 -1
  97. package/modern/DateField/DateField.js +1 -1
  98. package/modern/DatePicker/DatePicker.js +1 -1
  99. package/modern/DateTimeField/DateTimeField.js +1 -1
  100. package/modern/DateTimePicker/DateTimePicker.js +1 -1
  101. package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -1
  102. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +64 -25
  103. package/modern/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +101 -0
  104. package/modern/DesktopDateTimePicker/index.js +2 -1
  105. package/modern/MobileDatePicker/MobileDatePicker.js +1 -1
  106. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  107. package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
  108. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  109. package/modern/index.js +1 -1
  110. package/modern/internals/components/PickersPopper.js +1 -1
  111. package/modern/internals/hooks/useField/buildSectionsFromFormat.js +34 -30
  112. package/modern/internals/hooks/useField/useFieldV7TextField.js +1 -1
  113. package/modern/internals/hooks/useOpenState.js +1 -1
  114. package/modern/internals/utils/fields.js +1 -1
  115. package/node/AdapterLuxon/AdapterLuxon.js +9 -4
  116. package/node/DateCalendar/DateCalendar.js +1 -1
  117. package/node/DateField/DateField.js +1 -1
  118. package/node/DatePicker/DatePicker.js +1 -1
  119. package/node/DateTimeField/DateTimeField.js +1 -1
  120. package/node/DateTimePicker/DateTimePicker.js +1 -1
  121. package/node/DesktopDatePicker/DesktopDatePicker.js +1 -1
  122. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +63 -25
  123. package/node/DesktopDateTimePicker/DesktopDateTimePickerLayout.js +108 -0
  124. package/node/DesktopDateTimePicker/index.js +8 -1
  125. package/node/MobileDatePicker/MobileDatePicker.js +1 -1
  126. package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
  127. package/node/StaticDatePicker/StaticDatePicker.js +1 -1
  128. package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  129. package/node/index.js +1 -1
  130. package/node/internals/components/PickersPopper.js +1 -1
  131. package/node/internals/hooks/useField/buildSectionsFromFormat.js +34 -30
  132. package/node/internals/hooks/useField/useFieldV7TextField.js +1 -1
  133. package/node/internals/hooks/useOpenState.js +1 -1
  134. package/node/internals/utils/fields.js +1 -1
  135. package/package.json +5 -5
  136. package/timeViewRenderers/timeViewRenderers.js +1 -1
  137. package/dateTimeViewRenderers/dateTimeViewRenderers.d.ts +0 -15
  138. package/dateTimeViewRenderers/dateTimeViewRenderers.js +0 -163
  139. package/dateTimeViewRenderers/index.d.ts +0 -2
  140. package/dateTimeViewRenderers/index.js +0 -1
  141. package/dateTimeViewRenderers/package.json +0 -6
  142. package/modern/dateTimeViewRenderers/dateTimeViewRenderers.js +0 -162
  143. package/modern/dateTimeViewRenderers/index.js +0 -1
  144. package/node/dateTimeViewRenderers/dateTimeViewRenderers.js +0 -171
  145. package/node/dateTimeViewRenderers/index.js +0 -12
@@ -152,49 +152,53 @@ const buildSections = params => {
152
152
  const sections = [];
153
153
  let startSeparator = '';
154
154
 
155
- // This RegExp test if the beginning of a string corresponds to a supported token
156
- const isTokenStartRegExp = new RegExp(`^(${Object.keys(utils.formatTokenMap).sort((a, b) => b.length - a.length) // Sort to put longest word first
157
- .join('|')})`, 'g') // used to get access to lastIndex state
158
- ;
159
- let currentTokenValue = '';
160
- for (let i = 0; i < expandedFormat.length; i += 1) {
161
- const escapedPartOfCurrentChar = escapedParts.find(escapeIndex => escapeIndex.start <= i && escapeIndex.end >= i);
162
- const char = expandedFormat[i];
155
+ // This RegExp tests if the beginning of a string corresponds to a supported token
156
+ const validTokens = Object.keys(utils.formatTokenMap).sort((a, b) => b.length - a.length); // Sort to put longest word first
157
+
158
+ const regExpFirstWordInFormat = /^([a-zA-Z]+)/;
159
+ const regExpWordOnlyComposedOfTokens = new RegExp(`^(${validTokens.join('|')})*$`);
160
+ const regExpFirstTokenInWord = new RegExp(`^(${validTokens.join('|')})`);
161
+ const getEscapedPartOfCurrentChar = i => escapedParts.find(escapeIndex => escapeIndex.start <= i && escapeIndex.end >= i);
162
+ let i = 0;
163
+ while (i < expandedFormat.length) {
164
+ const escapedPartOfCurrentChar = getEscapedPartOfCurrentChar(i);
163
165
  const isEscapedChar = escapedPartOfCurrentChar != null;
164
- const potentialToken = `${currentTokenValue}${expandedFormat.slice(i)}`;
165
- const regExpMatch = isTokenStartRegExp.test(potentialToken);
166
- if (!isEscapedChar && char.match(/([A-Za-z]+)/) && regExpMatch) {
167
- currentTokenValue = potentialToken.slice(0, isTokenStartRegExp.lastIndex);
168
- i += isTokenStartRegExp.lastIndex - 1;
169
- } else {
166
+ const firstWordInFormat = regExpFirstWordInFormat.exec(expandedFormat.slice(i))?.[1];
167
+
168
+ // The first word in the format is only composed of tokens.
169
+ // We extract those tokens to create a new sections.
170
+ if (!isEscapedChar && firstWordInFormat != null && regExpWordOnlyComposedOfTokens.test(firstWordInFormat)) {
171
+ let word = firstWordInFormat;
172
+ while (word.length > 0) {
173
+ const firstWord = regExpFirstTokenInWord.exec(word)[1];
174
+ word = word.slice(firstWord.length);
175
+ sections.push(createSection(_extends({}, params, {
176
+ now,
177
+ token: firstWord,
178
+ startSeparator
179
+ })));
180
+ startSeparator = '';
181
+ }
182
+ i += firstWordInFormat.length;
183
+ }
184
+ // The remaining format does not start with a token,
185
+ // We take the first character and add it to the current section's end separator.
186
+ else {
187
+ const char = expandedFormat[i];
188
+
170
189
  // If we are on the opening or closing character of an escaped part of the format,
171
190
  // Then we ignore this character.
172
- const isEscapeBoundary = isEscapedChar && (escapedPartOfCurrentChar == null ? void 0 : escapedPartOfCurrentChar.start) === i || (escapedPartOfCurrentChar == null ? void 0 : escapedPartOfCurrentChar.end) === i;
191
+ const isEscapeBoundary = isEscapedChar && escapedPartOfCurrentChar?.start === i || escapedPartOfCurrentChar?.end === i;
173
192
  if (!isEscapeBoundary) {
174
- if (currentTokenValue !== '') {
175
- sections.push(createSection(_extends({}, params, {
176
- now,
177
- token: currentTokenValue,
178
- startSeparator
179
- })));
180
- currentTokenValue = '';
181
- }
182
193
  if (sections.length === 0) {
183
194
  startSeparator += char;
184
195
  } else {
185
- startSeparator = '';
186
196
  sections[sections.length - 1].endSeparator += char;
187
197
  }
188
198
  }
199
+ i += 1;
189
200
  }
190
201
  }
191
- if (currentTokenValue !== '') {
192
- sections.push(createSection(_extends({}, params, {
193
- now,
194
- token: currentTokenValue,
195
- startSeparator
196
- })));
197
- }
198
202
  if (sections.length === 0 && startSeparator.length > 0) {
199
203
  sections.push({
200
204
  type: 'empty',
@@ -69,7 +69,7 @@ export const useField = params => {
69
69
  sectionOrder
70
70
  }));
71
71
  const handleContainerKeyDown = useEventCallback(event => {
72
- onKeyDown == null || onKeyDown(event);
72
+ onKeyDown?.(event);
73
73
 
74
74
  // eslint-disable-next-line default-case
75
75
  switch (true) {
@@ -200,7 +200,7 @@ export const useField = params => {
200
200
  }));
201
201
  const handleClearValue = useEventCallback((event, ...args) => {
202
202
  event.preventDefault();
203
- onClear == null || onClear(event, ...args);
203
+ onClear?.(event, ...args);
204
204
  clearValue();
205
205
  setSelectedSections(sectionOrder.startIndex);
206
206
  if (!interactions.isFieldFocused) {
@@ -154,7 +154,7 @@ export const adjustSectionValue = (utils, timezone, section, keyCode, sectionsVa
154
154
  contentType: section.contentType
155
155
  });
156
156
  const getCleanValue = value => cleanDigitSectionValue(utils, value, sectionBoundaries, localizedDigits, section);
157
- const step = section.type === 'minutes' && stepsAttributes != null && stepsAttributes.minutesStep ? stepsAttributes.minutesStep : 1;
157
+ const step = section.type === 'minutes' && stepsAttributes?.minutesStep ? stepsAttributes.minutesStep : 1;
158
158
  const currentSectionValue = parseInt(removeLocalizedDigits(section.value, localizedDigits), 10);
159
159
  let newSectionValueNumber = currentSectionValue + delta * step;
160
160
  if (shouldSetAbsolute) {
@@ -533,12 +533,9 @@ export const getSectionOrder = (sections, shouldApplyRTL) => {
533
533
  while (RTLIndex >= 0) {
534
534
  groupedSectionsEnd = sections.findIndex(
535
535
  // eslint-disable-next-line @typescript-eslint/no-loop-func
536
- (section, index) => {
537
- var _section$endSeparator;
538
- return index >= groupedSectionsStart && ((_section$endSeparator = section.endSeparator) == null ? void 0 : _section$endSeparator.includes(' ')) &&
539
- // Special case where the spaces were not there in the initial input
540
- section.endSeparator !== ' / ';
541
- });
536
+ (section, index) => index >= groupedSectionsStart && section.endSeparator?.includes(' ') &&
537
+ // Special case where the spaces were not there in the initial input
538
+ section.endSeparator !== ' / ');
542
539
  if (groupedSectionsEnd === -1) {
543
540
  groupedSectionsEnd = sections.length - 1;
544
541
  }
@@ -48,8 +48,7 @@ export const useFieldCharacterEditing = ({
48
48
  const [query, setQuery] = React.useState(null);
49
49
  const resetQuery = useEventCallback(() => setQuery(null));
50
50
  React.useEffect(() => {
51
- var _sections$query$secti;
52
- if (query != null && ((_sections$query$secti = sections[query.sectionIndex]) == null ? void 0 : _sections$query$secti.type) !== query.sectionType) {
51
+ if (query != null && sections[query.sectionIndex]?.type !== query.sectionType) {
53
52
  resetQuery();
54
53
  }
55
54
  }, [sections, query, resetQuery]);
@@ -88,7 +88,7 @@ export const useFieldState = params => {
88
88
  });
89
89
  const setSelectedSections = newSelectedSections => {
90
90
  innerSetSelectedSections(newSelectedSections);
91
- onSelectedSectionsChange == null || onSelectedSectionsChange(newSelectedSections);
91
+ onSelectedSectionsChange?.(newSelectedSections);
92
92
  };
93
93
  const parsedSelectedSections = React.useMemo(() => parseSelectedSections(selectedSections, state.sections), [selectedSections, state.sections]);
94
94
  const activeSectionIndex = parsedSelectedSections === 'all' ? 0 : parsedSelectedSections;
@@ -109,9 +109,8 @@ export const useFieldV6TextField = params => {
109
109
  inputRef.current.scrollTop = currentScrollTop;
110
110
  },
111
111
  getActiveSectionIndexFromDOM: () => {
112
- var _selectionStart, _selectionEnd;
113
- const browserStartIndex = (_selectionStart = inputRef.current.selectionStart) != null ? _selectionStart : 0;
114
- const browserEndIndex = (_selectionEnd = inputRef.current.selectionEnd) != null ? _selectionEnd : 0;
112
+ const browserStartIndex = inputRef.current.selectionStart ?? 0;
113
+ const browserEndIndex = inputRef.current.selectionEnd ?? 0;
115
114
  if (browserStartIndex === 0 && browserEndIndex === 0) {
116
115
  return null;
117
116
  }
@@ -120,20 +119,18 @@ export const useFieldV6TextField = params => {
120
119
  return nextSectionIndex === -1 ? sections.length - 1 : nextSectionIndex - 1;
121
120
  },
122
121
  focusField: (newSelectedSection = 0) => {
123
- var _inputRef$current;
124
- (_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
122
+ inputRef.current?.focus();
125
123
  setSelectedSections(newSelectedSection);
126
124
  },
127
125
  setSelectedSections: newSelectedSections => setSelectedSections(newSelectedSections),
128
126
  isFieldFocused: () => inputRef.current === getActiveElement(document)
129
127
  }), [inputRef, parsedSelectedSections, sections, setSelectedSections]);
130
128
  const syncSelectionFromDOM = () => {
131
- var _selectionStart2;
132
129
  if (readOnly) {
133
130
  setSelectedSections(null);
134
131
  return;
135
132
  }
136
- const browserStartIndex = (_selectionStart2 = inputRef.current.selectionStart) != null ? _selectionStart2 : 0;
133
+ const browserStartIndex = inputRef.current.selectionStart ?? 0;
137
134
  let nextSectionIndex;
138
135
  if (browserStartIndex <= sections[0].startInInput) {
139
136
  // Special case if browser index is in invisible characters at the beginning
@@ -148,7 +145,7 @@ export const useFieldV6TextField = params => {
148
145
  setSelectedSections(sectionIndex);
149
146
  };
150
147
  const handleInputFocus = useEventCallback((...args) => {
151
- onFocus == null || onFocus(...args);
148
+ onFocus?.(...args);
152
149
  // The ref is guaranteed to be resolved at this point.
153
150
  const input = inputRef.current;
154
151
  clearTimeout(focusTimeoutRef.current);
@@ -175,11 +172,11 @@ export const useFieldV6TextField = params => {
175
172
  if (event.isDefaultPrevented()) {
176
173
  return;
177
174
  }
178
- onClick == null || onClick(event, ...args);
175
+ onClick?.(event, ...args);
179
176
  syncSelectionFromDOM();
180
177
  });
181
178
  const handleInputPaste = useEventCallback(event => {
182
- onPaste == null || onPaste(event);
179
+ onPaste?.(event);
183
180
 
184
181
  // prevent default to avoid the input `onChange` handler being called
185
182
  event.preventDefault();
@@ -212,7 +209,7 @@ export const useFieldV6TextField = params => {
212
209
  updateValueFromValueStr(pastedValue);
213
210
  });
214
211
  const handleContainerBlur = useEventCallback((...args) => {
215
- onBlur == null || onBlur(...args);
212
+ onBlur?.(...args);
216
213
  setSelectedSections(null);
217
214
  });
218
215
  const handleInputChange = useEventCallback(event => {
@@ -279,10 +276,7 @@ export const useFieldV6TextField = params => {
279
276
  });
280
277
  });
281
278
  const placeholder = React.useMemo(() => fieldValueManager.getV6InputValueFromSections(getSectionsFromValue(valueManager.emptyValue), localizedDigits, isRTL), [fieldValueManager, getSectionsFromValue, valueManager.emptyValue, localizedDigits, isRTL]);
282
- const valueStr = React.useMemo(() => {
283
- var _state$tempValueStrAn;
284
- return (_state$tempValueStrAn = state.tempValueStrAndroid) != null ? _state$tempValueStrAn : fieldValueManager.getV6InputValueFromSections(state.sections, localizedDigits, isRTL);
285
- }, [state.sections, fieldValueManager, state.tempValueStrAndroid, localizedDigits, isRTL]);
279
+ const valueStr = React.useMemo(() => state.tempValueStrAndroid ?? fieldValueManager.getV6InputValueFromSections(state.sections, localizedDigits, isRTL), [state.sections, fieldValueManager, state.tempValueStrAndroid, localizedDigits, isRTL]);
286
280
  React.useEffect(() => {
287
281
  // Select all the sections when focused on mount (`autoFocus = true` on the input)
288
282
  if (inputRef.current && inputRef.current === getActiveElement(document)) {
@@ -132,7 +132,7 @@ export const useFieldV7TextField = params => {
132
132
  return;
133
133
  }
134
134
  setFocused(true);
135
- onClick == null || onClick(event, ...args);
135
+ onClick?.(event, ...args);
136
136
  if (parsedSelectedSections === 'all') {
137
137
  setTimeout(() => {
138
138
  const cursorPosition = document.getSelection().getRangeAt(0).startOffset;
@@ -160,13 +160,12 @@ export const useFieldV7TextField = params => {
160
160
  }
161
161
  });
162
162
  const handleContainerInput = useEventCallback(event => {
163
- var _target$textContent;
164
- onInput == null || onInput(event);
163
+ onInput?.(event);
165
164
  if (!sectionListRef.current || parsedSelectedSections !== 'all') {
166
165
  return;
167
166
  }
168
167
  const target = event.target;
169
- const keyPressed = (_target$textContent = target.textContent) != null ? _target$textContent : '';
168
+ const keyPressed = target.textContent ?? '';
170
169
  sectionListRef.current.getRoot().innerHTML = state.sections.map(section => `${section.startSeparator}${section.value || section.placeholder}${section.endSeparator}`).join('');
171
170
  interactions.syncSelectionToDOM();
172
171
  if (keyPressed.length === 0 || keyPressed.charCodeAt(0) === 10) {
@@ -183,7 +182,7 @@ export const useFieldV7TextField = params => {
183
182
  }
184
183
  });
185
184
  const handleContainerPaste = useEventCallback(event => {
186
- onPaste == null || onPaste(event);
185
+ onPaste?.(event);
187
186
  if (readOnly || parsedSelectedSections !== 'all') {
188
187
  event.preventDefault();
189
188
  return;
@@ -194,7 +193,7 @@ export const useFieldV7TextField = params => {
194
193
  updateValueFromValueStr(pastedValue);
195
194
  });
196
195
  const handleContainerFocus = useEventCallback((...args) => {
197
- onFocus == null || onFocus(...args);
196
+ onFocus?.(...args);
198
197
  if (focused || !sectionListRef.current) {
199
198
  return;
200
199
  }
@@ -205,7 +204,7 @@ export const useFieldV7TextField = params => {
205
204
  }
206
205
  });
207
206
  const handleContainerBlur = useEventCallback((...args) => {
208
- onBlur == null || onBlur(...args);
207
+ onBlur?.(...args);
209
208
  setTimeout(() => {
210
209
  if (!sectionListRef.current) {
211
210
  return;
@@ -267,12 +266,11 @@ export const useFieldV7TextField = params => {
267
266
  event.dataTransfer.dropEffect = 'none';
268
267
  });
269
268
  const handleInputContentInput = useEventCallback(event => {
270
- var _target$textContent2;
271
269
  if (!sectionListRef.current) {
272
270
  return;
273
271
  }
274
272
  const target = event.target;
275
- const keyPressed = (_target$textContent2 = target.textContent) != null ? _target$textContent2 : '';
273
+ const keyPressed = target.textContent ?? '';
276
274
  const sectionIndex = sectionListRef.current.getSectionIndexFromDOMElement(target);
277
275
  const section = state.sections[sectionIndex];
278
276
  if (readOnly || !sectionListRef.current) {
@@ -368,7 +366,7 @@ export const useFieldV7TextField = params => {
368
366
  const valueStr = React.useMemo(() => areAllSectionsEmpty ? '' : fieldValueManager.getV7HiddenInputValueFromSections(state.sections), [areAllSectionsEmpty, state.sections, fieldValueManager]);
369
367
  React.useEffect(() => {
370
368
  if (sectionListRef.current == null) {
371
- throw new Error(['MUI X: The `sectionListRef` prop has not been initialized by `PickersSectionList`', 'You probably tried to pass a component to the `textField` slot that contains an `<input />` element instead of a `PickersSectionList`.', '', 'If you want to keep using an `<input />` HTML element for the editing, please remove the `enableAccessibleFieldDOMStructure` prop from your picker or field component:', '', '<DatePicker slots={{ textField: MyCustomTextField }} />', '', 'Learn more about the field accessible DOM structure on the MUI documentation: https://next.mui.com/x/react-date-pickers/fields/#fields-to-edit-a-single-element'].join('\n'));
369
+ throw new Error(['MUI X: The `sectionListRef` prop has not been initialized by `PickersSectionList`', 'You probably tried to pass a component to the `textField` slot that contains an `<input />` element instead of a `PickersSectionList`.', '', 'If you want to keep using an `<input />` HTML element for the editing, please remove the `enableAccessibleFieldDOMStructure` prop from your picker or field component:', '', '<DatePicker slots={{ textField: MyCustomTextField }} />', '', 'Learn more about the field accessible DOM structure on the MUI documentation: https://mui.com/x/react-date-pickers/fields/#fields-to-edit-a-single-element'].join('\n'));
372
370
  }
373
371
  if (autoFocus && sectionListRef.current) {
374
372
  sectionListRef.current.getSectionContent(sectionOrder.startIndex).focus();
@@ -381,7 +379,7 @@ export const useFieldV7TextField = params => {
381
379
  // Forwarded
382
380
  autoFocus,
383
381
  readOnly,
384
- focused: focusedProp != null ? focusedProp : focused,
382
+ focused: focusedProp ?? focused,
385
383
  sectionListRef: handleSectionListRef,
386
384
  onBlur: handleContainerBlur,
387
385
  onClick: handleContainerClick,
@@ -20,7 +20,6 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
20
20
  * - MobileTimePicker
21
21
  */
22
22
  export const useMobilePicker = _ref => {
23
- var _innerSlotProps$toolb, _innerSlotProps$toolb2, _slots$layout;
24
23
  let {
25
24
  props,
26
25
  getOpenDialogAriaText
@@ -47,7 +46,7 @@ export const useMobilePicker = _ref => {
47
46
  const utils = useUtils();
48
47
  const fieldRef = React.useRef(null);
49
48
  const labelId = useId();
50
- const isToolbarHidden = (_innerSlotProps$toolb = innerSlotProps == null || (_innerSlotProps$toolb2 = innerSlotProps.toolbar) == null ? void 0 : _innerSlotProps$toolb2.hidden) != null ? _innerSlotProps$toolb : false;
49
+ const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
51
50
  const {
52
51
  open,
53
52
  actions,
@@ -64,14 +63,14 @@ export const useMobilePicker = _ref => {
64
63
  const Field = slots.field;
65
64
  const fieldProps = useSlotProps({
66
65
  elementType: Field,
67
- externalSlotProps: innerSlotProps == null ? void 0 : innerSlotProps.field,
66
+ externalSlotProps: innerSlotProps?.field,
68
67
  additionalProps: _extends({}, pickerFieldProps, isToolbarHidden && {
69
68
  id: labelId
70
69
  }, !(disabled || readOnly) && {
71
70
  onClick: actions.onOpen,
72
71
  onKeyDown: onSpaceOrEnter(actions.onOpen)
73
72
  }, {
74
- readOnly: readOnly != null ? readOnly : true,
73
+ readOnly: readOnly ?? true,
75
74
  disabled,
76
75
  className,
77
76
  sx,
@@ -96,7 +95,7 @@ export const useMobilePicker = _ref => {
96
95
  const slotsForField = _extends({
97
96
  textField: slots.textField
98
97
  }, fieldProps.slots);
99
- const Layout = (_slots$layout = slots.layout) != null ? _slots$layout : PickersLayout;
98
+ const Layout = slots.layout ?? PickersLayout;
100
99
  let labelledById = labelId;
101
100
  if (isToolbarHidden) {
102
101
  if (label) {
@@ -106,12 +105,12 @@ export const useMobilePicker = _ref => {
106
105
  }
107
106
  }
108
107
  const slotProps = _extends({}, innerSlotProps, {
109
- toolbar: _extends({}, innerSlotProps == null ? void 0 : innerSlotProps.toolbar, {
108
+ toolbar: _extends({}, innerSlotProps?.toolbar, {
110
109
  titleId: labelId
111
110
  }),
112
111
  mobilePaper: _extends({
113
112
  'aria-labelledby': labelledById
114
- }, innerSlotProps == null ? void 0 : innerSlotProps.mobilePaper)
113
+ }, innerSlotProps?.mobilePaper)
115
114
  });
116
115
  const handleFieldRef = useForkRef(fieldRef, fieldProps.unstableFieldRef);
117
116
  const renderPicker = () => /*#__PURE__*/_jsxs(LocalizationProvider, {
@@ -124,7 +123,7 @@ export const useMobilePicker = _ref => {
124
123
  open: open,
125
124
  slots: slots,
126
125
  slotProps: slotProps,
127
- children: /*#__PURE__*/_jsx(Layout, _extends({}, layoutProps, slotProps == null ? void 0 : slotProps.layout, {
126
+ children: /*#__PURE__*/_jsx(Layout, _extends({}, layoutProps, slotProps?.layout, {
128
127
  slots: slots,
129
128
  slotProps: slotProps,
130
129
  children: renderCurrentView()
@@ -8,7 +8,7 @@ export const useOpenState = ({
8
8
  const [openState, setIsOpenState] = React.useState(false);
9
9
 
10
10
  // It is required to update inner state in useEffect in order to avoid situation when
11
- // Our component is not mounted yet, but `open` state is set to `true` (e.g. initially opened)
11
+ // Our component is not mounted yet, but `open` state is set to `true` (for example initially opened)
12
12
  React.useEffect(() => {
13
13
  if (isControllingOpenProp) {
14
14
  if (typeof open !== 'boolean') {
@@ -1,3 +1,4 @@
1
1
  export { usePicker } from './usePicker';
2
2
  export type { UsePickerProps, UsePickerBaseProps, UsePickerParams, UsePickerResponse, } from './usePicker.types';
3
3
  export type { PickerValueManager, PickerSelectionState, UsePickerValueFieldResponse, } from './usePickerValue.types';
4
+ export type { PickerViewsRendererProps } from './usePickerViews';
@@ -7,11 +7,13 @@ import { DateOrTimeViewWithMeridiem } from '../../models';
7
7
  import { FieldRef, FieldSection, PickerValidDate, TimezoneProps } from '../../../models';
8
8
  interface PickerViewsRendererBaseExternalProps<TView extends DateOrTimeViewWithMeridiem> extends Omit<UsePickerViewsProps<any, any, TView, any, any>, 'openTo' | 'viewRenderers'> {
9
9
  }
10
- export type PickerViewsRendererProps<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = TExternalProps & TAdditionalProps & UsePickerValueViewsResponse<TValue> & {
10
+ export type PickerViewsRendererProps<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = Omit<TExternalProps, 'className' | 'sx'> & TAdditionalProps & UsePickerValueViewsResponse<TValue> & {
11
11
  view: TView;
12
12
  views: readonly TView[];
13
13
  focusedView: TView | null;
14
14
  onFocusedViewChange: (viewToFocus: TView, hasFocus: boolean) => void;
15
+ showViewSwitcher: boolean;
16
+ timeViewsCount: number;
15
17
  };
16
18
  export type PickerViewRenderer<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<TView>, TAdditionalProps extends {}> = (props: PickerViewsRendererProps<TValue, TView, TExternalProps, TAdditionalProps>) => React.ReactNode;
17
19
  export type PickerViewRendererLookup<TValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends PickerViewsRendererBaseExternalProps<any>, TAdditionalProps extends {}> = {
@@ -73,7 +75,7 @@ export interface UsePickerViewParams<TValue, TDate extends PickerValidDate, TVie
73
75
  * @param {any} rendererProps All the props that are being passed down to the renderer.
74
76
  * @returns {React.ReactNode} A React node that will be rendered instead of the default renderer.
75
77
  */
76
- rendererInterceptor?: (viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps, TAdditionalProps>, popperView: TView, rendererProps: Omit<TExternalProps, 'className' | 'sx'> & TAdditionalProps & UsePickerValueViewsResponse<TValue>) => React.ReactNode;
78
+ rendererInterceptor?: (viewRenderers: PickerViewRendererLookup<TValue, TView, TExternalProps, TAdditionalProps>, popperView: TView, rendererProps: PickerViewsRendererProps<TValue, TView, TExternalProps, TAdditionalProps>) => React.ReactNode;
77
79
  }
78
80
  export interface UsePickerViewsResponse<TView extends DateOrTimeViewWithMeridiem> {
79
81
  /**
@@ -100,10 +100,9 @@ export const usePickerViews = ({
100
100
  if (currentViewMode === 'field' && open) {
101
101
  onClose();
102
102
  setTimeout(() => {
103
- var _fieldRef$current;
104
103
  // focusing the input before the range selection is done
105
104
  // calling it outside of timeout results in an inconsistent behavior between Safari And Chrome
106
- fieldRef == null || (_fieldRef$current = fieldRef.current) == null || _fieldRef$current.focusField(view);
105
+ fieldRef?.current?.focusField(view);
107
106
  });
108
107
  }
109
108
  }, [view]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -24,7 +24,6 @@ const PickerStaticLayout = styled(PickersLayout)(({
24
24
  * - StaticTimePicker
25
25
  */
26
26
  export const useStaticPicker = _ref => {
27
- var _slots$layout;
28
27
  let {
29
28
  props,
30
29
  ref
@@ -44,26 +43,23 @@ export const useStaticPicker = _ref => {
44
43
  renderCurrentView
45
44
  } = usePicker(_extends({}, pickerParams, {
46
45
  props,
47
- autoFocusView: autoFocus != null ? autoFocus : false,
46
+ autoFocusView: autoFocus ?? false,
48
47
  fieldRef: undefined,
49
48
  additionalViewProps: {},
50
49
  wrapperVariant: displayStaticWrapperAs
51
50
  }));
52
- const Layout = (_slots$layout = slots == null ? void 0 : slots.layout) != null ? _slots$layout : PickerStaticLayout;
53
- const renderPicker = () => {
54
- var _slotProps$layout, _slotProps$layout2, _slotProps$layout3;
55
- return /*#__PURE__*/_jsx(LocalizationProvider, {
56
- localeText: localeText,
57
- children: /*#__PURE__*/_jsx(Layout, _extends({}, layoutProps, slotProps == null ? void 0 : slotProps.layout, {
58
- slots: slots,
59
- slotProps: slotProps,
60
- sx: [...(Array.isArray(sx) ? sx : [sx]), ...(Array.isArray(slotProps == null || (_slotProps$layout = slotProps.layout) == null ? void 0 : _slotProps$layout.sx) ? slotProps.layout.sx : [slotProps == null || (_slotProps$layout2 = slotProps.layout) == null ? void 0 : _slotProps$layout2.sx])],
61
- className: clsx(className, slotProps == null || (_slotProps$layout3 = slotProps.layout) == null ? void 0 : _slotProps$layout3.className),
62
- ref: ref,
63
- children: renderCurrentView()
64
- }))
65
- });
66
- };
51
+ const Layout = slots?.layout ?? PickerStaticLayout;
52
+ const renderPicker = () => /*#__PURE__*/_jsx(LocalizationProvider, {
53
+ localeText: localeText,
54
+ children: /*#__PURE__*/_jsx(Layout, _extends({}, layoutProps, slotProps?.layout, {
55
+ slots: slots,
56
+ slotProps: slotProps,
57
+ sx: [...(Array.isArray(sx) ? sx : [sx]), ...(Array.isArray(slotProps?.layout?.sx) ? slotProps.layout.sx : [slotProps?.layout?.sx])],
58
+ className: clsx(className, slotProps?.layout?.className),
59
+ ref: ref,
60
+ children: renderCurrentView()
61
+ }))
62
+ });
67
63
  return {
68
64
  renderPicker
69
65
  };
@@ -14,10 +14,9 @@ export const useValueWithTimezone = ({
14
14
  onChange,
15
15
  valueManager
16
16
  }) => {
17
- var _ref, _ref2;
18
17
  const utils = useUtils();
19
18
  const firstDefaultValue = React.useRef(defaultValue);
20
- const inputValue = (_ref = valueProp != null ? valueProp : firstDefaultValue.current) != null ? _ref : valueManager.emptyValue;
19
+ const inputValue = valueProp ?? firstDefaultValue.current ?? valueManager.emptyValue;
21
20
  const inputTimezone = React.useMemo(() => valueManager.getTimezone(utils, inputValue), [utils, valueManager, inputValue]);
22
21
  const setInputTimezone = useEventCallback(newValue => {
23
22
  if (inputTimezone == null) {
@@ -25,11 +24,11 @@ export const useValueWithTimezone = ({
25
24
  }
26
25
  return valueManager.setTimezone(utils, inputTimezone, newValue);
27
26
  });
28
- const timezoneToRender = (_ref2 = timezoneProp != null ? timezoneProp : inputTimezone) != null ? _ref2 : 'default';
27
+ const timezoneToRender = timezoneProp ?? inputTimezone ?? 'default';
29
28
  const valueWithTimezoneToRender = React.useMemo(() => valueManager.setTimezone(utils, timezoneToRender, inputValue), [valueManager, utils, timezoneToRender, inputValue]);
30
29
  const handleValueChange = useEventCallback((newValue, ...otherParams) => {
31
30
  const newValueWithInputTimezone = setInputTimezone(newValue);
32
- onChange == null || onChange(newValueWithInputTimezone, ...otherParams);
31
+ onChange?.(newValueWithInputTimezone, ...otherParams);
33
32
  });
34
33
  return {
35
34
  value: valueWithTimezoneToRender,
@@ -53,11 +52,11 @@ export const useControlledValueWithTimezone = ({
53
52
  name,
54
53
  state: 'value',
55
54
  controlled: valueProp,
56
- default: defaultValue != null ? defaultValue : valueManager.emptyValue
55
+ default: defaultValue ?? valueManager.emptyValue
57
56
  });
58
57
  const onChange = useEventCallback((newValue, ...otherParams) => {
59
58
  setValue(newValue);
60
- onChangeProp == null || onChangeProp(newValue, ...otherParams);
59
+ onChangeProp?.(newValue, ...otherParams);
61
60
  });
62
61
  return useValueWithTimezone({
63
62
  timezone: timezoneProp,
@@ -12,7 +12,6 @@ export function useViews({
12
12
  focusedView: inFocusedView,
13
13
  onFocusedViewChange
14
14
  }) {
15
- var _views, _views2;
16
15
  if (process.env.NODE_ENV !== 'production') {
17
16
  if (!warnedOnceNotValidView) {
18
17
  if (inView != null && !views.includes(inView)) {
@@ -50,8 +49,8 @@ export function useViews({
50
49
  }
51
50
  }, [openTo, setView, view, views]);
52
51
  const viewIndex = views.indexOf(view);
53
- const previousView = (_views = views[viewIndex - 1]) != null ? _views : null;
54
- const nextView = (_views2 = views[viewIndex + 1]) != null ? _views2 : null;
52
+ const previousView = views[viewIndex - 1] ?? null;
53
+ const nextView = views[viewIndex + 1] ?? null;
55
54
  const handleFocusedViewChange = useEventCallback((viewToFocus, hasFocus) => {
56
55
  if (hasFocus) {
57
56
  // Focus event
@@ -61,7 +60,7 @@ export function useViews({
61
60
  setFocusedView(prevFocusedView => viewToFocus === prevFocusedView ? null : prevFocusedView // If false the blur is due to view switching
62
61
  );
63
62
  }
64
- onFocusedViewChange == null || onFocusedViewChange(viewToFocus, hasFocus);
63
+ onFocusedViewChange?.(viewToFocus, hasFocus);
65
64
  });
66
65
  const handleChangeView = useEventCallback(newView => {
67
66
  // always keep the focused view in sync
@@ -27,7 +27,7 @@ export { useField, createDateStrForV7HiddenInputFromSections, createDateStrForV6
27
27
  export type { UseFieldInternalProps, UseFieldParams, UseFieldResponse, FieldValueManager, FieldChangeHandler, FieldChangeHandlerContext, } from './hooks/useField';
28
28
  export type { MobileOnlyPickerProps } from './hooks/useMobilePicker';
29
29
  export { usePicker } from './hooks/usePicker';
30
- export type { UsePickerResponse, UsePickerParams, UsePickerProps, UsePickerValueFieldResponse, } from './hooks/usePicker';
30
+ export type { UsePickerResponse, UsePickerParams, UsePickerProps, UsePickerValueFieldResponse, PickerViewsRendererProps, } from './hooks/usePicker';
31
31
  export type { UsePickerValueNonStaticProps, PickerValueManager, PickerSelectionState, } from './hooks/usePicker/usePickerValue.types';
32
32
  export type { UsePickerViewsNonStaticProps, PickerViewRendererLookup, PickerViewRenderer, UsePickerViewsProps, } from './hooks/usePicker/usePickerViews';
33
33
  export { useStaticPicker } from './hooks/useStaticPicker';
@@ -71,7 +71,7 @@ export interface DayValidationProps<TDate extends PickerValidDate> {
71
71
  /**
72
72
  * Disable specific date.
73
73
  *
74
- * Warning: This function can be called multiple times (e.g. when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.
74
+ * Warning: This function can be called multiple times (for example when rendering date calendar, checking if focus can be moved to a certain date, etc.). Expensive computations can impact performance.
75
75
  *
76
76
  * @template TDate
77
77
  * @param {TDate} day The date to test.
@@ -15,7 +15,7 @@ export const convertFieldResponseIntoMuiTextFieldProps = _ref => {
15
15
  } = fieldResponse,
16
16
  other = _objectWithoutPropertiesLoose(fieldResponse, _excluded2);
17
17
  return _extends({}, other, {
18
- InputProps: _extends({}, InputProps != null ? InputProps : {}, {
18
+ InputProps: _extends({}, InputProps ?? {}, {
19
19
  readOnly
20
20
  })
21
21
  });
@@ -31,10 +31,10 @@ export const convertFieldResponseIntoMuiTextFieldProps = _ref => {
31
31
  } = fieldResponse,
32
32
  other = _objectWithoutPropertiesLoose(fieldResponse, _excluded3);
33
33
  return _extends({}, other, {
34
- InputProps: _extends({}, InputProps != null ? InputProps : {}, {
34
+ InputProps: _extends({}, InputProps ?? {}, {
35
35
  readOnly
36
36
  }),
37
- inputProps: _extends({}, inputProps != null ? inputProps : {}, {
37
+ inputProps: _extends({}, inputProps ?? {}, {
38
38
  inputMode,
39
39
  onPaste,
40
40
  onKeyDown,
@@ -45,17 +45,14 @@ const resolveViews = (ampm, views, shouldUseSingleColumn) => {
45
45
  }
46
46
  return ampm ? [...views, 'meridiem'] : views;
47
47
  };
48
- const resolveShouldRenderTimeInASingleColumn = (timeSteps, threshold) => {
49
- var _timeSteps$hours, _timeSteps$minutes;
50
- return 24 * 60 / (((_timeSteps$hours = timeSteps.hours) != null ? _timeSteps$hours : 1) * ((_timeSteps$minutes = timeSteps.minutes) != null ? _timeSteps$minutes : 5)) <= threshold;
51
- };
48
+ const resolveShouldRenderTimeInASingleColumn = (timeSteps, threshold) => 24 * 60 / ((timeSteps.hours ?? 1) * (timeSteps.minutes ?? 5)) <= threshold;
52
49
  export function resolveTimeViewsResponse({
53
50
  thresholdToRenderTimeInASingleColumn: inThreshold,
54
51
  ampm,
55
52
  timeSteps: inTimeSteps,
56
53
  views
57
54
  }) {
58
- const thresholdToRenderTimeInASingleColumn = inThreshold != null ? inThreshold : 24;
55
+ const thresholdToRenderTimeInASingleColumn = inThreshold ?? 24;
59
56
  const timeSteps = _extends({
60
57
  hours: 1,
61
58
  minutes: 5,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { DATE_TIME_VALIDATION_PROP_NAMES, DATE_VALIDATION_PROP_NAMES, TIME_VALIDATION_PROP_NAMES } from './validation/extractValidationProps';
3
- const SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'referenceDate', 'format', 'formatDensity', 'onChange', 'timezone', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'unstableFieldRef', 'enableAccessibleFieldDOMStructure', 'disabled', 'readOnly'];
3
+ const SHARED_FIELD_INTERNAL_PROP_NAMES = ['value', 'defaultValue', 'referenceDate', 'format', 'formatDensity', 'onChange', 'timezone', 'onError', 'shouldRespectLeadingZeros', 'selectedSections', 'onSelectedSectionsChange', 'unstableFieldRef', 'enableAccessibleFieldDOMStructure', 'disabled', 'readOnly', 'dateSeparator'];
4
4
  export const splitFieldInternalAndForwardedProps = (props, valueType) => {
5
5
  const forwardedProps = _extends({}, props);
6
6
  const internalProps = {};