@elliemae/ds-controlled-form 2.4.2-rc.0 → 2.4.2-rc.9

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 (190) hide show
  1. package/cjs/autocomplete/config/useAutocomplete.js +1 -3
  2. package/cjs/checkbox/ControlledCheckbox.js +49 -33
  3. package/cjs/checkbox/exported-related/data-test-ids.js +10 -0
  4. package/cjs/checkbox/exported-related/index.js +12 -0
  5. package/cjs/checkbox/exported-related/theming.js +13 -0
  6. package/cjs/checkbox/react-desc-prop-types.js +0 -1
  7. package/cjs/checkbox/styles.js +26 -15
  8. package/cjs/combobox/ComboBoxCTX.js +1 -1
  9. package/cjs/combobox/ComboboxDataTestids.js +1 -1
  10. package/cjs/combobox/config/useComboBox.js +6 -4
  11. package/cjs/combobox/index.js +5 -0
  12. package/cjs/combobox/parts/DropdownIndicator.js +2 -2
  13. package/cjs/combobox/parts/container/Container.js +5 -5
  14. package/cjs/combobox/parts/container/styled.js +13 -7
  15. package/cjs/combobox/parts/controls/Controls.js +14 -4
  16. package/cjs/combobox/parts/controls/styled.js +22 -13
  17. package/cjs/combobox/parts/controls-input/ControlsInput.js +1 -1
  18. package/cjs/combobox/parts/controls-input/styled.js +7 -3
  19. package/cjs/combobox/parts/controls-input/useControlsInput.js +3 -4
  20. package/cjs/combobox/parts/controls-input/useKeyboardNavigation.js +30 -15
  21. package/cjs/combobox/parts/header-list/HeaderList.js +4 -3
  22. package/cjs/combobox/parts/header-list/useHeaderListHandlers.js +9 -5
  23. package/cjs/combobox/parts/menu-list/MenuList.js +5 -2
  24. package/cjs/combobox/parts/menu-list/styled.js +12 -7
  25. package/cjs/combobox/parts/menu-list/useItemRenderer.js +5 -4
  26. package/cjs/combobox/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +1 -1
  27. package/cjs/combobox/parts/multi-selected-values-container/RemovableSelectedValuePill.js +2 -0
  28. package/cjs/combobox/parts/multi-selected-values-container/useGroupPills.js +13 -10
  29. package/cjs/combobox/theming.js +13 -0
  30. package/cjs/combobox/utils/listHelper.js +2 -1
  31. package/cjs/date-time-picker/config/useChangeHandlers.js +8 -12
  32. package/cjs/date-time-picker/config/useControlledDateTimePicker.js +13 -9
  33. package/cjs/date-time-picker/config/useFocusTracker.js +136 -0
  34. package/cjs/date-time-picker/config/useGetReferences.js +40 -19
  35. package/cjs/date-time-picker/config/useGlobalKeyHandlers.js +8 -12
  36. package/cjs/date-time-picker/parts/ClearButton/ClearButton.js +12 -2
  37. package/cjs/date-time-picker/parts/ClearButton/useClearButton.js +12 -25
  38. package/cjs/date-time-picker/parts/ControlledDateTimePickerContent.js +4 -7
  39. package/cjs/date-time-picker/parts/DateInputs/DDInput.js +8 -2
  40. package/cjs/date-time-picker/parts/DateInputs/DateInputs.js +9 -4
  41. package/cjs/date-time-picker/parts/DateInputs/MMInput.js +8 -2
  42. package/cjs/date-time-picker/parts/DateInputs/YYYYInput.js +8 -2
  43. package/cjs/date-time-picker/parts/DateInputs/useDateInputs.js +76 -95
  44. package/cjs/date-time-picker/parts/Pickers/Calendar/CalendarHead.js +31 -5
  45. package/cjs/date-time-picker/parts/Pickers/Calendar/Day.js +16 -10
  46. package/cjs/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.js +12 -12
  47. package/cjs/date-time-picker/parts/Pickers/Calendar/useFocusLogic.js +2 -38
  48. package/cjs/date-time-picker/parts/Pickers/Calendar/useKeyboardHandlers.js +40 -73
  49. package/cjs/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.js +18 -27
  50. package/cjs/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelIconTrigger.js +1 -0
  51. package/cjs/date-time-picker/parts/Pickers/CalendarWithTimeWheel/useConfigCalendarWithTimeWheelCTX.js +17 -23
  52. package/cjs/date-time-picker/parts/Pickers/TimeWheel/HoursList.js +13 -7
  53. package/cjs/date-time-picker/parts/Pickers/TimeWheel/MeridiemList.js +14 -8
  54. package/cjs/date-time-picker/parts/Pickers/TimeWheel/MinutesList.js +13 -7
  55. package/cjs/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.js +36 -230
  56. package/cjs/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.js +11 -13
  57. package/cjs/date-time-picker/parts/TimeInputs/HHInput.js +8 -2
  58. package/cjs/date-time-picker/parts/TimeInputs/MeridiemInput.js +8 -2
  59. package/cjs/date-time-picker/parts/TimeInputs/MinutesInput.js +8 -2
  60. package/cjs/date-time-picker/parts/TimeInputs/TimeInputs.js +11 -6
  61. package/cjs/date-time-picker/parts/TimeInputs/useTimeInputs.js +44 -74
  62. package/cjs/date-time-picker/utils/constants.js +0 -12
  63. package/cjs/date-time-picker/utils/hooks/useGetStartingFocusedDay.js +38 -36
  64. package/cjs/index.js +16 -7
  65. package/cjs/input-group/InputGroup.js +69 -0
  66. package/cjs/input-group/InputGroupDataTestIds.js +12 -0
  67. package/cjs/input-group/index.js +12 -0
  68. package/cjs/input-group/react-desc-prop-types.js +14 -0
  69. package/cjs/input-group/styled.js +46 -0
  70. package/cjs/mask-hook/hooks/index.js +0 -1
  71. package/cjs/mask-hook/hooks/usePhoneMask.js +2 -2
  72. package/cjs/mask-hook/hooks/useRegExpMask.js +0 -1
  73. package/cjs/mask-hook/index.js +0 -1
  74. package/cjs/text-input/styled/borders.js +1 -1
  75. package/esm/autocomplete/config/useAutocomplete.js +1 -3
  76. package/esm/checkbox/ControlledCheckbox.js +52 -36
  77. package/esm/checkbox/exported-related/data-test-ids.js +6 -0
  78. package/esm/checkbox/exported-related/index.js +2 -0
  79. package/esm/checkbox/exported-related/theming.js +8 -0
  80. package/esm/checkbox/react-desc-prop-types.js +0 -1
  81. package/esm/checkbox/styles.js +25 -15
  82. package/esm/combobox/ComboBoxCTX.js +1 -1
  83. package/esm/combobox/ComboboxDataTestids.js +1 -1
  84. package/esm/combobox/config/useComboBox.js +6 -4
  85. package/esm/combobox/index.js +2 -0
  86. package/esm/combobox/parts/DropdownIndicator.js +2 -2
  87. package/esm/combobox/parts/container/Container.js +7 -7
  88. package/esm/combobox/parts/container/styled.js +13 -6
  89. package/esm/combobox/parts/controls/Controls.js +14 -4
  90. package/esm/combobox/parts/controls/styled.js +22 -13
  91. package/esm/combobox/parts/controls-input/ControlsInput.js +1 -1
  92. package/esm/combobox/parts/controls-input/styled.js +7 -3
  93. package/esm/combobox/parts/controls-input/useControlsInput.js +3 -4
  94. package/esm/combobox/parts/controls-input/useKeyboardNavigation.js +30 -15
  95. package/esm/combobox/parts/header-list/HeaderList.js +4 -3
  96. package/esm/combobox/parts/header-list/useHeaderListHandlers.js +9 -5
  97. package/esm/combobox/parts/menu-list/MenuList.js +5 -2
  98. package/esm/combobox/parts/menu-list/styled.js +12 -7
  99. package/esm/combobox/parts/menu-list/useItemRenderer.js +5 -4
  100. package/esm/combobox/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +1 -1
  101. package/esm/combobox/parts/multi-selected-values-container/RemovableSelectedValuePill.js +2 -0
  102. package/esm/combobox/parts/multi-selected-values-container/useGroupPills.js +13 -10
  103. package/esm/combobox/theming.js +8 -0
  104. package/esm/combobox/utils/listHelper.js +2 -1
  105. package/esm/date-time-picker/config/useChangeHandlers.js +8 -12
  106. package/esm/date-time-picker/config/useControlledDateTimePicker.js +13 -9
  107. package/esm/date-time-picker/config/useFocusTracker.js +132 -0
  108. package/esm/date-time-picker/config/useGetReferences.js +41 -20
  109. package/esm/date-time-picker/config/useGlobalKeyHandlers.js +8 -12
  110. package/esm/date-time-picker/parts/ClearButton/ClearButton.js +12 -2
  111. package/esm/date-time-picker/parts/ClearButton/useClearButton.js +12 -25
  112. package/esm/date-time-picker/parts/ControlledDateTimePickerContent.js +4 -7
  113. package/esm/date-time-picker/parts/DateInputs/DDInput.js +8 -2
  114. package/esm/date-time-picker/parts/DateInputs/DateInputs.js +9 -4
  115. package/esm/date-time-picker/parts/DateInputs/MMInput.js +8 -2
  116. package/esm/date-time-picker/parts/DateInputs/YYYYInput.js +8 -2
  117. package/esm/date-time-picker/parts/DateInputs/useDateInputs.js +77 -96
  118. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarHead.js +32 -6
  119. package/esm/date-time-picker/parts/Pickers/Calendar/Day.js +16 -10
  120. package/esm/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.js +12 -12
  121. package/esm/date-time-picker/parts/Pickers/Calendar/useFocusLogic.js +3 -39
  122. package/esm/date-time-picker/parts/Pickers/Calendar/useKeyboardHandlers.js +40 -73
  123. package/esm/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.js +18 -27
  124. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelIconTrigger.js +1 -0
  125. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/useConfigCalendarWithTimeWheelCTX.js +17 -23
  126. package/esm/date-time-picker/parts/Pickers/TimeWheel/HoursList.js +14 -8
  127. package/esm/date-time-picker/parts/Pickers/TimeWheel/MeridiemList.js +15 -9
  128. package/esm/date-time-picker/parts/Pickers/TimeWheel/MinutesList.js +14 -8
  129. package/esm/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.js +36 -230
  130. package/esm/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.js +11 -13
  131. package/esm/date-time-picker/parts/TimeInputs/HHInput.js +8 -2
  132. package/esm/date-time-picker/parts/TimeInputs/MeridiemInput.js +8 -2
  133. package/esm/date-time-picker/parts/TimeInputs/MinutesInput.js +8 -2
  134. package/esm/date-time-picker/parts/TimeInputs/TimeInputs.js +11 -6
  135. package/esm/date-time-picker/parts/TimeInputs/useTimeInputs.js +44 -74
  136. package/esm/date-time-picker/utils/constants.js +1 -7
  137. package/esm/date-time-picker/utils/hooks/useGetStartingFocusedDay.js +38 -36
  138. package/esm/index.js +5 -1
  139. package/esm/input-group/InputGroup.js +59 -0
  140. package/esm/input-group/InputGroupDataTestIds.js +8 -0
  141. package/esm/input-group/index.js +2 -0
  142. package/esm/input-group/react-desc-prop-types.js +10 -0
  143. package/esm/input-group/styled.js +35 -0
  144. package/esm/mask-hook/hooks/index.js +1 -1
  145. package/esm/mask-hook/hooks/usePhoneMask.js +2 -2
  146. package/esm/mask-hook/hooks/useRegExpMask.js +1 -1
  147. package/esm/mask-hook/index.js +1 -1
  148. package/esm/text-input/styled/borders.js +1 -1
  149. package/package.json +55 -19
  150. package/types/checkbox/exported-related/data-test-ids.d.ts +4 -0
  151. package/types/checkbox/exported-related/index.d.ts +2 -0
  152. package/types/checkbox/exported-related/theming.d.ts +6 -0
  153. package/types/checkbox/react-desc-prop-types.d.ts +3 -3
  154. package/types/checkbox/styles.d.ts +5 -5
  155. package/types/combobox/ComboboxDataTestids.d.ts +1 -1
  156. package/types/combobox/index.d.ts +2 -0
  157. package/types/combobox/parts/container/styled.d.ts +1 -2
  158. package/types/combobox/theming.d.ts +6 -0
  159. package/types/date-time-picker/config/useChangeHandlers.d.ts +3 -1
  160. package/types/date-time-picker/config/useControlledDateTimePicker.d.ts +2 -5
  161. package/types/date-time-picker/config/useFocusTracker.d.ts +38 -0
  162. package/types/date-time-picker/config/useGetPropsBasedOnType.d.ts +6 -6
  163. package/types/date-time-picker/config/useGetReferences.d.ts +30 -36
  164. package/types/date-time-picker/config/useGlobalKeyHandlers.d.ts +3 -1
  165. package/types/date-time-picker/parts/DateInputs/DDInput.d.ts +2 -1
  166. package/types/date-time-picker/parts/DateInputs/MMInput.d.ts +2 -1
  167. package/types/date-time-picker/parts/DateInputs/YYYYInput.d.ts +2 -1
  168. package/types/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.d.ts +14 -0
  169. package/types/date-time-picker/parts/Pickers/Calendar/useFocusLogic.d.ts +1 -2
  170. package/types/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.d.ts +19 -0
  171. package/types/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.d.ts +0 -6
  172. package/types/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.d.ts +14 -0
  173. package/types/date-time-picker/parts/TimeInputs/HHInput.d.ts +2 -1
  174. package/types/date-time-picker/parts/TimeInputs/MeridiemInput.d.ts +2 -1
  175. package/types/date-time-picker/parts/TimeInputs/MinutesInput.d.ts +2 -1
  176. package/types/date-time-picker/propTypes.d.ts +117 -0
  177. package/types/date-time-picker/sharedTypes.d.ts +1 -1
  178. package/types/date-time-picker/utils/constants.d.ts +0 -6
  179. package/types/index.d.ts +1 -0
  180. package/types/input-group/InputGroup.d.ts +5 -0
  181. package/types/input-group/InputGroupDataTestIds.d.ts +6 -0
  182. package/types/input-group/index.d.ts +2 -0
  183. package/types/input-group/react-desc-prop-types.d.ts +19 -0
  184. package/types/input-group/styled.d.ts +7 -0
  185. package/types/input-group/tests/DSInputGroup.test.d.ts +1 -0
  186. package/types/mask-hook/hooks/useRegExpMask.d.ts +0 -1
  187. package/types/text-input/config/useInputText.d.ts +5 -5
  188. package/cjs/combobox/parts/menu-list/useMenuListSetFocusOption.js +0 -51
  189. package/esm/combobox/parts/menu-list/useMenuListSetFocusOption.js +0 -47
  190. package/types/combobox/parts/menu-list/useMenuListSetFocusOption.d.ts +0 -1
@@ -35,34 +35,27 @@ const useDateInputs = () => {
35
35
  day,
36
36
  year,
37
37
  hideTime,
38
- monthInputRef,
39
- dayInputRef,
40
- yearInputRef,
41
- hourInputRef,
42
- meridiemInputRef,
43
- clearButtonRef,
44
- pickerButtonRef,
45
38
  handleChangeComposedDateString,
46
- setLatestInteractionRegion,
47
39
  withClearBtn,
48
40
  withAnyPicker,
49
41
  withAnyRightController,
50
42
  autoFocusMonthInput,
51
- lastSegmentRef
43
+ trackFocusResetter,
44
+ trackFocusFirstSegment,
45
+ trackFocusLastSegment,
46
+ trackFocusDayInput,
47
+ trackFocusMonthInput,
48
+ trackFocusYearInput,
49
+ trackFocusHourInput,
50
+ trackFocusClearBtn,
51
+ trackFocusPicker
52
52
  } = React.useContext(ControlledDateTimePickerCTX.ControlledDateTimePickerContext);
53
53
  const onHomeKeyDown = React.useCallback(() => {
54
- var _monthInputRef$curren, _monthInputRef$curren2;
55
-
56
- monthInputRef === null || monthInputRef === void 0 ? void 0 : (_monthInputRef$curren = monthInputRef.current) === null || _monthInputRef$curren === void 0 ? void 0 : (_monthInputRef$curren2 = _monthInputRef$curren.focus) === null || _monthInputRef$curren2 === void 0 ? void 0 : _monthInputRef$curren2.call(_monthInputRef$curren);
57
- }, [monthInputRef]);
54
+ trackFocusFirstSegment();
55
+ }, [trackFocusFirstSegment]);
58
56
  const onEndKeyDown = React.useCallback(() => {
59
- var _pickerButtonRef$curr, _pickerButtonRef$curr2, _clearButtonRef$curre, _clearButtonRef$curre2, _meridiemInputRef$cur, _meridiemInputRef$cur2, _yearInputRef$current, _yearInputRef$current2;
60
-
61
- if (withAnyPicker) pickerButtonRef === null || pickerButtonRef === void 0 ? void 0 : (_pickerButtonRef$curr = pickerButtonRef.current) === null || _pickerButtonRef$curr === void 0 ? void 0 : (_pickerButtonRef$curr2 = _pickerButtonRef$curr.focus) === null || _pickerButtonRef$curr2 === void 0 ? void 0 : _pickerButtonRef$curr2.call(_pickerButtonRef$curr);else if (withClearBtn) clearButtonRef === null || clearButtonRef === void 0 ? void 0 : (_clearButtonRef$curre = clearButtonRef.current) === null || _clearButtonRef$curre === void 0 ? void 0 : (_clearButtonRef$curre2 = _clearButtonRef$curre.focus) === null || _clearButtonRef$curre2 === void 0 ? void 0 : _clearButtonRef$curre2.call(_clearButtonRef$curre);else if (!hideTime) meridiemInputRef === null || meridiemInputRef === void 0 ? void 0 : (_meridiemInputRef$cur = meridiemInputRef.current) === null || _meridiemInputRef$cur === void 0 ? void 0 : (_meridiemInputRef$cur2 = _meridiemInputRef$cur.focus) === null || _meridiemInputRef$cur2 === void 0 ? void 0 : _meridiemInputRef$cur2.call(_meridiemInputRef$cur);else yearInputRef === null || yearInputRef === void 0 ? void 0 : (_yearInputRef$current = yearInputRef.current) === null || _yearInputRef$current === void 0 ? void 0 : (_yearInputRef$current2 = _yearInputRef$current.focus) === null || _yearInputRef$current2 === void 0 ? void 0 : _yearInputRef$current2.call(_yearInputRef$current);
62
- }, [withAnyPicker, pickerButtonRef, withClearBtn, clearButtonRef, hideTime, meridiemInputRef, yearInputRef]);
63
- const setLatestInteractionRegionDateInputs = React.useCallback(() => {
64
- setLatestInteractionRegion('date-inputs');
65
- }, [setLatestInteractionRegion]);
57
+ trackFocusLastSegment();
58
+ }, [trackFocusLastSegment]);
66
59
  const handleChangeMonth = React.useCallback(function (newMonth, e) {
67
60
  let metaInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : constants.defaultMetaInfo;
68
61
  const newDateString = stringHelpers.getFormattedDateString({
@@ -79,29 +72,27 @@ const useDateInputs = () => {
79
72
  handleChangeComposedDateString(newDateString, finalMetaInfo);
80
73
  }, [day, year, getIsOutOfRangeDay, getIsDisabledDay, appOnMonthChange, handleChangeComposedDateString]);
81
74
  const onMonthFocus = React.useCallback(() => {
82
- setLatestInteractionRegionDateInputs();
83
- }, [setLatestInteractionRegionDateInputs]);
75
+ trackFocusMonthInput();
76
+ }, [trackFocusMonthInput]);
84
77
  const onMonthChange = React.useCallback(e => {
85
- var _e$target, _dayInputRef$current, _dayInputRef$current$;
78
+ var _e$target;
86
79
 
87
80
  let newMonth = e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value; // converts months 2~9 to 02~09
88
81
 
89
82
  if (Number.parseInt(newMonth, 10) > 1) newMonth = stringHelpers.prependStringWithPlaceHolders(newMonth, 2);
90
83
  handleChangeMonth(newMonth, e); // auto-advance functionality:
91
84
 
92
- if (newMonth.length === 2) dayInputRef === null || dayInputRef === void 0 ? void 0 : (_dayInputRef$current = dayInputRef.current) === null || _dayInputRef$current === void 0 ? void 0 : (_dayInputRef$current$ = _dayInputRef$current.focus) === null || _dayInputRef$current$ === void 0 ? void 0 : _dayInputRef$current$.call(_dayInputRef$current);
93
- }, [dayInputRef, handleChangeMonth]);
85
+ if (newMonth.length === 2) trackFocusDayInput();
86
+ }, [handleChangeMonth, trackFocusDayInput]);
94
87
  const onMonthKeyDown = React.useCallback(e => {
95
- var _lastSegmentRef$curre, _lastSegmentRef$curre2;
96
-
97
88
  const {
98
89
  key,
99
90
  ctrlKey,
100
91
  metaKey
101
92
  } = e;
102
93
  const monthStringConvertedToInteger = Number.parseInt(month, 10);
103
- if (constants.homeEndArrowUpDownDashSlashesKeys.includes(key)) e.preventDefault();
104
- if (constants.homeEndArrowUpDownDashSlashesKeys.includes(key)) e.stopPropagation();
94
+ if (['Home', 'End', 'ArrowUp', 'ArrowDown', '-', '/', '\\'].includes(key)) e.preventDefault();
95
+ if (['Home', 'End', 'ArrowUp', 'ArrowDown', '-', '/', '\\'].includes(key)) e.stopPropagation();
105
96
  if (key === 'Home') onHomeKeyDown();
106
97
  if (key === 'End') onEndKeyDown();
107
98
 
@@ -114,17 +105,15 @@ const useDateInputs = () => {
114
105
  }
115
106
 
116
107
  if (!Number.isNaN(monthStringConvertedToInteger) && (key === '-' || key === '/' || key === '\\')) {
117
- var _dayInputRef$current2, _dayInputRef$current3;
118
-
119
108
  const newMonth = stringHelpers.prependStringWithPlaceHolders("".concat(monthStringConvertedToInteger), 2);
120
109
  handleChangeMonth(newMonth, e); // auto-advance functionality:
121
110
 
122
- if (newMonth.length === 2) dayInputRef === null || dayInputRef === void 0 ? void 0 : (_dayInputRef$current2 = dayInputRef.current) === null || _dayInputRef$current2 === void 0 ? void 0 : (_dayInputRef$current3 = _dayInputRef$current2.focus) === null || _dayInputRef$current3 === void 0 ? void 0 : _dayInputRef$current3.call(_dayInputRef$current2);
111
+ if (newMonth.length === 2) trackFocusDayInput();
123
112
  } // focus last fragment on fill with now
124
113
 
125
114
 
126
- if ((ctrlKey || metaKey) && key === ';') lastSegmentRef === null || lastSegmentRef === void 0 ? void 0 : (_lastSegmentRef$curre = lastSegmentRef.current) === null || _lastSegmentRef$curre === void 0 ? void 0 : (_lastSegmentRef$curre2 = _lastSegmentRef$curre.focus) === null || _lastSegmentRef$curre2 === void 0 ? void 0 : _lastSegmentRef$curre2.call(_lastSegmentRef$curre);
127
- }, [month, onHomeKeyDown, onEndKeyDown, lastSegmentRef, handleChangeMonth, dayInputRef]);
115
+ if ((ctrlKey || metaKey) && key === ';') trackFocusLastSegment();
116
+ }, [month, onHomeKeyDown, onEndKeyDown, trackFocusLastSegment, trackFocusDayInput, handleChangeMonth]);
128
117
  const onMonthBlur = React.useCallback(e => {
129
118
  var _e$target2;
130
119
 
@@ -151,29 +140,27 @@ const useDateInputs = () => {
151
140
  handleChangeComposedDateString(newDateString, finalMetaInfo);
152
141
  }, [month, year, getIsOutOfRangeDay, getIsDisabledDay, appOnDayChange, handleChangeComposedDateString]);
153
142
  const onDayFocus = React.useCallback(() => {
154
- setLatestInteractionRegionDateInputs();
155
- }, [setLatestInteractionRegionDateInputs]);
143
+ trackFocusDayInput();
144
+ }, [trackFocusDayInput]);
156
145
  const onDayChange = React.useCallback(e => {
157
- var _e$target3, _yearInputRef$current3, _yearInputRef$current4;
146
+ var _e$target3;
158
147
 
159
148
  let newDay = e === null || e === void 0 ? void 0 : (_e$target3 = e.target) === null || _e$target3 === void 0 ? void 0 : _e$target3.value; // converts days 4~9 to 04~09
160
149
 
161
150
  if (Number.parseInt(newDay, 10) > 3) newDay = stringHelpers.prependStringWithPlaceHolders(newDay, 2);
162
151
  handleChangeDay(newDay, e); // auto-advance functionality:
163
152
 
164
- if (newDay.length === 2) yearInputRef === null || yearInputRef === void 0 ? void 0 : (_yearInputRef$current3 = yearInputRef.current) === null || _yearInputRef$current3 === void 0 ? void 0 : (_yearInputRef$current4 = _yearInputRef$current3.focus) === null || _yearInputRef$current4 === void 0 ? void 0 : _yearInputRef$current4.call(_yearInputRef$current3);
165
- }, [handleChangeDay, yearInputRef]);
153
+ if (newDay.length === 2) trackFocusYearInput();
154
+ }, [handleChangeDay, trackFocusYearInput]);
166
155
  const onDayKeyDown = React.useCallback(e => {
167
- var _lastSegmentRef$curre3, _lastSegmentRef$curre4;
168
-
169
156
  const {
170
157
  key,
171
158
  ctrlKey,
172
159
  metaKey
173
160
  } = e;
174
161
  const dayStringConvertedToInteger = Number.parseInt(day, 10);
175
- if (constants.homeEndArrowUpDownDashSlashesKeys.includes(key)) e.preventDefault();
176
- if (constants.homeEndArrowUpDownDashSlashesKeys.includes(key)) e.stopPropagation();
162
+ if (['Home', 'End', 'ArrowUp', 'ArrowDown', '-', '/', '\\'].includes(key)) e.preventDefault();
163
+ if (['Home', 'End', 'ArrowUp', 'ArrowDown', '-', '/', '\\'].includes(key)) e.stopPropagation();
177
164
  if (key === 'Home') onHomeKeyDown();
178
165
  if (key === 'End') onEndKeyDown();
179
166
 
@@ -186,24 +173,20 @@ const useDateInputs = () => {
186
173
  }
187
174
 
188
175
  if (!Number.isNaN(dayStringConvertedToInteger) && (key === '-' || key === '/' || key === '\\')) {
189
- var _yearInputRef$current5, _yearInputRef$current6;
190
-
191
176
  const newDay = stringHelpers.prependStringWithPlaceHolders("".concat(dayStringConvertedToInteger), 2);
192
177
  handleChangeDay(newDay, e); // auto-advance functionality:
193
178
 
194
- if (newDay.length === 2) yearInputRef === null || yearInputRef === void 0 ? void 0 : (_yearInputRef$current5 = yearInputRef.current) === null || _yearInputRef$current5 === void 0 ? void 0 : (_yearInputRef$current6 = _yearInputRef$current5.focus) === null || _yearInputRef$current6 === void 0 ? void 0 : _yearInputRef$current6.call(_yearInputRef$current5);
179
+ if (newDay.length === 2) trackFocusYearInput();
195
180
  } // regressive backspace functionality
196
181
 
197
182
 
198
183
  if (key === 'Backspace' && (day === null || day === void 0 ? void 0 : day.length) === 0) {
199
- var _monthInputRef$curren3, _monthInputRef$curren4;
200
-
201
- monthInputRef === null || monthInputRef === void 0 ? void 0 : (_monthInputRef$curren3 = monthInputRef.current) === null || _monthInputRef$curren3 === void 0 ? void 0 : (_monthInputRef$curren4 = _monthInputRef$curren3.focus) === null || _monthInputRef$curren4 === void 0 ? void 0 : _monthInputRef$curren4.call(_monthInputRef$curren3);
184
+ trackFocusMonthInput();
202
185
  } // focus last fragment on fill with now
203
186
 
204
187
 
205
- if ((ctrlKey || metaKey) && key === ';') lastSegmentRef === null || lastSegmentRef === void 0 ? void 0 : (_lastSegmentRef$curre3 = lastSegmentRef.current) === null || _lastSegmentRef$curre3 === void 0 ? void 0 : (_lastSegmentRef$curre4 = _lastSegmentRef$curre3.focus) === null || _lastSegmentRef$curre4 === void 0 ? void 0 : _lastSegmentRef$curre4.call(_lastSegmentRef$curre3);
206
- }, [day, onHomeKeyDown, onEndKeyDown, lastSegmentRef, handleChangeDay, yearInputRef, monthInputRef]);
188
+ if ((ctrlKey || metaKey) && key === ';') trackFocusLastSegment();
189
+ }, [day, onHomeKeyDown, onEndKeyDown, trackFocusLastSegment, handleChangeDay, trackFocusYearInput, trackFocusMonthInput]);
207
190
  const onDayBlur = React.useCallback(e => {
208
191
  var _e$target4;
209
192
 
@@ -230,8 +213,8 @@ const useDateInputs = () => {
230
213
  handleChangeComposedDateString(newDateString, finalMetaInfo);
231
214
  }, [month, day, getIsOutOfRangeDay, getIsDisabledDay, appOnYearChange, handleChangeComposedDateString]);
232
215
  const onYearFocus = React.useCallback(() => {
233
- setLatestInteractionRegionDateInputs();
234
- }, [setLatestInteractionRegionDateInputs]);
216
+ trackFocusYearInput();
217
+ }, [trackFocusYearInput]);
235
218
  const onYearChange = React.useCallback(e => {
236
219
  var _e$target5;
237
220
 
@@ -239,70 +222,68 @@ const useDateInputs = () => {
239
222
  handleChangeYear(newYear, e); // auto-advance functionality:
240
223
 
241
224
  if (newYear.length === 4) {
242
- var _hourInputRef$current, _hourInputRef$current2;
243
-
244
- if (!hideTime) hourInputRef === null || hourInputRef === void 0 ? void 0 : (_hourInputRef$current = hourInputRef.current) === null || _hourInputRef$current === void 0 ? void 0 : (_hourInputRef$current2 = _hourInputRef$current.focus) === null || _hourInputRef$current2 === void 0 ? void 0 : _hourInputRef$current2.call(_hourInputRef$current);else if (withAnyRightController) {
245
- var _clearButtonRef$curre3, _clearButtonRef$curre4, _pickerButtonRef$curr3, _pickerButtonRef$curr4;
246
-
247
- if (withClearBtn) (_clearButtonRef$curre3 = clearButtonRef.current) === null || _clearButtonRef$curre3 === void 0 ? void 0 : (_clearButtonRef$curre4 = _clearButtonRef$curre3.focus) === null || _clearButtonRef$curre4 === void 0 ? void 0 : _clearButtonRef$curre4.call(_clearButtonRef$curre3);else if (withAnyPicker) pickerButtonRef === null || pickerButtonRef === void 0 ? void 0 : (_pickerButtonRef$curr3 = pickerButtonRef.current) === null || _pickerButtonRef$curr3 === void 0 ? void 0 : (_pickerButtonRef$curr4 = _pickerButtonRef$curr3.focus) === null || _pickerButtonRef$curr4 === void 0 ? void 0 : _pickerButtonRef$curr4.call(_pickerButtonRef$curr3); // pending approval from Seda, check which one should be focused first...
225
+ if (!hideTime) trackFocusHourInput();else if (withAnyRightController) {
226
+ if (withClearBtn) trackFocusClearBtn();else if (withAnyPicker) trackFocusPicker(); // pending approval from Seda, check which one should be focused first...
248
227
  }
249
228
  }
250
- }, [handleChangeYear, hideTime, hourInputRef, withAnyRightController, withAnyPicker, pickerButtonRef, withClearBtn, clearButtonRef]);
229
+ }, [handleChangeYear, hideTime, trackFocusHourInput, withAnyRightController, withClearBtn, trackFocusClearBtn, withAnyPicker, trackFocusPicker]);
251
230
  const onYearKeyDown = React.useCallback(e => {
252
- var _lastSegmentRef$curre5, _lastSegmentRef$curre6;
253
-
254
231
  const {
255
232
  key,
256
233
  ctrlKey,
257
234
  metaKey
258
235
  } = e;
236
+ /* ****** New year value calculator logic ********* */
237
+
259
238
  const yearStringConvertedToInteger = Number.parseInt(year, 10);
260
- if (constants.homeEndArrowUpDownSpaceKeys.includes(key)) e.preventDefault();
261
- if (constants.homeEndArrowUpDownSpaceKeys.includes(key)) e.stopPropagation();
262
- if (key === 'Home') onHomeKeyDown();
263
- if (key === 'End') onEndKeyDown();
239
+ const yearInteger = Number.isNaN(yearStringConvertedToInteger) ? 0 : yearStringConvertedToInteger;
240
+ let newYear = yearInteger !== 0 ? stringHelpers.fillStringWithPlaceHolders("".concat(yearInteger), 4, '0') : '';
264
241
 
265
242
  if (key === 'ArrowUp' || key === 'ArrowDown') {
266
- const yearInteger = Number.isNaN(yearStringConvertedToInteger) ? 0 : yearStringConvertedToInteger;
267
- let newYear;
268
- if (key === 'ArrowUp') newYear = yearInteger + 1 <= 9999 ? yearInteger + 1 : yearInteger;else newYear = yearInteger - 1 > 0 ? yearInteger - 1 : 1;
269
- newYear = stringHelpers.prependStringWithPlaceHolders("".concat(newYear), 4);
270
- handleChangeYear(newYear, e);
243
+ let newYearInteger;
244
+ if (key === 'ArrowUp') newYearInteger = yearInteger + 1 <= 9999 ? yearInteger + 1 : yearInteger;else newYearInteger = yearInteger - 1 > 0 ? yearInteger - 1 : 1;
245
+ newYear = stringHelpers.prependStringWithPlaceHolders("".concat(newYearInteger), 4);
271
246
  }
272
247
 
273
- if (!Number.isNaN(yearStringConvertedToInteger) && key === ' ') {
274
- const newYear = stringHelpers.prependStringWithPlaceHolders("".concat(yearStringConvertedToInteger), 4);
275
- handleChangeYear(newYear, e); // auto-advance functionality:
248
+ const isAutomaticFillTrigger = newYear !== year && ['Tab', ' '].includes(key);
249
+ const metainfo = {
250
+ isAutomaticFillTrigger
251
+ };
252
+ /* ************* new year apply logic ************* */
253
+ // tab/spacebar applies auto-fill
254
+ // arrows up/down applies increment/decrement
276
255
 
277
- if (newYear.length === 4) {
278
- var _hourInputRef$current3, _hourInputRef$current4;
256
+ if (key === 'ArrowUp' || key === 'ArrowDown' || isAutomaticFillTrigger) {
257
+ handleChangeYear(newYear, e, metainfo);
258
+ }
259
+ /* ************* focus tracking logic ************* */
279
260
 
280
- if (!hideTime) hourInputRef === null || hourInputRef === void 0 ? void 0 : (_hourInputRef$current3 = hourInputRef.current) === null || _hourInputRef$current3 === void 0 ? void 0 : (_hourInputRef$current4 = _hourInputRef$current3.focus) === null || _hourInputRef$current4 === void 0 ? void 0 : _hourInputRef$current4.call(_hourInputRef$current3);else if (withAnyRightController) {
281
- var _clearButtonRef$curre5, _clearButtonRef$curre6, _pickerButtonRef$curr5, _pickerButtonRef$curr6;
282
261
 
283
- if (withClearBtn) (_clearButtonRef$curre5 = clearButtonRef.current) === null || _clearButtonRef$curre5 === void 0 ? void 0 : (_clearButtonRef$curre6 = _clearButtonRef$curre5.focus) === null || _clearButtonRef$curre6 === void 0 ? void 0 : _clearButtonRef$curre6.call(_clearButtonRef$curre5);else if (withAnyPicker) pickerButtonRef === null || pickerButtonRef === void 0 ? void 0 : (_pickerButtonRef$curr5 = pickerButtonRef.current) === null || _pickerButtonRef$curr5 === void 0 ? void 0 : (_pickerButtonRef$curr6 = _pickerButtonRef$curr5.focus) === null || _pickerButtonRef$curr6 === void 0 ? void 0 : _pickerButtonRef$curr6.call(_pickerButtonRef$curr5); // pending approval from Seda, check which one should be focused first...
284
- }
285
- }
286
- } // regressive backspace functionality
262
+ let trackNextFocus = trackFocusResetter; // if nothing after, we reset internal focus tracker to avoid re-render unexpected focus shift
287
263
 
264
+ if (!hideTime) trackNextFocus = trackFocusHourInput;else if (withClearBtn) trackNextFocus = trackFocusClearBtn;else if (withAnyPicker) trackNextFocus = trackFocusPicker;
265
+ if (['Home', 'End', 'ArrowUp', 'ArrowDown', ' '].includes(key)) e.preventDefault();
266
+ if (['Home', 'End', 'ArrowUp', 'ArrowDown', ' '].includes(key)) e.stopPropagation();
267
+ if (key === 'Home') onHomeKeyDown();
268
+ if (key === 'End') onEndKeyDown();
269
+ /* ************** auto-advance logic ************** */
288
270
 
289
- if (key === 'Backspace' && (year === null || year === void 0 ? void 0 : year.length) === 0) {
290
- var _dayInputRef$current4, _dayInputRef$current5;
271
+ if (key === ' ') {
272
+ // auto-advance functionality:
273
+ trackNextFocus();
274
+ }
275
+ /* ********** regressive backspace logic ********** */
291
276
 
292
- dayInputRef === null || dayInputRef === void 0 ? void 0 : (_dayInputRef$current4 = dayInputRef.current) === null || _dayInputRef$current4 === void 0 ? void 0 : (_dayInputRef$current5 = _dayInputRef$current4.focus) === null || _dayInputRef$current5 === void 0 ? void 0 : _dayInputRef$current5.call(_dayInputRef$current4);
293
- } // focus last fragment on fill with now
294
277
 
278
+ if (key === 'Backspace' && (year === null || year === void 0 ? void 0 : year.length) === 0) {
279
+ trackFocusDayInput();
280
+ } // focus last fragment on fill with now
295
281
 
296
- if ((ctrlKey || metaKey) && key === ';') lastSegmentRef === null || lastSegmentRef === void 0 ? void 0 : (_lastSegmentRef$curre5 = lastSegmentRef.current) === null || _lastSegmentRef$curre5 === void 0 ? void 0 : (_lastSegmentRef$curre6 = _lastSegmentRef$curre5.focus) === null || _lastSegmentRef$curre6 === void 0 ? void 0 : _lastSegmentRef$curre6.call(_lastSegmentRef$curre5);
297
- }, [year, onHomeKeyDown, onEndKeyDown, lastSegmentRef, handleChangeYear, hideTime, hourInputRef, withAnyRightController, withClearBtn, clearButtonRef, withAnyPicker, pickerButtonRef, dayInputRef]);
298
- const onYearBlur = React.useCallback(e => {
299
- var _e$target6;
300
282
 
301
- const newYear = e === null || e === void 0 ? void 0 : (_e$target6 = e.target) === null || _e$target6 === void 0 ? void 0 : _e$target6.value;
302
- if (newYear.length > 0 && newYear.length < 4) handleChangeYear(stringHelpers.fillStringWithPlaceHolders(newYear, 4, '0'), e, {
303
- isAutomaticFillTrigger: true
304
- });
305
- }, [handleChangeYear]);
283
+ if ((ctrlKey || metaKey) && key === ';') trackFocusLastSegment();
284
+ }, [year, trackFocusResetter, hideTime, trackFocusHourInput, withClearBtn, trackFocusClearBtn, withAnyPicker, trackFocusPicker, onHomeKeyDown, onEndKeyDown, trackFocusLastSegment, trackFocusDayInput, handleChangeYear]);
285
+ const onYearBlur = React.useCallback(() => {// this was used before, now that we have a wrapping onBlur resetting the focus tracker, this is unused;
286
+ }, []);
306
287
  return React.useMemo(() => ({
307
288
  month,
308
289
  day,
@@ -49,14 +49,40 @@ const CalendarHead = () => {
49
49
  prevYearBtnRef,
50
50
  prevMonthBtnRef,
51
51
  nextMonthBtnRef,
52
- nextYearBtnRef
52
+ nextYearBtnRef,
53
+ latestInteractionRegion,
54
+ currFocusDescriber
53
55
  } = React.useContext(ControlledDateTimePickerCTX.ControlledDateTimePickerContext);
56
+ const handlePrevYearRef = React.useCallback(ButtonDomNode => {
57
+ var _ButtonDomNode$focus;
58
+
59
+ prevYearBtnRef.current = ButtonDomNode;
60
+ if (latestInteractionRegion === 'calendar-head' && currFocusDescriber === 'calendar-prev-year') ButtonDomNode === null || ButtonDomNode === void 0 ? void 0 : (_ButtonDomNode$focus = ButtonDomNode.focus) === null || _ButtonDomNode$focus === void 0 ? void 0 : _ButtonDomNode$focus.call(ButtonDomNode);
61
+ }, [currFocusDescriber, latestInteractionRegion, prevYearBtnRef]);
62
+ const handlePrevMonthRef = React.useCallback(ButtonDomNode => {
63
+ var _ButtonDomNode$focus2;
64
+
65
+ prevMonthBtnRef.current = ButtonDomNode;
66
+ if (latestInteractionRegion === 'calendar-head' && currFocusDescriber === 'calendar-prev-month') ButtonDomNode === null || ButtonDomNode === void 0 ? void 0 : (_ButtonDomNode$focus2 = ButtonDomNode.focus) === null || _ButtonDomNode$focus2 === void 0 ? void 0 : _ButtonDomNode$focus2.call(ButtonDomNode);
67
+ }, [currFocusDescriber, latestInteractionRegion, prevMonthBtnRef]);
68
+ const handleNextMonthRef = React.useCallback(ButtonDomNode => {
69
+ var _ButtonDomNode$focus3;
70
+
71
+ nextMonthBtnRef.current = ButtonDomNode;
72
+ if (latestInteractionRegion === 'calendar-head' && currFocusDescriber === 'calendar-next-month') ButtonDomNode === null || ButtonDomNode === void 0 ? void 0 : (_ButtonDomNode$focus3 = ButtonDomNode.focus) === null || _ButtonDomNode$focus3 === void 0 ? void 0 : _ButtonDomNode$focus3.call(ButtonDomNode);
73
+ }, [currFocusDescriber, latestInteractionRegion, nextMonthBtnRef]);
74
+ const handleNextYearRef = React.useCallback(ButtonDomNode => {
75
+ var _ButtonDomNode$focus4;
76
+
77
+ nextYearBtnRef.current = ButtonDomNode;
78
+ if (latestInteractionRegion === 'calendar-head' && currFocusDescriber === 'calendar-next-year') ButtonDomNode === null || ButtonDomNode === void 0 ? void 0 : (_ButtonDomNode$focus4 = ButtonDomNode.focus) === null || _ButtonDomNode$focus4 === void 0 ? void 0 : _ButtonDomNode$focus4.call(ButtonDomNode);
79
+ }, [currFocusDescriber, latestInteractionRegion, nextYearBtnRef]);
54
80
  return /*#__PURE__*/_jsx__default["default"](Styleds.StyledHeader, {}, void 0, /*#__PURE__*/_jsx__default["default"](Styleds.StyledHeaderButton, {
55
81
  "aria-label": "previous year",
56
82
  buttonType: "raw",
57
83
  size: DSButton.BUTTON_SIZES.M,
58
84
  onClick: handlePrevYear,
59
- innerRef: prevYearBtnRef,
85
+ innerRef: handlePrevYearRef,
60
86
  onKeyDown: handlePrevYearKeyDown,
61
87
  onFocus: onPrevYearFocus,
62
88
  tabIndex: isControllerOnly ? -1 : 1,
@@ -71,7 +97,7 @@ const CalendarHead = () => {
71
97
  buttonType: "raw",
72
98
  size: DSButton.BUTTON_SIZES.M,
73
99
  onClick: handlePrevMonth,
74
- innerRef: prevMonthBtnRef,
100
+ innerRef: handlePrevMonthRef,
75
101
  onKeyDown: handlePrevMonthKeyDown,
76
102
  onFocus: onPrevMonthFocus,
77
103
  "data-testid": ControlledDateTimePickerDatatestid.ControlledDateTimePickerDatatestid.CALENDAR.PREV_MONTH // this is a tabstop for when the calendar is open
@@ -83,7 +109,7 @@ const CalendarHead = () => {
83
109
  buttonType: "raw",
84
110
  size: DSButton.BUTTON_SIZES.M,
85
111
  onClick: handleNextMonth,
86
- innerRef: nextMonthBtnRef,
112
+ innerRef: handleNextMonthRef,
87
113
  onKeyDown: handleNextMonthKeyDown,
88
114
  onFocus: onNextMonthFocus,
89
115
  "data-testid": ControlledDateTimePickerDatatestid.ControlledDateTimePickerDatatestid.CALENDAR.NEXT_MONTH
@@ -94,7 +120,7 @@ const CalendarHead = () => {
94
120
  buttonType: "raw",
95
121
  size: DSButton.BUTTON_SIZES.M,
96
122
  onClick: handleNextYear,
97
- innerRef: nextYearBtnRef,
123
+ innerRef: handleNextYearRef,
98
124
  onKeyDown: handleNextYearKeyDown,
99
125
  onFocus: onNextYearFocus,
100
126
  "data-testid": ControlledDateTimePickerDatatestid.ControlledDateTimePickerDatatestid.CALENDAR.NEXT_YEAR
@@ -58,15 +58,14 @@ const Day = _ref => {
58
58
  appOnDayChange,
59
59
  appOnYearChange,
60
60
  latestInteractionRegion,
61
- setLatestInteractionRegion,
62
- isWithTimeWheelToo
61
+ isWithTimeWheelToo,
62
+ trackFocusCalendarMetafocusedDay
63
63
  } = React.useContext(ControlledDateTimePickerCTX.ControlledDateTimePickerContext);
64
64
  const {
65
65
  focusedDay,
66
66
  handleDayOnKeyDown,
67
67
  handleFocusMetaDayByDay,
68
- closeCalendar,
69
- tryToFocusCurrentlyDataIsFocusedDay
68
+ closeCalendar
70
69
  } = React.useContext(CalendarContext.CalendarContext);
71
70
  const isFocusedMetaDay = focusedDay !== null && focusedDay !== void 0 && focusedDay.day ? dateHelpers.compareTwoDatesDayEquality(metaDay === null || metaDay === void 0 ? void 0 : metaDay.day, focusedDay === null || focusedDay === void 0 ? void 0 : focusedDay.day) : false;
72
71
  const isSelected = React.useMemo(() => {
@@ -81,7 +80,6 @@ const Day = _ref => {
81
80
  const isDayInRange = !isStartRangeDay && !isEndRangeDay && getIsDayInRange(metaDay.dayAsString);
82
81
  const handleOnDayClick = React.useCallback(e => {
83
82
  handleFocusMetaDayByDay(day);
84
- tryToFocusCurrentlyDataIsFocusedDay();
85
83
 
86
84
  if (!isDisabled && !isOutOfRange) {
87
85
  const newDateString = dateHelpers.getDateStringFromDay(day);
@@ -99,13 +97,21 @@ const Day = _ref => {
99
97
  if (dayNumber) appOnDayChange("".concat(dayNumber), e, metaInfo);
100
98
  appOnYearChange("".concat(year), e, metaInfo);
101
99
  handleChangeComposedDateString(newDateString, metaInfo);
102
- setLatestInteractionRegion('calendar-days');
100
+ trackFocusCalendarMetafocusedDay();
103
101
  if (!isWithTimeWheelToo && !preventCloseOnSelection) closeCalendar();
104
102
  }
105
- }, [isDisabled, isOutOfRange, day, appOnMonthChange, appOnDayChange, appOnYearChange, handleChangeComposedDateString, handleFocusMetaDayByDay, tryToFocusCurrentlyDataIsFocusedDay, setLatestInteractionRegion, isWithTimeWheelToo, preventCloseOnSelection, closeCalendar]);
103
+ }, [handleFocusMetaDayByDay, day, isDisabled, isOutOfRange, appOnMonthChange, appOnDayChange, appOnYearChange, handleChangeComposedDateString, trackFocusCalendarMetafocusedDay, isWithTimeWheelToo, preventCloseOnSelection, closeCalendar]);
104
+ const handleInnerRef = React.useCallback(ButtonDomNode => {
105
+ window.requestAnimationFrame(() => {
106
+ var _ButtonDomNode$focus;
107
+
108
+ dayBtnRef.current = ButtonDomNode;
109
+ if (isFocused) ButtonDomNode === null || ButtonDomNode === void 0 ? void 0 : (_ButtonDomNode$focus = ButtonDomNode.focus) === null || _ButtonDomNode$focus === void 0 ? void 0 : _ButtonDomNode$focus.call(ButtonDomNode);
110
+ });
111
+ }, [dayBtnRef, isFocused]);
106
112
  const handleOnDayFocus = React.useCallback(() => {
107
- setLatestInteractionRegion('calendar-days');
108
- }, [setLatestInteractionRegion]);
113
+ trackFocusCalendarMetafocusedDay('calendar-days');
114
+ }, [trackFocusCalendarMetafocusedDay]);
109
115
  const dayClassModifiers = React.useMemo(() => "dayWrapper ".concat(isSelected ? 'selectedDay ' : '').concat(isDisabled ? 'disabledDay ' : '').concat(isOutOfRange ? 'outOfRangeDay ' : '').concat(isFocused ? 'focusedDay ' : '').concat(isStartRangeDay ? 'startRangeDay ' : '').concat(isDayInRange ? 'inRangeDay ' : '').concat(isEndRangeDay ? 'endRangeDay ' : '').concat(isCurrMonthDay ? '' : 'notCurrentMonth'), [isSelected, isDisabled, isOutOfRange, isFocused, isStartRangeDay, isDayInRange, isEndRangeDay, isCurrMonthDay]);
110
116
  let dataTestid = ControlledDateTimePickerDatatestid.ControlledDateTimePickerDatatestid.CALENDAR.DAY;
111
117
  if (isSelected) dataTestid = ControlledDateTimePickerDatatestid.ControlledDateTimePickerDatatestid.CALENDAR.SELECTED_DAY;
@@ -133,7 +139,7 @@ const Day = _ref => {
133
139
  onKeyDown: e => {
134
140
  handleDayOnKeyDown(e, metaDay);
135
141
  },
136
- innerRef: dayBtnRef,
142
+ innerRef: handleInnerRef,
137
143
  tabIndex: isSelected ? 0 : -1,
138
144
  "data-isfocused": isFocused,
139
145
  "data-testid": dataTestid
@@ -25,24 +25,24 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
25
25
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
26
26
  const useConfigCalendarCTX = () => {
27
27
  const {
28
- setLatestInteractionRegion
28
+ trackFocusCalendarPrevYear,
29
+ trackFocusCalendarNextYear,
30
+ trackFocusCalendarPrevMonth,
31
+ trackFocusCalendarNextMonth
29
32
  } = React.useContext(ControlledDateTimePickerCTX.ControlledDateTimePickerContext);
30
33
  const [showCalendar, setShowCalendar] = React.useState(false);
31
- const setLatestInteractionRegionCalendarHead = React.useCallback(() => {
32
- setLatestInteractionRegion('calendar-head');
33
- }, [setLatestInteractionRegion]);
34
34
  const onPrevYearFocus = React.useCallback(() => {
35
- setLatestInteractionRegionCalendarHead();
36
- }, [setLatestInteractionRegionCalendarHead]);
35
+ trackFocusCalendarPrevYear();
36
+ }, [trackFocusCalendarPrevYear]);
37
37
  const onPrevMonthFocus = React.useCallback(() => {
38
- setLatestInteractionRegionCalendarHead();
39
- }, [setLatestInteractionRegionCalendarHead]);
38
+ trackFocusCalendarPrevMonth();
39
+ }, [trackFocusCalendarPrevMonth]);
40
40
  const onNextMonthFocus = React.useCallback(() => {
41
- setLatestInteractionRegionCalendarHead();
42
- }, [setLatestInteractionRegionCalendarHead]);
41
+ trackFocusCalendarNextMonth();
42
+ }, [trackFocusCalendarNextMonth]);
43
43
  const onNextYearFocus = React.useCallback(() => {
44
- setLatestInteractionRegionCalendarHead();
45
- }, [setLatestInteractionRegionCalendarHead]);
44
+ trackFocusCalendarNextYear();
45
+ }, [trackFocusCalendarNextYear]);
46
46
  const currentDisplayedMonthLogic = useCurrentDisplayedMonthYearLogic.useCurrentDisplayedMonthYearLogic();
47
47
  const focusLogic = useFocusLogic.useFocusLogic({
48
48
  currentDisplayedMonthLogic,
@@ -7,31 +7,13 @@ require('core-js/modules/esnext.async-iterator.find.js');
7
7
  require('core-js/modules/esnext.iterator.constructor.js');
8
8
  require('core-js/modules/esnext.iterator.find.js');
9
9
  var React = require('react');
10
- var ControlledDateTimePickerCTX = require('../../../ControlledDateTimePickerCTX.js');
11
10
  var dateHelpers = require('../../../utils/dateHelpers.js');
12
11
  var useGetStartingFocusedDay = require('../../../utils/hooks/useGetStartingFocusedDay.js');
13
12
 
14
- // eslint-disable-next-line max-params
15
- const loopWhileWaiting = function (cb) {
16
- let shortcircuit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => false;
17
- let timePerTry = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
18
- let maxTries = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 5;
19
- let ab = maxTries;
20
- const inter = setInterval(() => {
21
- cb();
22
- if (shortcircuit() || ab === 0) clearInterval(inter);
23
- ab -= 1;
24
- }, timePerTry);
25
- };
26
-
27
13
  const useFocusLogic = _ref => {
28
14
  let {
29
- currentDisplayedMonthLogic,
30
- showCalendar
15
+ currentDisplayedMonthLogic
31
16
  } = _ref;
32
- const {
33
- calendarDaysWrapperRef
34
- } = React.useContext(ControlledDateTimePickerCTX.ControlledDateTimePickerContext);
35
17
  const {
36
18
  daysArray
37
19
  } = currentDisplayedMonthLogic;
@@ -63,23 +45,6 @@ const useFocusLogic = _ref => {
63
45
  });
64
46
  return newFocusedDay;
65
47
  }, [daysArray, startFocusedDate, metadayToFocus]);
66
- const tryToFocusCurrentlyDataIsFocusedDay = React.useCallback(function () {
67
- let wrapperDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (calendarDaysWrapperRef === null || calendarDaysWrapperRef === void 0 ? void 0 : calendarDaysWrapperRef.current) || document;
68
- let shortcircuit = false;
69
- loopWhileWaiting(() => {
70
- const domElem = wrapperDOM === null || wrapperDOM === void 0 ? void 0 : wrapperDOM.querySelector('[data-isfocused="true"]');
71
-
72
- if (domElem) {
73
- var _domElem$focus;
74
-
75
- domElem === null || domElem === void 0 ? void 0 : (_domElem$focus = domElem.focus) === null || _domElem$focus === void 0 ? void 0 : _domElem$focus.call(domElem);
76
- shortcircuit = true;
77
- }
78
- }, () => shortcircuit);
79
- }, [calendarDaysWrapperRef]);
80
- React.useLayoutEffect(() => {
81
- if (showCalendar) tryToFocusCurrentlyDataIsFocusedDay(calendarDaysWrapperRef === null || calendarDaysWrapperRef === void 0 ? void 0 : calendarDaysWrapperRef.current);
82
- }, [calendarDaysWrapperRef, focusedDay, showCalendar, tryToFocusCurrentlyDataIsFocusedDay]);
83
48
  const handleFocusMetaDay = React.useCallback(metaDayToFocus => {
84
49
  // if focusedDay is inside current daysArray we set Focused day
85
50
  const newFocusedMetaDay = daysArray.find(_ref5 => {
@@ -105,11 +70,10 @@ const useFocusLogic = _ref => {
105
70
  }, []);
106
71
  return React.useMemo(() => ({
107
72
  focusedDay,
108
- tryToFocusCurrentlyDataIsFocusedDay,
109
73
  resetFocusedDayToStartDate,
110
74
  handleFocusMetaDay,
111
75
  handleFocusMetaDayByDay
112
- }), [focusedDay, tryToFocusCurrentlyDataIsFocusedDay, resetFocusedDayToStartDate, handleFocusMetaDay, handleFocusMetaDayByDay]);
76
+ }), [focusedDay, resetFocusedDayToStartDate, handleFocusMetaDay, handleFocusMetaDayByDay]);
113
77
  };
114
78
 
115
79
  exports.useFocusLogic = useFocusLogic;