@elliemae/ds-controlled-form 2.3.2-next.0 → 2.4.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/cjs/autocomplete/parts/controls/useKeyboardNavigation.js +93 -0
  2. package/cjs/autocomplete/parts/controls/useMaskedOnChange.js +28 -0
  3. package/cjs/autocomplete/react-desc-prop-types.js +19 -0
  4. package/cjs/autocomplete/sharedTypes.js +2 -0
  5. package/cjs/combobox/config/useComboBox.js +30 -6
  6. package/cjs/combobox/config/useCorrectOptions.js +1 -1
  7. package/cjs/combobox/parts/container/Container.js +25 -33
  8. package/cjs/combobox/parts/controls/Controls.js +4 -16
  9. package/cjs/combobox/parts/controls-input/useControlsInput.js +1 -3
  10. package/cjs/combobox/parts/controls-input/useKeyboardNavigation.js +36 -30
  11. package/cjs/combobox/parts/header-list/HeaderList.js +3 -4
  12. package/cjs/combobox/parts/header-list/useHeaderListHandlers.js +18 -9
  13. package/cjs/combobox/parts/menu-list/MenuList.js +0 -2
  14. package/cjs/combobox/parts/menu-list/useItemRenderer.js +9 -14
  15. package/cjs/combobox/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +6 -17
  16. package/cjs/combobox/parts/multi-selected-values-container/RemovableSelectedValuePill.js +42 -0
  17. package/cjs/combobox/react-desc-prop-types.js +0 -2
  18. package/cjs/combobox/sharedTypes.js +3 -1
  19. package/cjs/combobox/utils/listHelper.js +47 -0
  20. package/cjs/mask-hook/hooks/useNumberMask.js +21 -17
  21. package/cjs/mask-hook/hooks/usePhoneMask.js +1 -1
  22. package/esm/autocomplete/parts/controls/useKeyboardNavigation.js +89 -0
  23. package/esm/autocomplete/parts/controls/useMaskedOnChange.js +24 -0
  24. package/esm/autocomplete/react-desc-prop-types.js +14 -0
  25. package/esm/autocomplete/sharedTypes.js +1 -0
  26. package/esm/combobox/config/useComboBox.js +31 -7
  27. package/esm/combobox/config/useCorrectOptions.js +1 -1
  28. package/esm/combobox/parts/container/Container.js +26 -34
  29. package/esm/combobox/parts/controls/Controls.js +4 -16
  30. package/esm/combobox/parts/controls-input/useControlsInput.js +1 -3
  31. package/esm/combobox/parts/controls-input/useKeyboardNavigation.js +38 -32
  32. package/esm/combobox/parts/header-list/HeaderList.js +3 -4
  33. package/esm/combobox/parts/header-list/useHeaderListHandlers.js +19 -10
  34. package/esm/combobox/parts/menu-list/MenuList.js +0 -2
  35. package/esm/combobox/parts/menu-list/useItemRenderer.js +10 -15
  36. package/esm/combobox/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +6 -17
  37. package/esm/combobox/parts/multi-selected-values-container/RemovableSelectedValuePill.js +34 -0
  38. package/esm/combobox/react-desc-prop-types.js +0 -2
  39. package/esm/combobox/sharedTypes.js +3 -2
  40. package/esm/combobox/utils/listHelper.js +45 -1
  41. package/esm/mask-hook/hooks/useNumberMask.js +21 -17
  42. package/esm/mask-hook/hooks/usePhoneMask.js +1 -1
  43. package/package.json +35 -23
  44. package/types/autocomplete/parts/controls/useKeyboardNavigation.d.ts +4 -0
  45. package/types/autocomplete/parts/controls/useMaskedOnChange.d.ts +2 -0
  46. package/types/autocomplete/react-desc-prop-types.d.ts +54 -0
  47. package/types/autocomplete/sharedTypes.d.ts +20 -0
  48. package/types/combobox/parts/header-list/useHeaderListHandlers.d.ts +1 -1
  49. package/types/combobox/parts/multi-selected-values-container/RemovableSelectedValuePill.d.ts +5 -0
  50. package/types/combobox/react-desc-prop-types.d.ts +3 -4
  51. package/types/combobox/sharedTypes.d.ts +1 -0
  52. package/types/combobox/tests/{combobox-creatable.test.d.ts → creatable.test.d.ts} +0 -0
  53. package/types/combobox/tests/{combobox-disable.test.d.ts → disabled.test.d.ts} +0 -0
  54. package/types/combobox/tests/{combobox-general.test.d.ts → general.test.d.ts} +0 -0
  55. package/types/combobox/tests/{combobox-multi-select.test.d.ts → multi-select.test.d.ts} +0 -0
  56. package/types/combobox/tests/{combobox-onlyselectable.test.d.ts → onlyselectable.test.d.ts} +0 -0
  57. package/types/combobox/tests/{combobox-single-select.test.d.ts → single-select.test.d.ts} +0 -0
  58. package/types/combobox/tests/{combobox-usemask.test.d.ts → usemask.test.d.ts} +0 -0
  59. package/types/combobox/utils/listHelper.d.ts +3 -0
  60. package/cjs/combobox/utils/hooks/useKeyboardNavigation.js +0 -168
  61. package/cjs/combobox/utils/hooks/useOnElementResize.js +0 -37
  62. package/esm/combobox/utils/hooks/useKeyboardNavigation.js +0 -164
  63. package/esm/combobox/utils/hooks/useOnElementResize.js +0 -33
  64. package/types/combobox/utils/hooks/useKeyboardNavigation.d.ts +0 -4
  65. package/types/combobox/utils/hooks/useOnElementResize.d.ts +0 -3
@@ -0,0 +1,2 @@
1
+ declare const useMaskedOnChange: () => any;
2
+ export { useMaskedOnChange };
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ export declare function noop<T extends unknown[]>(..._args: T): void;
3
+ export declare namespace DSAutocompleteT {
4
+ interface CommonItemOptions {
5
+ dsId: string;
6
+ disabled?: boolean;
7
+ render?: React.ComponentType<unknown>;
8
+ }
9
+ interface ItemSeparatorOptions extends CommonItemOptions {
10
+ type: 'separator';
11
+ }
12
+ interface ItemSectionOptions extends CommonItemOptions {
13
+ type: 'section';
14
+ label: string;
15
+ }
16
+ interface ItemOption extends CommonItemOptions {
17
+ value: string;
18
+ label: string;
19
+ type: 'option';
20
+ }
21
+ type OptionTypes = ItemOption | ItemSectionOptions | ItemSeparatorOptions;
22
+ type SelectedOptionsT = ItemOption[] | ItemOption | null;
23
+ interface PropsOptional {
24
+ placeholder?: string;
25
+ autoFocus?: boolean;
26
+ onFilter?: (value: string) => void;
27
+ }
28
+ interface RequiredProps {
29
+ options: OptionTypes[];
30
+ value: string;
31
+ }
32
+ interface DefaultProps {
33
+ startPlacementPreference: string;
34
+ placementOrderPreference: string[];
35
+ hasError: boolean;
36
+ withoutPortal: boolean;
37
+ zIndex: number;
38
+ disabled: boolean;
39
+ innerRef: React.RefObject<HTMLInputElement>;
40
+ inputProps: object;
41
+ }
42
+ interface Props extends Partial<DefaultProps>, RequiredProps, PropsOptional {
43
+ }
44
+ interface InternalProps extends DefaultProps, RequiredProps, PropsOptional {
45
+ }
46
+ }
47
+ export declare const propTypes: {
48
+ placeholder: import("@elliemae/ds-props-helpers/types/propTypes/types").ReactDescT;
49
+ options: import("@elliemae/ds-props-helpers/types/propTypes/types").ReactDescT;
50
+ value: import("@elliemae/ds-props-helpers/types/propTypes/types").ReactDescT;
51
+ autoFocus: import("@elliemae/ds-props-helpers/types/propTypes/types").ReactDescT;
52
+ hasError: import("@elliemae/ds-props-helpers/types/propTypes/types").ReactDescT;
53
+ onChange: import("@elliemae/ds-props-helpers/types/propTypes/types").ReactDescT;
54
+ };
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ import { useVirtual } from 'react-virtual';
3
+ import { DSAutocompleteT } from './react-desc-prop-types';
4
+ export declare namespace DSAutoCompleteInternalsT {
5
+ interface AutocompleteContext {
6
+ props: DSAutocompleteT.InternalProps;
7
+ virtualListHelpers?: ReturnType<typeof useVirtual>;
8
+ showPopover: boolean;
9
+ setShowPopover: React.Dispatch<React.SetStateAction<boolean>>;
10
+ referenceElement: HTMLElement | null;
11
+ setReferenceElement: React.Dispatch<React.SetStateAction<HTMLElement | null>>;
12
+ scrollOptionIntoView: (dsId: string, opts?: any) => void;
13
+ inputRef: React.RefObject<HTMLInputElement>;
14
+ listRef: React.RefObject<HTMLDivElement>;
15
+ wrapperListRef: React.RefObject<HTMLDivElement>;
16
+ controlsWrapperRef: React.RefObject<HTMLDivElement>;
17
+ focusOptionIdx: string;
18
+ setCurrentOption: React.Dispatch<React.SetStateAction<string>>;
19
+ }
20
+ }
@@ -5,7 +5,7 @@ declare const useHeaderListHandlers: () => {
5
5
  handleFilterSelectionBtnOnTab: (e: React.KeyboardEvent) => void;
6
6
  handleOnMouseDown: (e: React.MouseEvent) => void;
7
7
  handleCheckAllOnTab: (e: React.KeyboardEvent) => void;
8
- handleSelectAllCheckboxChange: () => void;
8
+ handleSelectAllCheckboxChange: (e: React.MouseEvent | React.KeyboardEvent) => void;
9
9
  checkboxStatus: boolean | "mixed";
10
10
  };
11
11
  export { useHeaderListHandlers };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { DSComboboxT } from '../../react-desc-prop-types';
3
+ export declare const RemovableSelectedValuePill: React.ComponentType<{
4
+ pill: DSComboboxT.ItemOption;
5
+ }>;
@@ -36,15 +36,14 @@ export declare namespace DSComboboxT {
36
36
  onMenuOpen?: () => void;
37
37
  onMenuClose?: () => void;
38
38
  onCancel?: () => void;
39
- onSelectAll?: () => void;
40
- onClearAll?: () => void;
41
39
  onBlur?: () => void;
42
- onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>, value: ItemOption | undefined) => void;
40
+ onSelectAll?: (suggestedValue: OptionTypes[] | [], event: React.MouseEvent | React.KeyboardEvent) => null;
41
+ onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>, value: ItemOption) => void;
43
42
  }
44
43
  interface RequiredProps {
45
44
  options: OptionTypes[];
46
45
  selectedValues: SelectedOptionsT;
47
- onChange: (value: ItemOption | null) => void;
46
+ onChange: (suggestedValue: ItemOption | OptionTypes[] | null, selectedOption: ItemOption, event: React.MouseEvent | React.KeyboardEvent) => void;
48
47
  }
49
48
  interface DefaultProps {
50
49
  startPlacementPreference: string;
@@ -28,3 +28,4 @@ export declare namespace DSComboboxInternalsT {
28
28
  }
29
29
  }
30
30
  export declare const isSeparator: (el: DSComboboxT.OptionTypes | undefined) => el is DSComboboxT.ItemSeparatorOptions;
31
+ export declare const isOption: (el: DSComboboxT.OptionTypes | undefined) => el is DSComboboxT.ItemOption;
@@ -5,3 +5,6 @@ export declare const isSelectedValueEmpty: (value: DSComboboxT.SelectedOptionsT)
5
5
  export declare const isSelectedValueMultiple: (value: DSComboboxT.SelectedOptionsT) => boolean;
6
6
  export declare const isSelected: (value: DSComboboxT.SelectedOptionsT, activeOption: DSComboboxT.ItemOption) => boolean;
7
7
  export declare const findInCircularList: (list: DSComboboxT.OptionTypes[], from: number, criteria: (item: DSComboboxT.OptionTypes) => boolean, step?: number) => number;
8
+ export declare const getFirstOption: (options: DSComboboxT.OptionTypes[], selectedValues: DSComboboxT.SelectedOptionsT, inputValue: string) => string;
9
+ export declare const getSuggestedValueOnChange: (selectedOption: DSComboboxT.ItemOption, selectedValues: DSComboboxT.SelectedOptionsT) => DSComboboxT.ItemOption | DSComboboxT.ItemOption[] | null;
10
+ export declare const getLastValueSelected: (selectedValues: DSComboboxT.SelectedOptionsT) => DSComboboxT.ItemOption | null;
@@ -1,168 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('core-js/modules/esnext.async-iterator.find.js');
6
- require('core-js/modules/esnext.iterator.constructor.js');
7
- require('core-js/modules/esnext.iterator.find.js');
8
- var React = require('react');
9
- var ComboBoxCTX = require('../../ComboBoxCTX.js');
10
- var listHelper = require('../listHelper.js');
11
- var constants = require('../../constants.js');
12
-
13
- const isOptionFocuseable = opt => !['section', 'separator'].includes(opt.type) && !opt.disabled;
14
-
15
- const useKeyboardNavigation = () => {
16
- const {
17
- props: {
18
- inline,
19
- onSelectAll,
20
- onCancel,
21
- onKeyDown,
22
- onChange,
23
- onCreate,
24
- options,
25
- selectedValues,
26
- onFilter,
27
- withoutPortal
28
- },
29
- setShowPopover,
30
- setInputValue,
31
- inputValue,
32
- showPopover,
33
- focusOptionIdx,
34
- setFocusOptionIdx,
35
- selectAllCheckboxRef,
36
- toggleSelectionButtonRef
37
- } = React.useContext(ComboBoxCTX.ComboBoxContext);
38
- const multiple = Array.isArray(selectedValues);
39
- const selectableOptions = listHelper.getOptions(options);
40
- const currentItemIndex = options.findIndex(opt => opt.dsId === focusOptionIdx);
41
- const currentItem = options.find(item => item.dsId === focusOptionIdx);
42
- const selectOption = React.useCallback(() => {
43
- const selectedOption = options.find(item => item.dsId === focusOptionIdx);
44
-
45
- if (!selectedOption.disabled) {
46
- if (onFilter) onFilter('');
47
- setInputValue('');
48
- onChange(selectedOption);
49
- if (!multiple) setShowPopover(false);
50
- }
51
- }, [multiple, options, setInputValue, focusOptionIdx, setShowPopover, onFilter, onChange]);
52
- const onInputKeyDown = React.useCallback(e => {
53
- // =============================================================================
54
- // CUSTOM KEYS
55
- // =============================================================================
56
- if (onKeyDown) onKeyDown(e, currentItem);
57
-
58
- if (!['Escape', 'Tab', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
59
- setShowPopover(true);
60
- } // =============================================================================
61
- // ESCAPE
62
- // =============================================================================
63
-
64
-
65
- if (e.key === 'Escape') {
66
- if (onCancel) onCancel();
67
-
68
- if (inputValue) {
69
- if (onFilter) onFilter('');
70
- setInputValue('');
71
- }
72
-
73
- if (!inline) setShowPopover(false);
74
- } // =============================================================================
75
- // ENTER KEY TO CREATE ELEMENTS
76
- // =============================================================================
77
-
78
-
79
- if (e.key === 'Enter' && (currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) === constants.INTERNAL_MENU_OPTION_TYPES.CREATABLE && onCreate) {
80
- onCreate(inputValue);
81
- if (onFilter) onFilter('');
82
- setInputValue('');
83
- return;
84
- } // =============================================================================
85
- // Enter and space on selection
86
- // =============================================================================
87
-
88
-
89
- if (e.key === 'Enter' || e.keyCode === 32 && e.altKey) {
90
- e.preventDefault();
91
- e.stopPropagation();
92
-
93
- if (focusOptionIdx !== '' && showPopover) {
94
- selectOption();
95
- }
96
- }
97
-
98
- if (e.key === 'Enter' && e.altKey) {
99
- setShowPopover(false);
100
- }
101
-
102
- if (e.key === 'a' && e.ctrlKey && multiple) {
103
- if (onSelectAll) onSelectAll();
104
- } // =============================================================================
105
- // ARROWS UP AND DOWN: LOGIC TO CALCULATE NEXT OR PREV ITEM TO PSEUDOFOCUS FROM INPUT
106
- // =============================================================================
107
-
108
-
109
- if (e.key === 'ArrowDown') {
110
- e.preventDefault();
111
- e.stopPropagation();
112
-
113
- if ((showPopover || inline) && selectableOptions.length) {
114
- const nextItemIndex = listHelper.findInCircularList(options, currentItemIndex, isOptionFocuseable);
115
- setFocusOptionIdx(options[nextItemIndex].dsId);
116
- }
117
- }
118
-
119
- if (e.key === 'ArrowUp') {
120
- e.preventDefault();
121
- e.stopPropagation();
122
- if (!selectableOptions.length) return;
123
- const prevItemIndex = listHelper.findInCircularList(options, currentItemIndex, isOptionFocuseable, -1);
124
-
125
- if (showPopover || inline) {
126
- setFocusOptionIdx(options[prevItemIndex].dsId);
127
- } else {
128
- setShowPopover(true);
129
- setTimeout(() => {
130
- const nextItemIndex = listHelper.findInCircularList(options, 0, isOptionFocuseable, -1);
131
- setFocusOptionIdx(options[nextItemIndex].dsId);
132
- });
133
- }
134
- } // =============================================================================
135
- // BACKSPACE
136
- // =============================================================================
137
-
138
-
139
- if (e.key === 'Backspace' && inputValue.length <= 0 && !inline) {
140
- if (multiple && !inputValue) {
141
- if (selectedValues.length > 0) onChange(selectedValues[selectedValues.length - 1]);
142
- } else {
143
- onChange(null);
144
- }
145
-
146
- if (onFilter) onFilter('');
147
- }
148
-
149
- if (e.key === 'Tab' && !inline && !withoutPortal) {
150
- var _selectAllCheckboxRef;
151
-
152
- const element = (_selectAllCheckboxRef = selectAllCheckboxRef.current) !== null && _selectAllCheckboxRef !== void 0 ? _selectAllCheckboxRef : toggleSelectionButtonRef.current;
153
-
154
- if (element) {
155
- e.preventDefault();
156
- element.focus();
157
- }
158
- } // waiting for validation from ux
159
- // if (e.key === 'Tab' && multiple) {
160
- // }
161
-
162
- }, [onKeyDown, currentItem, onCreate, multiple, inputValue, inline, withoutPortal, setShowPopover, onCancel, onFilter, setInputValue, focusOptionIdx, showPopover, selectOption, onSelectAll, selectableOptions.length, options, currentItemIndex, setFocusOptionIdx, selectedValues, onChange, selectAllCheckboxRef, toggleSelectionButtonRef]);
163
- return {
164
- onInputKeyDown
165
- };
166
- };
167
-
168
- exports.useKeyboardNavigation = useKeyboardNavigation;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('core-js/modules/web.dom-collections.iterator.js');
6
- var React = require('react');
7
-
8
- // Taken and modified from https://stackoverflow.com/a/60218754
9
-
10
- const useOnElementResize = targetRef => {
11
- var _targetRef$current, _targetRef$current2;
12
-
13
- const [width, setWidth] = React.useState(targetRef.current ? (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.offsetWidth : 0);
14
- const [height, setHeight] = React.useState(targetRef.current ? (_targetRef$current2 = targetRef.current) === null || _targetRef$current2 === void 0 ? void 0 : _targetRef$current2.offsetWidth : 0);
15
- const observer = React.useRef(null);
16
- React.useEffect(() => {
17
- function outputsize() {
18
- if (targetRef.current) {
19
- setWidth(targetRef.current.offsetWidth);
20
- setHeight(targetRef.current.offsetHeight);
21
- }
22
- }
23
-
24
- observer.current = new ResizeObserver(outputsize).observe(targetRef.current);
25
- return () => {
26
- var _observer$current;
27
-
28
- (_observer$current = observer.current) === null || _observer$current === void 0 ? void 0 : _observer$current.disconnect();
29
- };
30
- }, [targetRef]);
31
- return React.useMemo(() => ({
32
- width,
33
- height
34
- }), [width, height]);
35
- };
36
-
37
- exports.useOnElementResize = useOnElementResize;
@@ -1,164 +0,0 @@
1
- import 'core-js/modules/esnext.async-iterator.find.js';
2
- import 'core-js/modules/esnext.iterator.constructor.js';
3
- import 'core-js/modules/esnext.iterator.find.js';
4
- import { useContext, useCallback } from 'react';
5
- import { ComboBoxContext } from '../../ComboBoxCTX.js';
6
- import { getOptions, findInCircularList } from '../listHelper.js';
7
- import { INTERNAL_MENU_OPTION_TYPES } from '../../constants.js';
8
-
9
- const isOptionFocuseable = opt => !['section', 'separator'].includes(opt.type) && !opt.disabled;
10
-
11
- const useKeyboardNavigation = () => {
12
- const {
13
- props: {
14
- inline,
15
- onSelectAll,
16
- onCancel,
17
- onKeyDown,
18
- onChange,
19
- onCreate,
20
- options,
21
- selectedValues,
22
- onFilter,
23
- withoutPortal
24
- },
25
- setShowPopover,
26
- setInputValue,
27
- inputValue,
28
- showPopover,
29
- focusOptionIdx,
30
- setFocusOptionIdx,
31
- selectAllCheckboxRef,
32
- toggleSelectionButtonRef
33
- } = useContext(ComboBoxContext);
34
- const multiple = Array.isArray(selectedValues);
35
- const selectableOptions = getOptions(options);
36
- const currentItemIndex = options.findIndex(opt => opt.dsId === focusOptionIdx);
37
- const currentItem = options.find(item => item.dsId === focusOptionIdx);
38
- const selectOption = useCallback(() => {
39
- const selectedOption = options.find(item => item.dsId === focusOptionIdx);
40
-
41
- if (!selectedOption.disabled) {
42
- if (onFilter) onFilter('');
43
- setInputValue('');
44
- onChange(selectedOption);
45
- if (!multiple) setShowPopover(false);
46
- }
47
- }, [multiple, options, setInputValue, focusOptionIdx, setShowPopover, onFilter, onChange]);
48
- const onInputKeyDown = useCallback(e => {
49
- // =============================================================================
50
- // CUSTOM KEYS
51
- // =============================================================================
52
- if (onKeyDown) onKeyDown(e, currentItem);
53
-
54
- if (!['Escape', 'Tab', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
55
- setShowPopover(true);
56
- } // =============================================================================
57
- // ESCAPE
58
- // =============================================================================
59
-
60
-
61
- if (e.key === 'Escape') {
62
- if (onCancel) onCancel();
63
-
64
- if (inputValue) {
65
- if (onFilter) onFilter('');
66
- setInputValue('');
67
- }
68
-
69
- if (!inline) setShowPopover(false);
70
- } // =============================================================================
71
- // ENTER KEY TO CREATE ELEMENTS
72
- // =============================================================================
73
-
74
-
75
- if (e.key === 'Enter' && (currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) === INTERNAL_MENU_OPTION_TYPES.CREATABLE && onCreate) {
76
- onCreate(inputValue);
77
- if (onFilter) onFilter('');
78
- setInputValue('');
79
- return;
80
- } // =============================================================================
81
- // Enter and space on selection
82
- // =============================================================================
83
-
84
-
85
- if (e.key === 'Enter' || e.keyCode === 32 && e.altKey) {
86
- e.preventDefault();
87
- e.stopPropagation();
88
-
89
- if (focusOptionIdx !== '' && showPopover) {
90
- selectOption();
91
- }
92
- }
93
-
94
- if (e.key === 'Enter' && e.altKey) {
95
- setShowPopover(false);
96
- }
97
-
98
- if (e.key === 'a' && e.ctrlKey && multiple) {
99
- if (onSelectAll) onSelectAll();
100
- } // =============================================================================
101
- // ARROWS UP AND DOWN: LOGIC TO CALCULATE NEXT OR PREV ITEM TO PSEUDOFOCUS FROM INPUT
102
- // =============================================================================
103
-
104
-
105
- if (e.key === 'ArrowDown') {
106
- e.preventDefault();
107
- e.stopPropagation();
108
-
109
- if ((showPopover || inline) && selectableOptions.length) {
110
- const nextItemIndex = findInCircularList(options, currentItemIndex, isOptionFocuseable);
111
- setFocusOptionIdx(options[nextItemIndex].dsId);
112
- }
113
- }
114
-
115
- if (e.key === 'ArrowUp') {
116
- e.preventDefault();
117
- e.stopPropagation();
118
- if (!selectableOptions.length) return;
119
- const prevItemIndex = findInCircularList(options, currentItemIndex, isOptionFocuseable, -1);
120
-
121
- if (showPopover || inline) {
122
- setFocusOptionIdx(options[prevItemIndex].dsId);
123
- } else {
124
- setShowPopover(true);
125
- setTimeout(() => {
126
- const nextItemIndex = findInCircularList(options, 0, isOptionFocuseable, -1);
127
- setFocusOptionIdx(options[nextItemIndex].dsId);
128
- });
129
- }
130
- } // =============================================================================
131
- // BACKSPACE
132
- // =============================================================================
133
-
134
-
135
- if (e.key === 'Backspace' && inputValue.length <= 0 && !inline) {
136
- if (multiple && !inputValue) {
137
- if (selectedValues.length > 0) onChange(selectedValues[selectedValues.length - 1]);
138
- } else {
139
- onChange(null);
140
- }
141
-
142
- if (onFilter) onFilter('');
143
- }
144
-
145
- if (e.key === 'Tab' && !inline && !withoutPortal) {
146
- var _selectAllCheckboxRef;
147
-
148
- const element = (_selectAllCheckboxRef = selectAllCheckboxRef.current) !== null && _selectAllCheckboxRef !== void 0 ? _selectAllCheckboxRef : toggleSelectionButtonRef.current;
149
-
150
- if (element) {
151
- e.preventDefault();
152
- element.focus();
153
- }
154
- } // waiting for validation from ux
155
- // if (e.key === 'Tab' && multiple) {
156
- // }
157
-
158
- }, [onKeyDown, currentItem, onCreate, multiple, inputValue, inline, withoutPortal, setShowPopover, onCancel, onFilter, setInputValue, focusOptionIdx, showPopover, selectOption, onSelectAll, selectableOptions.length, options, currentItemIndex, setFocusOptionIdx, selectedValues, onChange, selectAllCheckboxRef, toggleSelectionButtonRef]);
159
- return {
160
- onInputKeyDown
161
- };
162
- };
163
-
164
- export { useKeyboardNavigation };
@@ -1,33 +0,0 @@
1
- import 'core-js/modules/web.dom-collections.iterator.js';
2
- import { useState, useRef, useEffect, useMemo } from 'react';
3
-
4
- // Taken and modified from https://stackoverflow.com/a/60218754
5
-
6
- const useOnElementResize = targetRef => {
7
- var _targetRef$current, _targetRef$current2;
8
-
9
- const [width, setWidth] = useState(targetRef.current ? (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.offsetWidth : 0);
10
- const [height, setHeight] = useState(targetRef.current ? (_targetRef$current2 = targetRef.current) === null || _targetRef$current2 === void 0 ? void 0 : _targetRef$current2.offsetWidth : 0);
11
- const observer = useRef(null);
12
- useEffect(() => {
13
- function outputsize() {
14
- if (targetRef.current) {
15
- setWidth(targetRef.current.offsetWidth);
16
- setHeight(targetRef.current.offsetHeight);
17
- }
18
- }
19
-
20
- observer.current = new ResizeObserver(outputsize).observe(targetRef.current);
21
- return () => {
22
- var _observer$current;
23
-
24
- (_observer$current = observer.current) === null || _observer$current === void 0 ? void 0 : _observer$current.disconnect();
25
- };
26
- }, [targetRef]);
27
- return useMemo(() => ({
28
- width,
29
- height
30
- }), [width, height]);
31
- };
32
-
33
- export { useOnElementResize };
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const useKeyboardNavigation: () => {
3
- onInputKeyDown: import("react").KeyboardEventHandler<HTMLInputElement>;
4
- };
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const useOnElementResize: (targetRef: React.RefObject<HTMLDivElement>) => Record<'width' | 'height', number>;
3
- export { useOnElementResize };