@mui/x-date-pickers 9.0.0-alpha.4 → 9.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 (300) hide show
  1. package/AdapterDateFnsBase/AdapterDateFnsBase.mjs +1 -1
  2. package/AdapterDayjs/AdapterDayjs.mjs +1 -1
  3. package/AdapterLuxon/AdapterLuxon.mjs +1 -1
  4. package/AdapterMoment/AdapterMoment.mjs +1 -1
  5. package/AdapterMomentHijri/AdapterMomentHijri.mjs +1 -1
  6. package/AdapterMomentJalaali/AdapterMomentJalaali.mjs +1 -1
  7. package/CHANGELOG.md +374 -2
  8. package/DateCalendar/DateCalendar.js +1 -1
  9. package/DateCalendar/DateCalendar.mjs +1 -1
  10. package/DateCalendar/DayCalendar.d.mts +7 -7
  11. package/DateCalendar/DayCalendar.d.ts +7 -7
  12. package/DateCalendar/DayCalendar.js +23 -25
  13. package/DateCalendar/DayCalendar.mjs +23 -25
  14. package/DateField/DateField.d.mts +1 -1
  15. package/DateField/DateField.d.ts +1 -1
  16. package/DateField/DateField.js +22 -28
  17. package/DateField/DateField.mjs +22 -28
  18. package/DateField/DateField.types.d.mts +3 -3
  19. package/DateField/DateField.types.d.ts +3 -3
  20. package/DateField/useDateField.d.mts +1 -1
  21. package/DateField/useDateField.d.ts +1 -1
  22. package/DateField/useDateField.js +1 -1
  23. package/DateField/useDateField.mjs +1 -1
  24. package/DatePicker/DatePicker.d.mts +1 -1
  25. package/DatePicker/DatePicker.d.ts +1 -1
  26. package/DatePicker/DatePicker.js +1 -5
  27. package/DatePicker/DatePicker.mjs +1 -5
  28. package/DatePicker/DatePicker.types.d.mts +3 -3
  29. package/DatePicker/DatePicker.types.d.ts +3 -3
  30. package/DateTimeField/DateTimeField.d.mts +1 -1
  31. package/DateTimeField/DateTimeField.d.ts +1 -1
  32. package/DateTimeField/DateTimeField.js +22 -28
  33. package/DateTimeField/DateTimeField.mjs +22 -28
  34. package/DateTimeField/DateTimeField.types.d.mts +2 -2
  35. package/DateTimeField/DateTimeField.types.d.ts +2 -2
  36. package/DateTimeField/useDateTimeField.d.mts +1 -1
  37. package/DateTimeField/useDateTimeField.d.ts +1 -1
  38. package/DateTimeField/useDateTimeField.js +1 -1
  39. package/DateTimeField/useDateTimeField.mjs +1 -1
  40. package/DateTimePicker/DateTimePicker.d.mts +1 -1
  41. package/DateTimePicker/DateTimePicker.d.ts +1 -1
  42. package/DateTimePicker/DateTimePicker.js +1 -5
  43. package/DateTimePicker/DateTimePicker.mjs +1 -5
  44. package/DateTimePicker/DateTimePicker.types.d.mts +3 -3
  45. package/DateTimePicker/DateTimePicker.types.d.ts +3 -3
  46. package/DesktopDatePicker/DesktopDatePicker.d.mts +1 -1
  47. package/DesktopDatePicker/DesktopDatePicker.d.ts +1 -1
  48. package/DesktopDatePicker/DesktopDatePicker.js +1 -5
  49. package/DesktopDatePicker/DesktopDatePicker.mjs +1 -5
  50. package/DesktopDatePicker/DesktopDatePicker.types.d.mts +3 -3
  51. package/DesktopDatePicker/DesktopDatePicker.types.d.ts +3 -3
  52. package/DesktopDateTimePicker/DesktopDateTimePicker.d.mts +1 -1
  53. package/DesktopDateTimePicker/DesktopDateTimePicker.d.ts +1 -1
  54. package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -5
  55. package/DesktopDateTimePicker/DesktopDateTimePicker.mjs +1 -5
  56. package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.mts +3 -3
  57. package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +3 -3
  58. package/DesktopTimePicker/DesktopTimePicker.d.mts +1 -1
  59. package/DesktopTimePicker/DesktopTimePicker.d.ts +1 -1
  60. package/DesktopTimePicker/DesktopTimePicker.js +0 -4
  61. package/DesktopTimePicker/DesktopTimePicker.mjs +0 -4
  62. package/DesktopTimePicker/DesktopTimePicker.types.d.mts +3 -3
  63. package/DesktopTimePicker/DesktopTimePicker.types.d.ts +3 -3
  64. package/DigitalClock/DigitalClock.d.mts +1 -1
  65. package/DigitalClock/DigitalClock.d.ts +1 -1
  66. package/DigitalClock/DigitalClock.js +2 -2
  67. package/DigitalClock/DigitalClock.mjs +3 -3
  68. package/LocalizationProvider/LocalizationProvider.d.mts +0 -6
  69. package/LocalizationProvider/LocalizationProvider.d.ts +0 -6
  70. package/LocalizationProvider/LocalizationProvider.js +1 -10
  71. package/LocalizationProvider/LocalizationProvider.mjs +0 -9
  72. package/LocalizationProvider/index.d.mts +1 -1
  73. package/LocalizationProvider/index.d.ts +1 -1
  74. package/LocalizationProvider/index.js +0 -6
  75. package/LocalizationProvider/index.mjs +1 -1
  76. package/MobileDatePicker/MobileDatePicker.d.mts +1 -1
  77. package/MobileDatePicker/MobileDatePicker.d.ts +1 -1
  78. package/MobileDatePicker/MobileDatePicker.js +1 -5
  79. package/MobileDatePicker/MobileDatePicker.mjs +1 -5
  80. package/MobileDatePicker/MobileDatePicker.types.d.mts +3 -3
  81. package/MobileDatePicker/MobileDatePicker.types.d.ts +3 -3
  82. package/MobileDateTimePicker/MobileDateTimePicker.d.mts +1 -1
  83. package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -1
  84. package/MobileDateTimePicker/MobileDateTimePicker.js +1 -5
  85. package/MobileDateTimePicker/MobileDateTimePicker.mjs +1 -5
  86. package/MobileDateTimePicker/MobileDateTimePicker.types.d.mts +3 -3
  87. package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +3 -3
  88. package/MobileTimePicker/MobileTimePicker.d.mts +1 -1
  89. package/MobileTimePicker/MobileTimePicker.d.ts +1 -1
  90. package/MobileTimePicker/MobileTimePicker.js +0 -4
  91. package/MobileTimePicker/MobileTimePicker.mjs +0 -4
  92. package/MobileTimePicker/MobileTimePicker.types.d.mts +3 -3
  93. package/MobileTimePicker/MobileTimePicker.types.d.ts +3 -3
  94. package/MonthCalendar/MonthCalendarButton.js +2 -2
  95. package/MonthCalendar/MonthCalendarButton.mjs +3 -3
  96. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +2 -2
  97. package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.mjs +3 -3
  98. package/PickerDay/PickerDay.d.mts +14 -0
  99. package/PickerDay/PickerDay.d.ts +14 -0
  100. package/{PickerDay2/PickerDay2.js → PickerDay/PickerDay.js} +110 -45
  101. package/{PickerDay2/PickerDay2.mjs → PickerDay/PickerDay.mjs} +110 -45
  102. package/PickerDay/PickerDay.types.d.mts +137 -0
  103. package/PickerDay/PickerDay.types.d.ts +137 -0
  104. package/PickerDay/index.d.mts +4 -0
  105. package/PickerDay/index.d.ts +4 -0
  106. package/PickerDay/index.js +25 -0
  107. package/PickerDay/index.mjs +2 -0
  108. package/{PickerDay2/pickerDay2Classes.d.mts → PickerDay/pickerDayClasses.d.mts} +4 -4
  109. package/{PickerDay2/pickerDay2Classes.d.ts → PickerDay/pickerDayClasses.d.ts} +4 -4
  110. package/PickerDay/pickerDayClasses.js +14 -0
  111. package/PickerDay/pickerDayClasses.mjs +6 -0
  112. package/PickersTextField/PickersFilledInput/PickersFilledInput.js +37 -16
  113. package/PickersTextField/PickersFilledInput/PickersFilledInput.mjs +37 -16
  114. package/PickersTextField/PickersInput/PickersInput.js +35 -14
  115. package/PickersTextField/PickersInput/PickersInput.mjs +35 -14
  116. package/PickersTextField/PickersInputBase/PickersInputBase.js +38 -8
  117. package/PickersTextField/PickersInputBase/PickersInputBase.mjs +38 -8
  118. package/PickersTextField/PickersInputBase/PickersInputBase.types.d.mts +56 -13
  119. package/PickersTextField/PickersInputBase/PickersInputBase.types.d.ts +56 -13
  120. package/PickersTextField/PickersOutlinedInput/Outline.js +1 -1
  121. package/PickersTextField/PickersOutlinedInput/Outline.mjs +1 -1
  122. package/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.js +33 -11
  123. package/PickersTextField/PickersOutlinedInput/PickersOutlinedInput.mjs +33 -11
  124. package/PickersTextField/PickersTextField.js +92 -39
  125. package/PickersTextField/PickersTextField.mjs +92 -39
  126. package/PickersTextField/PickersTextField.types.d.mts +56 -28
  127. package/PickersTextField/PickersTextField.types.d.ts +56 -28
  128. package/PickersTextField/index.d.mts +1 -1
  129. package/PickersTextField/index.d.ts +1 -1
  130. package/StaticDatePicker/StaticDatePicker.js +1 -1
  131. package/StaticDatePicker/StaticDatePicker.mjs +1 -1
  132. package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
  133. package/StaticDateTimePicker/StaticDateTimePicker.mjs +1 -1
  134. package/TimeField/TimeField.d.mts +1 -1
  135. package/TimeField/TimeField.d.ts +1 -1
  136. package/TimeField/TimeField.js +23 -29
  137. package/TimeField/TimeField.mjs +23 -29
  138. package/TimeField/TimeField.types.d.mts +2 -2
  139. package/TimeField/TimeField.types.d.ts +2 -2
  140. package/TimeField/useTimeField.d.mts +1 -1
  141. package/TimeField/useTimeField.d.ts +1 -1
  142. package/TimePicker/TimePicker.d.mts +1 -1
  143. package/TimePicker/TimePicker.d.ts +1 -1
  144. package/TimePicker/TimePicker.js +0 -4
  145. package/TimePicker/TimePicker.mjs +0 -4
  146. package/TimePicker/TimePicker.types.d.mts +3 -3
  147. package/TimePicker/TimePicker.types.d.ts +3 -3
  148. package/YearCalendar/YearCalendarButton.js +2 -2
  149. package/YearCalendar/YearCalendarButton.mjs +3 -3
  150. package/hooks/useParsedFormat.js +5 -7
  151. package/hooks/useParsedFormat.mjs +5 -7
  152. package/hooks/useSplitFieldProps.d.mts +1 -1
  153. package/hooks/useSplitFieldProps.d.ts +1 -1
  154. package/hooks/useSplitFieldProps.js +1 -1
  155. package/hooks/useSplitFieldProps.mjs +1 -1
  156. package/index.d.mts +1 -2
  157. package/index.d.ts +1 -2
  158. package/index.js +2 -14
  159. package/index.mjs +2 -3
  160. package/internals/components/PickerFieldUI.d.mts +11 -17
  161. package/internals/components/PickerFieldUI.d.ts +11 -17
  162. package/internals/components/PickerFieldUI.js +65 -114
  163. package/internals/components/PickerFieldUI.mjs +65 -114
  164. package/internals/components/PickerPopper/PickerPopper.js +3 -0
  165. package/internals/components/PickerPopper/PickerPopper.mjs +3 -0
  166. package/internals/components/PickersToolbar.js +3 -1
  167. package/internals/components/PickersToolbar.mjs +3 -1
  168. package/internals/demo/DemoContainer.js +6 -8
  169. package/internals/demo/DemoContainer.mjs +6 -8
  170. package/internals/hooks/PickerDay.types.d.mts +12 -0
  171. package/internals/hooks/PickerDay.types.d.ts +12 -0
  172. package/internals/hooks/useDesktopPicker/useDesktopPicker.d.mts +2 -2
  173. package/internals/hooks/useDesktopPicker/useDesktopPicker.d.ts +2 -2
  174. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.mts +6 -6
  175. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +6 -6
  176. package/internals/hooks/useField/buildSectionsFromFormat.d.mts +0 -1
  177. package/internals/hooks/useField/buildSectionsFromFormat.d.ts +0 -1
  178. package/internals/hooks/useField/buildSectionsFromFormat.js +1 -1
  179. package/internals/hooks/useField/buildSectionsFromFormat.mjs +1 -1
  180. package/internals/hooks/useField/index.d.mts +1 -1
  181. package/internals/hooks/useField/index.d.ts +1 -1
  182. package/internals/hooks/useField/index.js +2 -8
  183. package/internals/hooks/useField/index.mjs +1 -1
  184. package/internals/hooks/useField/useField.d.mts +2 -2
  185. package/internals/hooks/useField/useField.d.ts +2 -2
  186. package/internals/hooks/useField/useField.js +265 -8
  187. package/internals/hooks/useField/useField.mjs +264 -8
  188. package/internals/hooks/useField/useField.types.d.mts +11 -50
  189. package/internals/hooks/useField/useField.types.d.ts +11 -50
  190. package/internals/hooks/useField/useField.utils.d.mts +2 -3
  191. package/internals/hooks/useField/useField.utils.d.ts +2 -3
  192. package/internals/hooks/useField/useField.utils.js +8 -65
  193. package/internals/hooks/useField/useField.utils.mjs +6 -62
  194. package/internals/hooks/useField/useFieldHiddenInputProps.d.mts +2 -4
  195. package/internals/hooks/useField/useFieldHiddenInputProps.d.ts +2 -4
  196. package/internals/hooks/useField/useFieldHiddenInputProps.js +1 -3
  197. package/internals/hooks/useField/useFieldHiddenInputProps.mjs +1 -3
  198. package/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +0 -1
  199. package/internals/hooks/useField/useFieldInternalPropsWithDefaults.mjs +0 -1
  200. package/internals/hooks/useField/useFieldRootProps.d.mts +5 -5
  201. package/internals/hooks/useField/useFieldRootProps.d.ts +5 -5
  202. package/internals/hooks/useField/useFieldRootProps.js +183 -11
  203. package/internals/hooks/useField/useFieldRootProps.mjs +183 -11
  204. package/internals/hooks/useField/useFieldSectionContainerProps.d.mts +3 -5
  205. package/internals/hooks/useField/useFieldSectionContainerProps.d.ts +3 -5
  206. package/internals/hooks/useField/useFieldSectionContainerProps.js +2 -4
  207. package/internals/hooks/useField/useFieldSectionContainerProps.mjs +2 -4
  208. package/internals/hooks/useField/useFieldSectionContentProps.d.mts +6 -7
  209. package/internals/hooks/useField/useFieldSectionContentProps.d.ts +6 -7
  210. package/internals/hooks/useField/useFieldSectionContentProps.js +2 -4
  211. package/internals/hooks/useField/useFieldSectionContentProps.mjs +2 -4
  212. package/internals/hooks/useField/useFieldState.d.mts +4 -4
  213. package/internals/hooks/useField/useFieldState.d.ts +4 -4
  214. package/internals/hooks/useField/useFieldState.js +3 -6
  215. package/internals/hooks/useField/useFieldState.mjs +3 -6
  216. package/internals/hooks/useMobilePicker/useMobilePicker.d.mts +2 -2
  217. package/internals/hooks/useMobilePicker/useMobilePicker.d.ts +2 -2
  218. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.mts +6 -6
  219. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +6 -6
  220. package/internals/hooks/useNullableFieldPrivateContext.d.mts +1 -1
  221. package/internals/hooks/useNullableFieldPrivateContext.d.ts +1 -1
  222. package/internals/hooks/usePicker/usePicker.js +1 -3
  223. package/internals/hooks/usePicker/usePicker.mjs +1 -3
  224. package/{PickersDay → internals/hooks}/usePickerDayOwnerState.d.mts +2 -3
  225. package/{PickersDay → internals/hooks}/usePickerDayOwnerState.d.ts +2 -3
  226. package/{PickersDay → internals/hooks}/usePickerDayOwnerState.js +3 -5
  227. package/{PickersDay → internals/hooks}/usePickerDayOwnerState.mjs +3 -5
  228. package/internals/index.d.mts +4 -4
  229. package/internals/index.d.ts +4 -4
  230. package/internals/index.js +9 -9
  231. package/internals/index.mjs +3 -3
  232. package/internals/models/manager.d.mts +3 -5
  233. package/internals/models/manager.d.ts +3 -5
  234. package/internals/utils/valueManagers.js +1 -2
  235. package/internals/utils/valueManagers.mjs +2 -3
  236. package/managers/index.d.mts +2 -2
  237. package/managers/index.d.ts +2 -2
  238. package/managers/useDateManager.d.mts +3 -6
  239. package/managers/useDateManager.d.ts +3 -6
  240. package/managers/useDateManager.js +2 -6
  241. package/managers/useDateManager.mjs +2 -6
  242. package/managers/useDateTimeManager.d.mts +3 -6
  243. package/managers/useDateTimeManager.d.ts +3 -6
  244. package/managers/useDateTimeManager.js +2 -6
  245. package/managers/useDateTimeManager.mjs +2 -6
  246. package/managers/useTimeManager.d.mts +4 -6
  247. package/managers/useTimeManager.d.ts +4 -6
  248. package/managers/useTimeManager.js +1 -3
  249. package/managers/useTimeManager.mjs +1 -3
  250. package/models/fields.d.mts +3 -4
  251. package/models/fields.d.ts +3 -4
  252. package/models/manager.d.mts +2 -8
  253. package/models/manager.d.ts +2 -8
  254. package/package.json +55 -69
  255. package/themeAugmentation/components.d.mts +4 -8
  256. package/themeAugmentation/components.d.ts +4 -8
  257. package/themeAugmentation/overrides.d.mts +2 -4
  258. package/themeAugmentation/overrides.d.ts +2 -4
  259. package/themeAugmentation/props.d.mts +5 -7
  260. package/themeAugmentation/props.d.ts +5 -7
  261. package/PickerDay2/PickerDay2.d.mts +0 -7
  262. package/PickerDay2/PickerDay2.d.ts +0 -7
  263. package/PickerDay2/PickerDay2.types.d.mts +0 -18
  264. package/PickerDay2/PickerDay2.types.d.ts +0 -18
  265. package/PickerDay2/index.d.mts +0 -4
  266. package/PickerDay2/index.d.ts +0 -4
  267. package/PickerDay2/index.js +0 -25
  268. package/PickerDay2/index.mjs +0 -2
  269. package/PickerDay2/pickerDay2Classes.js +0 -14
  270. package/PickerDay2/pickerDay2Classes.mjs +0 -6
  271. package/PickersDay/PickersDay.d.mts +0 -15
  272. package/PickersDay/PickersDay.d.ts +0 -15
  273. package/PickersDay/PickersDay.js +0 -384
  274. package/PickersDay/PickersDay.mjs +0 -377
  275. package/PickersDay/PickersDay.types.d.mts +0 -114
  276. package/PickersDay/PickersDay.types.d.ts +0 -114
  277. package/PickersDay/index.d.mts +0 -4
  278. package/PickersDay/index.d.ts +0 -4
  279. package/PickersDay/index.js +0 -25
  280. package/PickersDay/index.mjs +0 -2
  281. package/PickersDay/pickersDayClasses.d.mts +0 -19
  282. package/PickersDay/pickersDayClasses.d.ts +0 -19
  283. package/PickersDay/pickersDayClasses.js +0 -14
  284. package/PickersDay/pickersDayClasses.mjs +0 -6
  285. package/internals/hooks/useField/useFieldRootHandleKeyDown.d.mts +0 -16
  286. package/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +0 -16
  287. package/internals/hooks/useField/useFieldRootHandleKeyDown.js +0 -211
  288. package/internals/hooks/useField/useFieldRootHandleKeyDown.mjs +0 -205
  289. package/internals/hooks/useField/useFieldV6TextField.d.mts +0 -26
  290. package/internals/hooks/useField/useFieldV6TextField.d.ts +0 -26
  291. package/internals/hooks/useField/useFieldV6TextField.js +0 -422
  292. package/internals/hooks/useField/useFieldV6TextField.mjs +0 -413
  293. package/internals/hooks/useField/useFieldV7TextField.d.mts +0 -3
  294. package/internals/hooks/useField/useFieldV7TextField.d.ts +0 -3
  295. package/internals/hooks/useField/useFieldV7TextField.js +0 -272
  296. package/internals/hooks/useField/useFieldV7TextField.mjs +0 -264
  297. /package/{PickerDay2/PickerDay2.types.js → PickerDay/PickerDay.types.js} +0 -0
  298. /package/{PickerDay2/PickerDay2.types.mjs → PickerDay/PickerDay.types.mjs} +0 -0
  299. /package/{PickersDay/PickersDay.types.js → internals/hooks/PickerDay.types.js} +0 -0
  300. /package/{PickersDay/PickersDay.types.mjs → internals/hooks/PickerDay.types.mjs} +0 -0
@@ -1,413 +0,0 @@
1
- 'use client';
2
-
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- import * as React from 'react';
5
- import { useRtl } from '@mui/system/RtlProvider';
6
- import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
- import useEventCallback from '@mui/utils/useEventCallback';
8
- import useTimeout from '@mui/utils/useTimeout';
9
- import useForkRef from '@mui/utils/useForkRef';
10
- import { useSplitFieldProps } from "../../../hooks/index.mjs";
11
- import { getActiveElement } from "../../utils/utils.mjs";
12
- import { getSectionVisibleValue, isAndroid } from "./useField.utils.mjs";
13
- import { useFieldCharacterEditing } from "./useFieldCharacterEditing.mjs";
14
- import { useFieldRootHandleKeyDown } from "./useFieldRootHandleKeyDown.mjs";
15
- import { useFieldState } from "./useFieldState.mjs";
16
- import { useFieldInternalPropsWithDefaults } from "./useFieldInternalPropsWithDefaults.mjs";
17
- const cleanString = dirtyString => dirtyString.replace(/[\u2066\u2067\u2068\u2069]/g, '');
18
- export const addPositionPropertiesToSections = (sections, localizedDigits, isRtl) => {
19
- let position = 0;
20
- let positionInInput = isRtl ? 1 : 0;
21
- const newSections = [];
22
- for (let i = 0; i < sections.length; i += 1) {
23
- const section = sections[i];
24
- const renderedValue = getSectionVisibleValue(section, isRtl ? 'input-rtl' : 'input-ltr', localizedDigits);
25
- const sectionStr = `${section.startSeparator}${renderedValue}${section.endSeparator}`;
26
- const sectionLength = cleanString(sectionStr).length;
27
- const sectionLengthInInput = sectionStr.length;
28
-
29
- // The ...InInput values consider the unicode characters but do include them in their indexes
30
- const cleanedValue = cleanString(renderedValue);
31
- const startInInput = positionInInput + (cleanedValue === '' ? 0 : renderedValue.indexOf(cleanedValue[0])) + section.startSeparator.length;
32
- const endInInput = startInInput + cleanedValue.length;
33
- newSections.push(_extends({}, section, {
34
- start: position,
35
- end: position + sectionLength,
36
- startInInput,
37
- endInInput
38
- }));
39
- position += sectionLength;
40
- // Move position to the end of string associated to the current section
41
- positionInInput += sectionLengthInInput;
42
- }
43
- return newSections;
44
- };
45
- export const useFieldV6TextField = parameters => {
46
- const isRtl = useRtl();
47
- const focusTimeout = useTimeout();
48
- const selectionSyncTimeout = useTimeout();
49
- const {
50
- props,
51
- manager,
52
- skipContextFieldRefAssignment,
53
- manager: {
54
- valueType,
55
- internal_valueManager: valueManager,
56
- internal_fieldValueManager: fieldValueManager,
57
- internal_useOpenPickerButtonAriaLabel: useOpenPickerButtonAriaLabel
58
- }
59
- } = parameters;
60
- const {
61
- internalProps,
62
- forwardedProps
63
- } = useSplitFieldProps(props, valueType);
64
- const internalPropsWithDefaults = useFieldInternalPropsWithDefaults({
65
- manager,
66
- internalProps,
67
- skipContextFieldRefAssignment
68
- });
69
- const {
70
- onFocus,
71
- onClick,
72
- onPaste,
73
- onBlur,
74
- onKeyDown,
75
- onClear,
76
- clearable,
77
- inputRef: inputRefProp,
78
- placeholder: inPlaceholder
79
- } = forwardedProps;
80
- const {
81
- readOnly = false,
82
- disabled = false,
83
- autoFocus = false,
84
- focused,
85
- fieldRef
86
- } = internalPropsWithDefaults;
87
- const inputRef = React.useRef(null);
88
- const handleRef = useForkRef(inputRefProp, inputRef);
89
- const stateResponse = useFieldState({
90
- manager,
91
- internalPropsWithDefaults,
92
- forwardedProps
93
- });
94
- const {
95
- // States and derived states
96
- activeSectionIndex,
97
- areAllSectionsEmpty,
98
- error,
99
- localizedDigits,
100
- parsedSelectedSections,
101
- sectionOrder,
102
- state,
103
- value,
104
- // Methods to update the states
105
- clearValue,
106
- clearActiveSection,
107
- setCharacterQuery,
108
- setSelectedSections,
109
- setTempAndroidValueStr,
110
- updateSectionValue,
111
- updateValueFromValueStr,
112
- // Utilities methods
113
- getSectionsFromValue
114
- } = stateResponse;
115
- const applyCharacterEditing = useFieldCharacterEditing({
116
- stateResponse
117
- });
118
- const openPickerAriaLabel = useOpenPickerButtonAriaLabel(value);
119
- const sections = React.useMemo(() => addPositionPropertiesToSections(state.sections, localizedDigits, isRtl), [state.sections, localizedDigits, isRtl]);
120
- function syncSelectionFromDOM() {
121
- const browserStartIndex = inputRef.current.selectionStart ?? 0;
122
- let nextSectionIndex;
123
- if (browserStartIndex <= sections[0].startInInput) {
124
- // Special case if browser index is in invisible characters at the beginning
125
- nextSectionIndex = 1;
126
- } else if (browserStartIndex >= sections[sections.length - 1].endInInput) {
127
- // If the click is after the last character of the input, then we want to select the 1st section.
128
- nextSectionIndex = 1;
129
- } else {
130
- nextSectionIndex = sections.findIndex(section => section.startInInput - section.startSeparator.length > browserStartIndex);
131
- }
132
- const sectionIndex = nextSectionIndex === -1 ? sections.length - 1 : nextSectionIndex - 1;
133
- setSelectedSections(sectionIndex);
134
- }
135
- function focusField(newSelectedSection = 0) {
136
- if (getActiveElement(inputRef.current) === inputRef.current) {
137
- return;
138
- }
139
- inputRef.current?.focus();
140
- setSelectedSections(newSelectedSection);
141
- }
142
- const handleInputFocus = useEventCallback(event => {
143
- onFocus?.(event);
144
- // The ref is guaranteed to be resolved at this point.
145
- const input = inputRef.current;
146
- focusTimeout.start(0, () => {
147
- // The ref changed, the component got remounted, the focus event is no longer relevant.
148
- if (!input || input !== inputRef.current) {
149
- return;
150
- }
151
- if (activeSectionIndex != null) {
152
- return;
153
- }
154
- if (
155
- // avoid selecting all sections when focusing empty field without value
156
- input.value.length && Number(input.selectionEnd) - Number(input.selectionStart) === input.value.length) {
157
- setSelectedSections('all');
158
- } else {
159
- syncSelectionFromDOM();
160
- }
161
- });
162
- });
163
- const handleInputClick = useEventCallback((event, ...args) => {
164
- // The click event on the clear button would propagate to the input, trigger this handler and result in a wrong section selection.
165
- // We avoid this by checking if the call of `handleInputClick` is actually intended, or a side effect.
166
- if (event.isDefaultPrevented()) {
167
- return;
168
- }
169
- onClick?.(event, ...args);
170
- syncSelectionFromDOM();
171
- });
172
- const handleInputPaste = useEventCallback(event => {
173
- onPaste?.(event);
174
-
175
- // prevent default to avoid the input `onChange` handler being called
176
- event.preventDefault();
177
- if (readOnly || disabled) {
178
- return;
179
- }
180
- const pastedValue = event.clipboardData.getData('text');
181
- if (typeof parsedSelectedSections === 'number') {
182
- const activeSection = state.sections[parsedSelectedSections];
183
- const lettersOnly = /^[a-zA-Z]+$/.test(pastedValue);
184
- const digitsOnly = /^[0-9]+$/.test(pastedValue);
185
- const digitsAndLetterOnly = /^(([a-zA-Z]+)|)([0-9]+)(([a-zA-Z]+)|)$/.test(pastedValue);
186
- const isValidPastedValue = activeSection.contentType === 'letter' && lettersOnly || activeSection.contentType === 'digit' && digitsOnly || activeSection.contentType === 'digit-with-letter' && digitsAndLetterOnly;
187
- if (isValidPastedValue) {
188
- setCharacterQuery(null);
189
- updateSectionValue({
190
- section: activeSection,
191
- newSectionValue: pastedValue,
192
- shouldGoToNextSection: true
193
- });
194
- return;
195
- }
196
- if (lettersOnly || digitsOnly) {
197
- // The pasted value corresponds to a single section, but not the expected type,
198
- // skip the modification
199
- return;
200
- }
201
- }
202
- setCharacterQuery(null);
203
- updateValueFromValueStr(pastedValue);
204
- });
205
- const handleContainerBlur = useEventCallback(event => {
206
- onBlur?.(event);
207
- setSelectedSections(null);
208
- });
209
- const handleInputChange = useEventCallback(event => {
210
- if (readOnly) {
211
- return;
212
- }
213
- const targetValue = event.target.value;
214
- if (targetValue === '') {
215
- clearValue();
216
- return;
217
- }
218
- const eventData = event.nativeEvent.data;
219
- // Calling `.fill(04/11/2022)` in playwright will trigger a change event with the requested content to insert in `event.nativeEvent.data`
220
- // usual changes have only the currently typed character in the `event.nativeEvent.data`
221
- const shouldUseEventData = eventData && eventData.length > 1;
222
- const valueStr = shouldUseEventData ? eventData : targetValue;
223
- const cleanValueStr = cleanString(valueStr);
224
- if (parsedSelectedSections === 'all') {
225
- setSelectedSections(activeSectionIndex);
226
- }
227
-
228
- // If no section is selected or eventData should be used, we just try to parse the new value
229
- // This line is mostly triggered by imperative code / application tests.
230
- if (activeSectionIndex == null || shouldUseEventData) {
231
- updateValueFromValueStr(shouldUseEventData ? eventData : cleanValueStr);
232
- return;
233
- }
234
- let keyPressed;
235
- if (parsedSelectedSections === 'all' && cleanValueStr.length === 1) {
236
- keyPressed = cleanValueStr;
237
- } else {
238
- const prevValueStr = cleanString(fieldValueManager.getV6InputValueFromSections(sections, localizedDigits, isRtl));
239
- let startOfDiffIndex = -1;
240
- let endOfDiffIndex = -1;
241
- for (let i = 0; i < prevValueStr.length; i += 1) {
242
- if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
243
- startOfDiffIndex = i;
244
- }
245
- if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
246
- endOfDiffIndex = i;
247
- }
248
- }
249
- const activeSection = sections[activeSectionIndex];
250
- const hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
251
- if (hasDiffOutsideOfActiveSection) {
252
- // TODO: Support if the new date is valid
253
- return;
254
- }
255
-
256
- // The active section being selected, the browser has replaced its value with the key pressed by the user.
257
- const activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
258
- keyPressed = cleanValueStr.slice(activeSection.start + cleanString(activeSection.startSeparator || '').length, activeSectionEndRelativeToNewValue);
259
- }
260
- if (keyPressed.length === 0) {
261
- if (isAndroid()) {
262
- setTempAndroidValueStr(valueStr);
263
- }
264
- clearActiveSection();
265
- return;
266
- }
267
- applyCharacterEditing({
268
- keyPressed,
269
- sectionIndex: activeSectionIndex
270
- });
271
- });
272
- const handleClear = useEventCallback((event, ...args) => {
273
- event.preventDefault();
274
- onClear?.(event, ...args);
275
- clearValue();
276
- if (!isFieldFocused(inputRef)) {
277
- // setSelectedSections is called internally
278
- focusField(0);
279
- } else {
280
- setSelectedSections(sectionOrder.startIndex);
281
- }
282
- });
283
- const handleContainerKeyDown = useFieldRootHandleKeyDown({
284
- manager,
285
- internalPropsWithDefaults,
286
- stateResponse
287
- });
288
- const wrappedHandleContainerKeyDown = useEventCallback(event => {
289
- onKeyDown?.(event);
290
- handleContainerKeyDown(event);
291
- });
292
- const placeholder = React.useMemo(() => {
293
- if (inPlaceholder !== undefined) {
294
- return inPlaceholder;
295
- }
296
- return fieldValueManager.getV6InputValueFromSections(getSectionsFromValue(valueManager.emptyValue), localizedDigits, isRtl);
297
- }, [inPlaceholder, fieldValueManager, getSectionsFromValue, valueManager.emptyValue, localizedDigits, isRtl]);
298
- const valueStr = React.useMemo(() => state.tempValueStrAndroid ?? fieldValueManager.getV6InputValueFromSections(state.sections, localizedDigits, isRtl), [state.sections, fieldValueManager, state.tempValueStrAndroid, localizedDigits, isRtl]);
299
- React.useEffect(() => {
300
- // Select all the sections when focused on mount (`autoFocus = true` on the input)
301
- if (inputRef.current && inputRef.current === getActiveElement(inputRef.current)) {
302
- setSelectedSections('all');
303
- }
304
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
305
-
306
- useEnhancedEffect(() => {
307
- function syncSelectionToDOM() {
308
- if (!inputRef.current) {
309
- return;
310
- }
311
- if (parsedSelectedSections == null) {
312
- if (inputRef.current.scrollLeft) {
313
- // Ensure that input content is not marked as selected.
314
- // setting selection range to 0 causes issues in Safari.
315
- // https://bugs.webkit.org/show_bug.cgi?id=224425
316
- inputRef.current.scrollLeft = 0;
317
- }
318
- return;
319
- }
320
-
321
- // On multi input range pickers we want to update selection range only for the active input
322
- // This helps to avoid the focus jumping on Safari https://github.com/mui/mui-x/issues/9003
323
- // because WebKit implements the `setSelectionRange` based on the spec: https://bugs.webkit.org/show_bug.cgi?id=224425
324
- if (inputRef.current !== getActiveElement(inputRef.current)) {
325
- return;
326
- }
327
-
328
- // Fix scroll jumping on iOS browser: https://github.com/mui/mui-x/issues/8321
329
- const currentScrollTop = inputRef.current.scrollTop;
330
- if (parsedSelectedSections === 'all') {
331
- inputRef.current.select();
332
- } else {
333
- const selectedSection = sections[parsedSelectedSections];
334
- const selectionStart = selectedSection.type === 'empty' ? selectedSection.startInInput - selectedSection.startSeparator.length : selectedSection.startInInput;
335
- const selectionEnd = selectedSection.type === 'empty' ? selectedSection.endInInput + selectedSection.endSeparator.length : selectedSection.endInInput;
336
- if (selectionStart !== inputRef.current.selectionStart || selectionEnd !== inputRef.current.selectionEnd) {
337
- if (inputRef.current === getActiveElement(inputRef.current)) {
338
- inputRef.current.setSelectionRange(selectionStart, selectionEnd);
339
- }
340
- }
341
- selectionSyncTimeout.start(0, () => {
342
- // handle case when the selection is not updated correctly
343
- // could happen on Android
344
- if (inputRef.current && inputRef.current === getActiveElement(inputRef.current) &&
345
- // The section might loose all selection, where `selectionStart === selectionEnd`
346
- // https://github.com/mui/mui-x/pull/13652
347
- inputRef.current.selectionStart === inputRef.current.selectionEnd && (inputRef.current.selectionStart !== selectionStart || inputRef.current.selectionEnd !== selectionEnd)) {
348
- syncSelectionToDOM();
349
- }
350
- });
351
- }
352
-
353
- // Even reading this variable seems to do the trick, but also setting it just to make use of it
354
- inputRef.current.scrollTop = currentScrollTop;
355
- }
356
- syncSelectionToDOM();
357
- });
358
- const inputMode = React.useMemo(() => {
359
- if (activeSectionIndex == null) {
360
- return 'text';
361
- }
362
- if (state.sections[activeSectionIndex].contentType === 'letter') {
363
- return 'text';
364
- }
365
- return 'numeric';
366
- }, [activeSectionIndex, state.sections]);
367
- const inputHasFocus = inputRef.current && inputRef.current === getActiveElement(inputRef.current);
368
- const shouldShowPlaceholder = !inputHasFocus && areAllSectionsEmpty;
369
- React.useImperativeHandle(fieldRef, () => ({
370
- getSections: () => state.sections,
371
- getActiveSectionIndex: () => {
372
- const browserStartIndex = inputRef.current.selectionStart ?? 0;
373
- const browserEndIndex = inputRef.current.selectionEnd ?? 0;
374
- if (browserStartIndex === 0 && browserEndIndex === 0) {
375
- return null;
376
- }
377
- const nextSectionIndex = browserStartIndex <= sections[0].startInInput ? 1 // Special case if browser index is in invisible characters at the beginning.
378
- : sections.findIndex(section => section.startInInput - section.startSeparator.length > browserStartIndex);
379
- return nextSectionIndex === -1 ? sections.length - 1 : nextSectionIndex - 1;
380
- },
381
- setSelectedSections: newSelectedSections => setSelectedSections(newSelectedSections),
382
- focusField,
383
- isFieldFocused: () => isFieldFocused(inputRef),
384
- clearValue
385
- }));
386
- return _extends({}, forwardedProps, {
387
- error,
388
- 'aria-invalid': error,
389
- clearable: Boolean(clearable && !areAllSectionsEmpty && !readOnly && !disabled),
390
- onBlur: handleContainerBlur,
391
- onClick: handleInputClick,
392
- onFocus: handleInputFocus,
393
- onPaste: handleInputPaste,
394
- onKeyDown: wrappedHandleContainerKeyDown,
395
- onClear: handleClear,
396
- inputRef: handleRef,
397
- // Additional
398
- enableAccessibleFieldDOMStructure: false,
399
- placeholder,
400
- inputMode,
401
- autoComplete: 'off',
402
- value: shouldShowPlaceholder ? '' : valueStr,
403
- onChange: handleInputChange,
404
- focused,
405
- disabled,
406
- readOnly,
407
- autoFocus,
408
- openPickerAriaLabel
409
- });
410
- };
411
- function isFieldFocused(inputRef) {
412
- return inputRef.current === getActiveElement(inputRef.current);
413
- }
@@ -1,3 +0,0 @@
1
- import { UseFieldParameters, UseFieldProps, UseFieldReturnValue } from "./useField.types.mjs";
2
- import { PickerValidValue } from "../../models/index.mjs";
3
- export declare const useFieldV7TextField: <TValue extends PickerValidValue, TError, TValidationProps extends {}, TProps extends UseFieldProps<true>>(parameters: UseFieldParameters<TValue, true, TError, TValidationProps, TProps>) => UseFieldReturnValue<true, TProps>;
@@ -1,3 +0,0 @@
1
- import { UseFieldParameters, UseFieldProps, UseFieldReturnValue } from "./useField.types.js";
2
- import { PickerValidValue } from "../../models/index.js";
3
- export declare const useFieldV7TextField: <TValue extends PickerValidValue, TError, TValidationProps extends {}, TProps extends UseFieldProps<true>>(parameters: UseFieldParameters<TValue, true, TError, TValidationProps, TProps>) => UseFieldReturnValue<true, TProps>;
@@ -1,272 +0,0 @@
1
- "use strict";
2
- 'use client';
3
-
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
- Object.defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- exports.useFieldV7TextField = void 0;
10
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
- var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
12
- var React = _interopRequireWildcard(require("react"));
13
- var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
14
- var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
15
- var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
16
- var _useField = require("./useField.utils");
17
- var _utils = require("../../utils/utils");
18
- var _hooks = require("../../../hooks");
19
- var _useFieldCharacterEditing = require("./useFieldCharacterEditing");
20
- var _useFieldState = require("./useFieldState");
21
- var _useFieldInternalPropsWithDefaults = require("./useFieldInternalPropsWithDefaults");
22
- var _syncSelectionToDOM = require("./syncSelectionToDOM");
23
- var _useFieldRootProps = require("./useFieldRootProps");
24
- var _useFieldHiddenInputProps = require("./useFieldHiddenInputProps");
25
- var _useFieldSectionContainerProps = require("./useFieldSectionContainerProps");
26
- var _useFieldSectionContentProps = require("./useFieldSectionContentProps");
27
- const useFieldV7TextField = parameters => {
28
- const {
29
- props,
30
- manager,
31
- skipContextFieldRefAssignment,
32
- manager: {
33
- valueType,
34
- internal_useOpenPickerButtonAriaLabel: useOpenPickerButtonAriaLabel
35
- }
36
- } = parameters;
37
- const {
38
- internalProps,
39
- forwardedProps
40
- } = (0, _hooks.useSplitFieldProps)(props, valueType);
41
- const internalPropsWithDefaults = (0, _useFieldInternalPropsWithDefaults.useFieldInternalPropsWithDefaults)({
42
- manager,
43
- internalProps,
44
- skipContextFieldRefAssignment
45
- });
46
- const {
47
- sectionListRef: sectionListRefProp,
48
- onBlur,
49
- onClick,
50
- onFocus,
51
- onInput,
52
- onPaste,
53
- onKeyDown,
54
- onClear,
55
- clearable
56
- } = forwardedProps;
57
- const {
58
- disabled = false,
59
- readOnly = false,
60
- autoFocus = false,
61
- focused: focusedProp,
62
- fieldRef
63
- } = internalPropsWithDefaults;
64
- const sectionListRef = React.useRef(null);
65
- const handleSectionListRef = (0, _useForkRef.default)(sectionListRefProp, sectionListRef);
66
- const domGetters = React.useMemo(() => ({
67
- isReady: () => sectionListRef.current != null,
68
- getRoot: () => sectionListRef.current.getRoot(),
69
- getSectionContainer: sectionIndex => sectionListRef.current.getSectionContainer(sectionIndex),
70
- getSectionContent: sectionIndex => sectionListRef.current.getSectionContent(sectionIndex),
71
- getSectionIndexFromDOMElement: element => sectionListRef.current.getSectionIndexFromDOMElement(element)
72
- }), [sectionListRef]);
73
- const stateResponse = (0, _useFieldState.useFieldState)({
74
- manager,
75
- internalPropsWithDefaults,
76
- forwardedProps
77
- });
78
- const {
79
- // States and derived states
80
- areAllSectionsEmpty,
81
- error,
82
- parsedSelectedSections,
83
- sectionOrder,
84
- state,
85
- value,
86
- // Methods to update the states
87
- clearValue,
88
- setSelectedSections
89
- } = stateResponse;
90
- const applyCharacterEditing = (0, _useFieldCharacterEditing.useFieldCharacterEditing)({
91
- stateResponse
92
- });
93
- const openPickerAriaLabel = useOpenPickerButtonAriaLabel(value);
94
- const [focused, setFocused] = React.useState(false);
95
- function focusField(newSelectedSections = 0) {
96
- if (disabled || !sectionListRef.current ||
97
- // if the field is already focused, we don't need to focus it again
98
- getActiveSectionIndex(sectionListRef) != null) {
99
- return;
100
- }
101
- const newParsedSelectedSections = (0, _useField.parseSelectedSections)(newSelectedSections, state.sections);
102
- setFocused(true);
103
- sectionListRef.current.getSectionContent(newParsedSelectedSections).focus();
104
- }
105
- const rootProps = (0, _useFieldRootProps.useFieldRootProps)({
106
- manager,
107
- internalPropsWithDefaults,
108
- stateResponse,
109
- applyCharacterEditing,
110
- focused,
111
- setFocused,
112
- domGetters
113
- });
114
- const hiddenInputProps = (0, _useFieldHiddenInputProps.useFieldHiddenInputProps)({
115
- manager,
116
- stateResponse
117
- });
118
- const createSectionContainerProps = (0, _useFieldSectionContainerProps.useFieldSectionContainerProps)({
119
- stateResponse,
120
- internalPropsWithDefaults
121
- });
122
- const createSectionContentProps = (0, _useFieldSectionContentProps.useFieldSectionContentProps)({
123
- manager,
124
- stateResponse,
125
- applyCharacterEditing,
126
- internalPropsWithDefaults,
127
- domGetters,
128
- focused
129
- });
130
- const handleRootKeyDown = (0, _useEventCallback.default)(event => {
131
- onKeyDown?.(event);
132
- rootProps.onKeyDown(event);
133
- });
134
- const handleRootBlur = (0, _useEventCallback.default)(event => {
135
- onBlur?.(event);
136
- rootProps.onBlur(event);
137
- });
138
- const handleRootFocus = (0, _useEventCallback.default)(event => {
139
- onFocus?.(event);
140
- rootProps.onFocus(event);
141
- });
142
- const handleRootClick = (0, _useEventCallback.default)(event => {
143
- // The click event on the clear or open button would propagate to the input, trigger this handler and result in an inadvertent section selection.
144
- // We avoid this by checking if the call of `handleInputClick` is actually intended, or a propagated call, which should be skipped.
145
- if (event.isDefaultPrevented()) {
146
- return;
147
- }
148
- onClick?.(event);
149
- rootProps.onClick(event);
150
- });
151
- const handleRootPaste = (0, _useEventCallback.default)(event => {
152
- onPaste?.(event);
153
- rootProps.onPaste(event);
154
- });
155
- const handleRootInput = (0, _useEventCallback.default)(event => {
156
- onInput?.(event);
157
- rootProps.onInput(event);
158
- });
159
- const handleClear = (0, _useEventCallback.default)((event, ...args) => {
160
- event.preventDefault();
161
- onClear?.(event, ...args);
162
- clearValue();
163
- if (!isFieldFocused(sectionListRef)) {
164
- // setSelectedSections is called internally
165
- focusField(0);
166
- } else {
167
- setSelectedSections(sectionOrder.startIndex);
168
- }
169
- });
170
- const elements = React.useMemo(() => {
171
- return state.sections.map((section, sectionIndex) => {
172
- const content = createSectionContentProps(section, sectionIndex);
173
- return {
174
- container: createSectionContainerProps(sectionIndex),
175
- content: createSectionContentProps(section, sectionIndex),
176
- before: {
177
- children: section.startSeparator
178
- },
179
- after: {
180
- children: section.endSeparator,
181
- 'data-range-position': section.isEndFormatSeparator ? content['data-range-position'] : undefined
182
- }
183
- };
184
- });
185
- }, [state.sections, createSectionContainerProps, createSectionContentProps]);
186
- React.useEffect(() => {
187
- if (sectionListRef.current == null) {
188
- throw new Error(process.env.NODE_ENV !== "production" ? `MUI X: The \`sectionListRef\` prop has not been initialized by \`PickersSectionList\`
189
- You probably tried to pass a component to the \`textField\` slot that contains an \`<input />\` element instead of a \`PickersSectionList\`.
190
-
191
- If you want to keep using an \`<input />\` HTML element for the editing, please add the \`enableAccessibleFieldDOMStructure={false}\` prop to your Picker or Field component:
192
-
193
- <DatePicker enableAccessibleFieldDOMStructure={false} slots={{ textField: MyCustomTextField }} />
194
-
195
- 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` : (0, _formatErrorMessage2.default)(159));
196
- }
197
- if (autoFocus && !disabled && sectionListRef.current) {
198
- sectionListRef.current.getSectionContent(sectionOrder.startIndex).focus();
199
- }
200
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
201
-
202
- (0, _useEnhancedEffect.default)(() => {
203
- if (!focused || !sectionListRef.current) {
204
- return;
205
- }
206
- if (parsedSelectedSections === 'all') {
207
- sectionListRef.current.getRoot().focus();
208
- } else if (typeof parsedSelectedSections === 'number') {
209
- const domElement = sectionListRef.current.getSectionContent(parsedSelectedSections);
210
- if (domElement) {
211
- domElement.focus();
212
- }
213
- }
214
- }, [parsedSelectedSections, focused]);
215
- (0, _useEnhancedEffect.default)(() => {
216
- (0, _syncSelectionToDOM.syncSelectionToDOM)({
217
- focused,
218
- domGetters,
219
- stateResponse
220
- });
221
- });
222
- React.useImperativeHandle(fieldRef, () => ({
223
- getSections: () => state.sections,
224
- getActiveSectionIndex: () => getActiveSectionIndex(sectionListRef),
225
- setSelectedSections: newSelectedSections => {
226
- if (disabled || !sectionListRef.current) {
227
- return;
228
- }
229
- const newParsedSelectedSections = (0, _useField.parseSelectedSections)(newSelectedSections, state.sections);
230
- const newActiveSectionIndex = newParsedSelectedSections === 'all' ? 0 : newParsedSelectedSections;
231
- setFocused(newActiveSectionIndex !== null);
232
- setSelectedSections(newSelectedSections);
233
- },
234
- focusField,
235
- isFieldFocused: () => isFieldFocused(sectionListRef),
236
- clearValue
237
- }));
238
- return (0, _extends2.default)({}, forwardedProps, rootProps, {
239
- onBlur: handleRootBlur,
240
- onClick: handleRootClick,
241
- onFocus: handleRootFocus,
242
- onInput: handleRootInput,
243
- onPaste: handleRootPaste,
244
- onKeyDown: handleRootKeyDown,
245
- onClear: handleClear
246
- }, hiddenInputProps, {
247
- error,
248
- clearable: Boolean(clearable && !areAllSectionsEmpty && !readOnly && !disabled),
249
- focused: focusedProp ?? focused,
250
- sectionListRef: handleSectionListRef,
251
- // Additional
252
- enableAccessibleFieldDOMStructure: true,
253
- elements,
254
- areAllSectionsEmpty,
255
- disabled,
256
- readOnly,
257
- autoFocus,
258
- openPickerAriaLabel
259
- });
260
- };
261
- exports.useFieldV7TextField = useFieldV7TextField;
262
- function getActiveSectionIndex(sectionListRef) {
263
- const activeElement = (0, _utils.getActiveElement)(sectionListRef.current?.getRoot());
264
- if (!activeElement || !sectionListRef.current || !sectionListRef.current.getRoot().contains(activeElement)) {
265
- return null;
266
- }
267
- return sectionListRef.current.getSectionIndexFromDOMElement(activeElement);
268
- }
269
- function isFieldFocused(sectionListRef) {
270
- const activeElement = (0, _utils.getActiveElement)(sectionListRef.current?.getRoot());
271
- return !!sectionListRef.current && sectionListRef.current.getRoot().contains(activeElement);
272
- }