@elliemae/ds-controlled-form 2.4.1 → 2.4.2-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) 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 +3 -5
  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 +8 -6
  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-range-picker/config/useRangePickerLogic.js +2 -2
  106. package/esm/date-time-picker/config/useChangeHandlers.js +8 -12
  107. package/esm/date-time-picker/config/useControlledDateTimePicker.js +13 -9
  108. package/esm/date-time-picker/config/useFocusTracker.js +132 -0
  109. package/esm/date-time-picker/config/useGetReferences.js +41 -20
  110. package/esm/date-time-picker/config/useGlobalKeyHandlers.js +8 -12
  111. package/esm/date-time-picker/parts/ClearButton/ClearButton.js +12 -2
  112. package/esm/date-time-picker/parts/ClearButton/useClearButton.js +12 -25
  113. package/esm/date-time-picker/parts/ControlledDateTimePickerContent.js +4 -7
  114. package/esm/date-time-picker/parts/DateInputs/DDInput.js +8 -2
  115. package/esm/date-time-picker/parts/DateInputs/DateInputs.js +9 -4
  116. package/esm/date-time-picker/parts/DateInputs/MMInput.js +8 -2
  117. package/esm/date-time-picker/parts/DateInputs/YYYYInput.js +8 -2
  118. package/esm/date-time-picker/parts/DateInputs/useDateInputs.js +77 -96
  119. package/esm/date-time-picker/parts/Pickers/Calendar/CalendarHead.js +32 -6
  120. package/esm/date-time-picker/parts/Pickers/Calendar/Day.js +16 -10
  121. package/esm/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.js +14 -14
  122. package/esm/date-time-picker/parts/Pickers/Calendar/useFocusLogic.js +3 -39
  123. package/esm/date-time-picker/parts/Pickers/Calendar/useKeyboardHandlers.js +40 -73
  124. package/esm/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.js +18 -27
  125. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/CalendarWithTimeWheelIconTrigger.js +1 -0
  126. package/esm/date-time-picker/parts/Pickers/CalendarWithTimeWheel/useConfigCalendarWithTimeWheelCTX.js +17 -23
  127. package/esm/date-time-picker/parts/Pickers/TimeWheel/HoursList.js +14 -8
  128. package/esm/date-time-picker/parts/Pickers/TimeWheel/MeridiemList.js +15 -9
  129. package/esm/date-time-picker/parts/Pickers/TimeWheel/MinutesList.js +14 -8
  130. package/esm/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.js +36 -230
  131. package/esm/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.js +11 -13
  132. package/esm/date-time-picker/parts/TimeInputs/HHInput.js +8 -2
  133. package/esm/date-time-picker/parts/TimeInputs/MeridiemInput.js +8 -2
  134. package/esm/date-time-picker/parts/TimeInputs/MinutesInput.js +8 -2
  135. package/esm/date-time-picker/parts/TimeInputs/TimeInputs.js +11 -6
  136. package/esm/date-time-picker/parts/TimeInputs/useTimeInputs.js +44 -74
  137. package/esm/date-time-picker/utils/constants.js +1 -7
  138. package/esm/date-time-picker/utils/hooks/useGetStartingFocusedDay.js +38 -36
  139. package/esm/index.js +5 -1
  140. package/esm/input-group/InputGroup.js +59 -0
  141. package/esm/input-group/InputGroupDataTestIds.js +8 -0
  142. package/esm/input-group/index.js +2 -0
  143. package/esm/input-group/react-desc-prop-types.js +10 -0
  144. package/esm/input-group/styled.js +35 -0
  145. package/esm/mask-hook/hooks/index.js +1 -1
  146. package/esm/mask-hook/hooks/usePhoneMask.js +2 -2
  147. package/esm/mask-hook/hooks/useRegExpMask.js +1 -1
  148. package/esm/mask-hook/index.js +1 -1
  149. package/esm/text-input/styled/borders.js +1 -1
  150. package/esm/toggle/ControlledToggle.js +3 -3
  151. package/package.json +55 -19
  152. package/types/checkbox/exported-related/data-test-ids.d.ts +4 -0
  153. package/types/checkbox/exported-related/index.d.ts +2 -0
  154. package/types/checkbox/exported-related/theming.d.ts +6 -0
  155. package/types/checkbox/react-desc-prop-types.d.ts +3 -3
  156. package/types/checkbox/styles.d.ts +5 -5
  157. package/types/combobox/ComboboxDataTestids.d.ts +1 -1
  158. package/types/combobox/index.d.ts +2 -0
  159. package/types/combobox/parts/container/styled.d.ts +1 -2
  160. package/types/combobox/theming.d.ts +6 -0
  161. package/types/date-time-picker/config/useChangeHandlers.d.ts +3 -1
  162. package/types/date-time-picker/config/useControlledDateTimePicker.d.ts +2 -5
  163. package/types/date-time-picker/config/useFocusTracker.d.ts +38 -0
  164. package/types/date-time-picker/config/useGetPropsBasedOnType.d.ts +6 -6
  165. package/types/date-time-picker/config/useGetReferences.d.ts +30 -36
  166. package/types/date-time-picker/config/useGlobalKeyHandlers.d.ts +3 -1
  167. package/types/date-time-picker/parts/DateInputs/DDInput.d.ts +2 -1
  168. package/types/date-time-picker/parts/DateInputs/MMInput.d.ts +2 -1
  169. package/types/date-time-picker/parts/DateInputs/YYYYInput.d.ts +2 -1
  170. package/types/date-time-picker/parts/Pickers/Calendar/useConfigCalendarCTX.d.ts +14 -0
  171. package/types/date-time-picker/parts/Pickers/Calendar/useFocusLogic.d.ts +1 -2
  172. package/types/date-time-picker/parts/Pickers/Calendar/usePopperTriggerLogic.d.ts +19 -0
  173. package/types/date-time-picker/parts/Pickers/TimeWheel/useKeyboardHandlers.d.ts +0 -6
  174. package/types/date-time-picker/parts/Pickers/TimeWheel/usePopperTriggerLogic.d.ts +14 -0
  175. package/types/date-time-picker/parts/TimeInputs/HHInput.d.ts +2 -1
  176. package/types/date-time-picker/parts/TimeInputs/MeridiemInput.d.ts +2 -1
  177. package/types/date-time-picker/parts/TimeInputs/MinutesInput.d.ts +2 -1
  178. package/types/date-time-picker/propTypes.d.ts +117 -0
  179. package/types/date-time-picker/sharedTypes.d.ts +1 -1
  180. package/types/date-time-picker/utils/constants.d.ts +0 -6
  181. package/types/index.d.ts +1 -0
  182. package/types/input-group/InputGroup.d.ts +5 -0
  183. package/types/input-group/InputGroupDataTestIds.d.ts +6 -0
  184. package/types/input-group/index.d.ts +2 -0
  185. package/types/input-group/react-desc-prop-types.d.ts +19 -0
  186. package/types/input-group/styled.d.ts +7 -0
  187. package/types/input-group/tests/DSInputGroup.test.d.ts +1 -0
  188. package/types/mask-hook/hooks/useRegExpMask.d.ts +0 -1
  189. package/types/text-input/config/useInputText.d.ts +5 -5
  190. package/cjs/combobox/parts/menu-list/useMenuListSetFocusOption.js +0 -51
  191. package/esm/combobox/parts/menu-list/useMenuListSetFocusOption.js +0 -47
  192. package/types/combobox/parts/menu-list/useMenuListSetFocusOption.d.ts +0 -1
@@ -1,14 +1,20 @@
1
- import { useRef, useMemo } from 'react';
1
+ import 'core-js/modules/web.dom-collections.iterator.js';
2
+ import { useState, useRef, useMemo } from 'react';
2
3
 
3
- /* eslint-disable complexity */
4
4
  const useGetReferences = _ref => {
5
5
  let {
6
6
  isWithDateInputs,
7
7
  isWithTimeInputs,
8
+ isDateSelector,
9
+ isTimeSelector,
10
+ isDateTimeSelector,
8
11
  withAnyPicker,
9
12
  withClearBtn
10
13
  } = _ref;
11
- // refs are used for "auto-advance" feature
14
+ // those 2 states are needed for focus tracking
15
+ const [firstSegment, setFirstSegment] = useState('');
16
+ const [lastSegment, setLastSegment] = useState(''); // refs are used for "auto-advance" feature
17
+
12
18
  const monthInputRef = useRef(null);
13
19
  const dayInputRef = useRef(null);
14
20
  const yearInputRef = useRef(null);
@@ -32,22 +38,38 @@ const useGetReferences = _ref => {
32
38
  const currMeridiemBtnRef = useRef(null);
33
39
  const nextMeridiemBtnRef = useRef(null);
34
40
  let firstSegmentRef = useRef(null);
35
- if (isWithDateInputs) firstSegmentRef = monthInputRef;else if (isWithTimeInputs) firstSegmentRef = hourInputRef;else if (withAnyPicker) firstSegmentRef = pickerButtonRef; // we need some non-ref to force refresh of the hooks dependencies when using firstSegmentRef
36
41
 
37
- const firstFragmentRefUpdateDeps = useMemo(() => ({
38
- isWithDateInputs,
39
- isWithTimeInputs,
40
- withAnyPicker
41
- }), [isWithDateInputs, isWithTimeInputs, withAnyPicker]);
42
+ if (isWithDateInputs) {
43
+ firstSegmentRef = monthInputRef;
44
+ if (firstSegment !== 'month-input') setFirstSegment('month-input');
45
+ } else if (isWithTimeInputs) {
46
+ firstSegmentRef = hourInputRef;
47
+ if (firstSegment !== 'hour-input') setFirstSegment('hour-input');
48
+ } else if (withAnyPicker) {
49
+ firstSegmentRef = pickerButtonRef;
50
+ if (isDateSelector && firstSegment !== 'date-picker-icon') setFirstSegment('date-picker-icon');
51
+ if (isTimeSelector && firstSegment !== 'time-picker-icon') setFirstSegment('time-picker-icon');
52
+ if (isDateTimeSelector && firstSegment !== 'datetime-picker-icon') setFirstSegment('datetime-picker-icon');
53
+ }
54
+
42
55
  let lastSegmentRef = useRef(null);
43
- if (withAnyPicker) lastSegmentRef = pickerButtonRef;else if (withClearBtn) lastSegmentRef = clearButtonRef;else if (isWithTimeInputs) lastSegmentRef = meridiemInputRef;else if (isWithDateInputs) lastSegmentRef = yearInputRef; // we need some non-ref to force refresh of the hooks dependencies when using lastSegmentRef
44
56
 
45
- const lastFragmentRefUpdateDeps = useMemo(() => ({
46
- withAnyPicker,
47
- withClearBtn,
48
- isWithTimeInputs,
49
- isWithDateInputs
50
- }), [isWithDateInputs, isWithTimeInputs, withAnyPicker, withClearBtn]);
57
+ if (withAnyPicker) {
58
+ lastSegmentRef = pickerButtonRef;
59
+ if (isDateSelector && lastSegment !== 'date-picker-icon') setLastSegment('date-picker-icon');
60
+ if (isTimeSelector && lastSegment !== 'time-picker-icon') setLastSegment('time-picker-icon');
61
+ if (isDateTimeSelector && lastSegment !== 'datetime-picker-icon') setLastSegment('datetime-picker-icon');
62
+ } else if (withClearBtn) {
63
+ lastSegmentRef = clearButtonRef;
64
+ if (lastSegment !== 'clear-btn') setLastSegment('clear-btn');
65
+ } else if (isWithTimeInputs) {
66
+ lastSegmentRef = meridiemInputRef;
67
+ if (lastSegment !== 'meridiem-input') setLastSegment('meridiem-input');
68
+ } else if (isWithDateInputs) {
69
+ lastSegmentRef = yearInputRef;
70
+ if (lastSegment !== 'year-input') setLastSegment('year-input');
71
+ }
72
+
51
73
  return useMemo(() => ({
52
74
  monthInputRef,
53
75
  dayInputRef,
@@ -73,10 +95,9 @@ const useGetReferences = _ref => {
73
95
  nextMeridiemBtnRef,
74
96
  firstSegmentRef,
75
97
  lastSegmentRef,
76
- firstFragmentRefUpdateDeps,
77
- lastFragmentRefUpdateDeps
78
- }), [firstFragmentRefUpdateDeps, lastFragmentRefUpdateDeps] // if we remove this last/first segment won't work
79
- );
98
+ firstSegment,
99
+ lastSegment
100
+ }), [firstSegment, lastSegment]);
80
101
  };
81
102
 
82
103
  export { useGetReferences };
@@ -16,8 +16,8 @@ const useGlobalKeyHandlers = _ref => {
16
16
  let {
17
17
  propsBasedOnType,
18
18
  changeHandlers,
19
- DOMRefs,
20
- flags
19
+ flags,
20
+ focusTrackers
21
21
  } = _ref;
22
22
  const {
23
23
  getIsOutOfRangeDay,
@@ -34,13 +34,13 @@ const useGlobalKeyHandlers = _ref => {
34
34
  handleChangeComposedDateTimeString,
35
35
  handleClearAll
36
36
  } = changeHandlers;
37
- const {
38
- lastSegmentRef,
39
- clearButtonRef
40
- } = DOMRefs;
41
37
  const {
42
38
  shouldPreserveClearableSpace
43
39
  } = flags;
40
+ const {
41
+ trackFocusClearBtn,
42
+ trackFocusLastSegment
43
+ } = focusTrackers;
44
44
  const onFillWithCurrentDateKeys = useCallback(function (e) {
45
45
  let metaInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
46
46
  isAutomaticFillTrigger: true
@@ -70,12 +70,8 @@ const useGlobalKeyHandlers = _ref => {
70
70
  appOnMinuteChange(minutes, e, metaInfo);
71
71
  appOnMeridiemChange(meridiem, e, metaInfo);
72
72
  handleChangeComposedDateTimeString(nowDateString, nowTimeString, finalMetaInfo);
73
- setTimeout(() => {
74
- var _clearButtonRef$curre, _lastSegmentRef$curre;
75
-
76
- if (shouldPreserveClearableSpace) (_clearButtonRef$curre = clearButtonRef.current) === null || _clearButtonRef$curre === void 0 ? void 0 : _clearButtonRef$curre.focus();else (_lastSegmentRef$curre = lastSegmentRef.current) === null || _lastSegmentRef$curre === void 0 ? void 0 : _lastSegmentRef$curre.focus();
77
- });
78
- }, [appOnDayChange, appOnHourChange, appOnMeridiemChange, appOnMinuteChange, appOnMonthChange, appOnYearChange, clearButtonRef, getIsDisabledDay, getIsDisabledTime, getIsOutOfRangeDay, handleChangeComposedDateTimeString, lastSegmentRef, shouldPreserveClearableSpace]);
73
+ if (shouldPreserveClearableSpace) trackFocusClearBtn();else trackFocusLastSegment();
74
+ }, [appOnDayChange, appOnHourChange, appOnMeridiemChange, appOnMinuteChange, appOnMonthChange, appOnYearChange, getIsDisabledDay, getIsDisabledTime, getIsOutOfRangeDay, handleChangeComposedDateTimeString, shouldPreserveClearableSpace, trackFocusClearBtn, trackFocusLastSegment]);
79
75
  const onGlobalKeyDown = useCallback(e => {
80
76
  const {
81
77
  key,
@@ -5,12 +5,13 @@ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
5
  import 'core-js/modules/esnext.iterator.for-each.js';
6
6
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
7
  import _jsx from '@babel/runtime/helpers/esm/jsx';
8
- import 'react';
8
+ import { useContext } from 'react';
9
9
  import { CloseMedium } from '@elliemae/ds-icons';
10
10
  import { DSIconColors } from '@elliemae/ds-icon';
11
11
  import { BUTTON_SIZES } from '@elliemae/ds-button';
12
12
  import { StyledClearButton } from '../Styleds.js';
13
13
  import { ControlledDateTimePickerDatatestid } from '../../ControlledDateTimePickerDatatestid.js';
14
+ import { ControlledDateTimePickerContext } from '../../ControlledDateTimePickerCTX.js';
14
15
  import { useClearButton } from './useClearButton.js';
15
16
  import { jsx } from 'react/jsx-runtime';
16
17
 
@@ -27,12 +28,21 @@ const ClearButton = () => {
27
28
  const styledsAttrs = {
28
29
  shouldDisplay: withClearBtn
29
30
  };
31
+ const {
32
+ latestInteractionRegion,
33
+ currFocusDescriber
34
+ } = useContext(ControlledDateTimePickerContext);
30
35
  return /*#__PURE__*/jsx(StyledClearButton, _objectSpread(_objectSpread({
31
36
  "aria-label": "clear selected date",
32
37
  buttonType: "icon",
33
38
  size: BUTTON_SIZES.M,
34
39
  "data-testid": ControlledDateTimePickerDatatestid.CLEAR_BUTTON,
35
- innerRef: clearButtonRef,
40
+ innerRef: DomElem => {
41
+ var _DomElem$focus;
42
+
43
+ clearButtonRef.current = DomElem;
44
+ if (latestInteractionRegion === 'clear-btn' && currFocusDescriber === 'clear-btn') DomElem === null || DomElem === void 0 ? void 0 : (_DomElem$focus = DomElem.focus) === null || _DomElem$focus === void 0 ? void 0 : _DomElem$focus.call(DomElem);
45
+ },
36
46
  onClick: onClearClick,
37
47
  onKeyDown: onClearButtonKeyDown
38
48
  }, styledsAttrs), {}, {
@@ -11,32 +11,21 @@ const useClearButton = () => {
11
11
  withAnyInputs,
12
12
  isWithTimeInputs,
13
13
  isWithDateInputs,
14
- isTimeSelector,
15
- hourInputRef,
16
- monthInputRef,
17
- pickerButtonRef,
18
- meridiemInputRef,
19
- yearInputRef,
20
- setLatestInteractionRegion
14
+ trackFocusFirstSegment,
15
+ trackFocusMeridiemInput,
16
+ trackFocusYearInput,
17
+ trackFocusPicker
21
18
  } = useContext(ControlledDateTimePickerContext);
22
- const focusFirstRegion = useCallback(() => {
23
- var _hourInputRef$current, _hourInputRef$current2, _monthInputRef$curren, _monthInputRef$curren2;
24
-
25
- if (withAnyInputs) if (isTimeSelector) 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 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);
26
- }, [withAnyInputs, isTimeSelector, hourInputRef, monthInputRef]);
27
19
  const onClearClick = useCallback(e => {
28
20
  handleClearAll(e);
29
- setLatestInteractionRegion('clear-btn');
30
- focusFirstRegion();
31
- }, [focusFirstRegion, handleClearAll, setLatestInteractionRegion]);
21
+ trackFocusFirstSegment();
22
+ }, [handleClearAll, trackFocusFirstSegment]);
32
23
  const onHomeKeyDown = useCallback(() => {
33
- focusFirstRegion();
34
- }, [focusFirstRegion]);
24
+ trackFocusFirstSegment();
25
+ }, [trackFocusFirstSegment]);
35
26
  const onEndKeyDown = useCallback(() => {
36
- var _pickerButtonRef$curr, _pickerButtonRef$curr2;
37
-
38
- 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);
39
- }, [withAnyPicker, pickerButtonRef]);
27
+ if (withAnyPicker) trackFocusPicker();
28
+ }, [withAnyPicker, trackFocusPicker]);
40
29
  const onClearButtonKeyDown = useCallback(e => {
41
30
  const {
42
31
  key
@@ -49,11 +38,9 @@ const useClearButton = () => {
49
38
  if (key === 'End') onEndKeyDown();
50
39
 
51
40
  if (key === 'Backspace' && withAnyInputs) {
52
- var _meridiemInputRef$cur, _meridiemInputRef$cur2, _yearInputRef$current, _yearInputRef$current2;
53
-
54
- if (isWithTimeInputs) 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 if (isWithDateInputs) 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);
41
+ if (isWithTimeInputs) trackFocusMeridiemInput();else if (isWithDateInputs) trackFocusYearInput();
55
42
  }
56
- }, [isWithDateInputs, isWithTimeInputs, meridiemInputRef, onEndKeyDown, onHomeKeyDown, withAnyInputs, yearInputRef]);
43
+ }, [isWithDateInputs, isWithTimeInputs, onEndKeyDown, onHomeKeyDown, trackFocusMeridiemInput, trackFocusYearInput, withAnyInputs]);
57
44
  return useMemo(() => ({
58
45
  onClearClick,
59
46
  onClearButtonKeyDown,
@@ -31,13 +31,13 @@ const ControlledDateTimePickerContent = () => {
31
31
  hideTime,
32
32
  hideTimePicker,
33
33
  hideDateTimePicker,
34
- setLatestInteractionRegion,
35
34
  withAnyPicker,
36
35
  withAnyRightController,
37
36
  shouldPreserveClearableSpace,
38
37
  isControllerOnly,
39
38
  dataAttrs,
40
- onGlobalKeyDown
39
+ onGlobalKeyDown,
40
+ trackFocusResetter
41
41
  } = React.useContext(ControlledDateTimePickerContext);
42
42
  const styledsAttrs = {
43
43
  justPicker: hideDate && hideTime,
@@ -45,9 +45,6 @@ const ControlledDateTimePickerContent = () => {
45
45
  hasError,
46
46
  isControllerOnly
47
47
  };
48
- const resetLatestInteraction = React.useCallback(() => {
49
- setLatestInteractionRegion('');
50
- }, [setLatestInteractionRegion]);
51
48
  const mainCols = [];
52
49
  if (!hideDate) mainCols.push('auto');
53
50
  if (!hideTime) mainCols.push('auto');
@@ -60,9 +57,9 @@ const ControlledDateTimePickerContent = () => {
60
57
  cols: mainCols,
61
58
  gutter: "xxs",
62
59
  pr: hideDatePicker && hideTimePicker && hideDateTimePicker ? '2px' : undefined,
63
- onBlur: resetLatestInteraction,
64
60
  onKeyDown: onGlobalKeyDown,
65
- disabled: disabled
61
+ disabled: disabled,
62
+ onBlur: trackFocusResetter
66
63
  }, styledsAttrs), dataAttrs), {}, {
67
64
  children: [hideDate ? null : _DateInputs || (_DateInputs = /*#__PURE__*/_jsx(DateInputs, {})), hideTime ? null : _TimeInputs || (_TimeInputs = /*#__PURE__*/_jsx(TimeInputs, {})), withAnyRightController ? /*#__PURE__*/_jsx(Grid, {
68
65
  cols: rightControlCols
@@ -21,7 +21,8 @@ const DDInput = /*#__PURE__*/React.memo(_ref => {
21
21
  disabled,
22
22
  contextRef,
23
23
  placeholder,
24
- ariaCurrentValueForInputs
24
+ ariaCurrentValueForInputs,
25
+ isFocused
25
26
  } = _ref;
26
27
  const validateOnChange = useCallback(e => {
27
28
  var _e$target;
@@ -39,7 +40,12 @@ const DDInput = /*#__PURE__*/React.memo(_ref => {
39
40
  onFocus: onFocus,
40
41
  onKeyDown: onKeyDown,
41
42
  value: value,
42
- ref: contextRef,
43
+ ref: DomElem => {
44
+ var _DomElem$focus;
45
+
46
+ contextRef.current = DomElem;
47
+ if (isFocused) DomElem === null || DomElem === void 0 ? void 0 : (_DomElem$focus = DomElem.focus) === null || _DomElem$focus === void 0 ? void 0 : _DomElem$focus.call(DomElem);
48
+ },
43
49
  placeholder: placeholder,
44
50
  "aria-label": "day input field, ".concat(ariaCurrentValueForInputs),
45
51
  "data-testid": ControlledDateTimePickerDatatestid.DATE_INPUTS.DAY,
@@ -35,7 +35,9 @@ const DateInputs = () => {
35
35
  monthInputRef,
36
36
  dayInputRef,
37
37
  yearInputRef,
38
- ariaCurrentValueForInputs
38
+ ariaCurrentValueForInputs,
39
+ latestInteractionRegion,
40
+ currFocusDescriber
39
41
  } = useContext(ControlledDateTimePickerContext);
40
42
  return /*#__PURE__*/_jsx(Grid, {
41
43
  cols: [fixedValues.smallInputWidth, fixedValues.separatorWidth, fixedValues.smallInputWidth, fixedValues.separatorWidth, fixedValues.largeInputWidth]
@@ -49,7 +51,8 @@ const DateInputs = () => {
49
51
  autoFocusMonthInput: autoFocusMonthInput,
50
52
  placeholder: "MM",
51
53
  ariaCurrentValueForInputs: ariaCurrentValueForInputs,
52
- disabled: disabled
54
+ disabled: disabled,
55
+ isFocused: latestInteractionRegion === 'date-inputs' && currFocusDescriber === 'month-input'
53
56
  })), _StyledSeparator || (_StyledSeparator = /*#__PURE__*/_jsx(StyledSeparator, {
54
57
  alignItems: "center"
55
58
  }, void 0, "/")), /*#__PURE__*/_jsx(StyledFocusWithIn, {}, void 0, /*#__PURE__*/_jsx(DDInput, {
@@ -61,7 +64,8 @@ const DateInputs = () => {
61
64
  contextRef: dayInputRef,
62
65
  placeholder: "DD",
63
66
  ariaCurrentValueForInputs: ariaCurrentValueForInputs,
64
- disabled: disabled
67
+ disabled: disabled,
68
+ isFocused: latestInteractionRegion === 'date-inputs' && currFocusDescriber === 'day-input'
65
69
  })), _StyledSeparator2 || (_StyledSeparator2 = /*#__PURE__*/_jsx(StyledSeparator, {
66
70
  alignItems: "center"
67
71
  }, void 0, "/")), /*#__PURE__*/_jsx(StyledFocusWithIn, {}, void 0, /*#__PURE__*/_jsx(YYYYInput, {
@@ -73,7 +77,8 @@ const DateInputs = () => {
73
77
  contextRef: yearInputRef,
74
78
  placeholder: "YYYY",
75
79
  ariaCurrentValueForInputs: ariaCurrentValueForInputs,
76
- disabled: disabled
80
+ disabled: disabled,
81
+ isFocused: latestInteractionRegion === 'date-inputs' && currFocusDescriber === 'year-input'
77
82
  })));
78
83
  };
79
84
 
@@ -22,7 +22,8 @@ const MMInput = /*#__PURE__*/React.memo(_ref => {
22
22
  placeholder,
23
23
  contextRef,
24
24
  autoFocusMonthInput,
25
- ariaCurrentValueForInputs
25
+ ariaCurrentValueForInputs,
26
+ isFocused
26
27
  } = _ref;
27
28
  const validateOnChange = useCallback(e => {
28
29
  var _e$target;
@@ -41,7 +42,12 @@ const MMInput = /*#__PURE__*/React.memo(_ref => {
41
42
  onFocus: onFocus,
42
43
  onKeyDown: onKeyDown,
43
44
  value: value,
44
- ref: contextRef,
45
+ ref: DomElem => {
46
+ var _DomElem$focus;
47
+
48
+ contextRef.current = DomElem;
49
+ if (isFocused) DomElem === null || DomElem === void 0 ? void 0 : (_DomElem$focus = DomElem.focus) === null || _DomElem$focus === void 0 ? void 0 : _DomElem$focus.call(DomElem);
50
+ },
45
51
  placeholder: placeholder,
46
52
  "aria-label": "month input field, ".concat(ariaCurrentValueForInputs),
47
53
  "data-testid": ControlledDateTimePickerDatatestid.DATE_INPUTS.MONTH,
@@ -21,7 +21,8 @@ const YYYYInput = /*#__PURE__*/React.memo(_ref => {
21
21
  disabled,
22
22
  placeholder,
23
23
  contextRef,
24
- ariaCurrentValueForInputs
24
+ ariaCurrentValueForInputs,
25
+ isFocused
25
26
  } = _ref;
26
27
  const validateOnChange = useCallback(e => {
27
28
  var _e$target;
@@ -39,7 +40,12 @@ const YYYYInput = /*#__PURE__*/React.memo(_ref => {
39
40
  onFocus: onFocus,
40
41
  onKeyDown: onKeyDown,
41
42
  value: value,
42
- ref: contextRef,
43
+ ref: DomElem => {
44
+ var _DomElem$focus;
45
+
46
+ contextRef.current = DomElem;
47
+ if (isFocused) DomElem === null || DomElem === void 0 ? void 0 : (_DomElem$focus = DomElem.focus) === null || _DomElem$focus === void 0 ? void 0 : _DomElem$focus.call(DomElem);
48
+ },
43
49
  placeholder: placeholder,
44
50
  "aria-label": "year input field, ".concat(ariaCurrentValueForInputs),
45
51
  "data-testid": ControlledDateTimePickerDatatestid.DATE_INPUTS.YEAR,