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