@elliemae/ds-controlled-form 2.4.1-rc.1 → 2.4.1-rc.5

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 (186) hide show
  1. package/cjs/autocomplete/Autocomplete.js +4 -5
  2. package/cjs/autocomplete/AutocompleteCTX.js +3 -14
  3. package/cjs/autocomplete/AutocompleteDataTestids.js +1 -7
  4. package/cjs/autocomplete/config/useAutocomplete.js +23 -10
  5. package/cjs/autocomplete/parts/container/Container.js +36 -20
  6. package/cjs/autocomplete/parts/container/styled.js +1 -5
  7. package/cjs/autocomplete/parts/{controls → container}/useKeyboardNavigation.js +8 -24
  8. package/cjs/autocomplete/parts/menu-list/MenuList.js +17 -50
  9. package/cjs/autocomplete/parts/menu-list/styled.js +9 -10
  10. package/cjs/autocomplete/parts/menu-list/useItemRenderer.js +38 -44
  11. package/cjs/autocomplete/react-desc-prop-types.js +4 -8
  12. package/cjs/autocomplete/utils/listHelper.js +8 -16
  13. package/cjs/checkbox/ControlledCheckbox.js +2 -1
  14. package/cjs/checkbox/react-desc-prop-types.js +2 -0
  15. package/cjs/combobox/ComboBox.js +1 -0
  16. package/cjs/combobox/config/useComboBox.js +8 -2
  17. package/cjs/combobox/config/useCorrectOptions.js +14 -42
  18. package/cjs/combobox/index.js +1 -0
  19. package/cjs/combobox/parts/A11yFocusedOption.js +3 -3
  20. package/cjs/combobox/parts/controls/Controls.js +4 -2
  21. package/cjs/combobox/parts/controls-input/ControlsInput.js +2 -0
  22. package/cjs/combobox/parts/controls-input/styled.js +1 -1
  23. package/cjs/combobox/parts/controls-input/useControlsInput.js +6 -6
  24. package/cjs/combobox/parts/controls-input/useKeyboardNavigation.js +30 -26
  25. package/cjs/combobox/parts/controls-input/useMaskedOnChange.js +7 -5
  26. package/cjs/combobox/parts/dropdown-indicator/DropdownIndicator.js +6 -4
  27. package/cjs/combobox/parts/header-list/useHeaderListHandlers.js +4 -4
  28. package/cjs/combobox/parts/menu-list/MenuList.js +13 -7
  29. package/cjs/combobox/parts/menu-list/styled.js +16 -5
  30. package/cjs/combobox/parts/menu-list/useItemRenderer.js +8 -8
  31. package/cjs/combobox/parts/menu-list/useMenuListSetFocusOption.js +6 -6
  32. package/cjs/combobox/react-desc-prop-types.js +2 -1
  33. package/cjs/combobox/utils/listHelper.js +40 -11
  34. package/cjs/index.js +16 -3
  35. package/cjs/large-text-input/DSControlledLargeTextInput.js +83 -0
  36. package/cjs/large-text-input/exported-related/data-test-ids.js +11 -0
  37. package/cjs/large-text-input/exported-related/index.js +12 -0
  38. package/cjs/large-text-input/exported-related/theming.js +13 -0
  39. package/cjs/large-text-input/index.js +15 -0
  40. package/cjs/large-text-input/react-desc-prop-types.js +45 -0
  41. package/cjs/large-text-input/styles.js +40 -0
  42. package/cjs/mask-hook/hooks/index.js +7 -3
  43. package/cjs/mask-hook/hooks/useNumberMask.js +5 -0
  44. package/cjs/mask-hook/hooks/usePhoneMask.js +5 -0
  45. package/cjs/mask-hook/hooks/useSSNMask.js +5 -0
  46. package/cjs/mask-hook/hooks/{useZipCode.js → useZipCodeMask.js} +10 -5
  47. package/cjs/mask-hook/index.js +7 -3
  48. package/esm/autocomplete/Autocomplete.js +2 -3
  49. package/esm/autocomplete/AutocompleteCTX.js +3 -14
  50. package/esm/autocomplete/AutocompleteDataTestids.js +1 -7
  51. package/esm/autocomplete/config/useAutocomplete.js +27 -14
  52. package/esm/autocomplete/parts/container/Container.js +38 -23
  53. package/esm/autocomplete/parts/container/styled.js +2 -5
  54. package/esm/autocomplete/parts/{controls → container}/useKeyboardNavigation.js +8 -24
  55. package/esm/autocomplete/parts/menu-list/MenuList.js +19 -52
  56. package/esm/autocomplete/parts/menu-list/styled.js +9 -10
  57. package/esm/autocomplete/parts/menu-list/useItemRenderer.js +39 -45
  58. package/esm/autocomplete/react-desc-prop-types.js +5 -8
  59. package/esm/autocomplete/utils/listHelper.js +8 -16
  60. package/esm/checkbox/ControlledCheckbox.js +2 -1
  61. package/esm/checkbox/react-desc-prop-types.js +2 -0
  62. package/esm/combobox/ComboBox.js +1 -1
  63. package/esm/combobox/config/useComboBox.js +8 -2
  64. package/esm/combobox/config/useCorrectOptions.js +15 -43
  65. package/esm/combobox/index.js +1 -1
  66. package/esm/combobox/parts/A11yFocusedOption.js +3 -3
  67. package/esm/combobox/parts/controls/Controls.js +4 -2
  68. package/esm/combobox/parts/controls-input/ControlsInput.js +2 -0
  69. package/esm/combobox/parts/controls-input/styled.js +1 -1
  70. package/esm/combobox/parts/controls-input/useControlsInput.js +6 -6
  71. package/esm/combobox/parts/controls-input/useKeyboardNavigation.js +30 -26
  72. package/esm/combobox/parts/controls-input/useMaskedOnChange.js +7 -5
  73. package/esm/combobox/parts/dropdown-indicator/DropdownIndicator.js +2 -2
  74. package/esm/combobox/parts/header-list/useHeaderListHandlers.js +4 -4
  75. package/esm/combobox/parts/menu-list/MenuList.js +13 -7
  76. package/esm/combobox/parts/menu-list/styled.js +16 -5
  77. package/esm/combobox/parts/menu-list/useItemRenderer.js +8 -8
  78. package/esm/combobox/parts/menu-list/useMenuListSetFocusOption.js +6 -6
  79. package/esm/combobox/react-desc-prop-types.js +2 -1
  80. package/esm/combobox/utils/listHelper.js +38 -12
  81. package/esm/index.js +8 -5
  82. package/esm/large-text-input/DSControlledLargeTextInput.js +72 -0
  83. package/esm/large-text-input/exported-related/data-test-ids.js +7 -0
  84. package/esm/large-text-input/exported-related/index.js +2 -0
  85. package/esm/large-text-input/exported-related/theming.js +8 -0
  86. package/esm/large-text-input/index.js +3 -0
  87. package/esm/large-text-input/react-desc-prop-types.js +36 -0
  88. package/esm/large-text-input/styles.js +30 -0
  89. package/esm/mask-hook/hooks/index.js +4 -4
  90. package/esm/mask-hook/hooks/useNumberMask.js +5 -1
  91. package/esm/mask-hook/hooks/usePhoneMask.js +5 -1
  92. package/esm/mask-hook/hooks/useSSNMask.js +5 -1
  93. package/esm/mask-hook/hooks/{useZipCode.js → useZipCodeMask.js} +9 -5
  94. package/esm/mask-hook/index.js +4 -4
  95. package/package.json +52 -88
  96. package/types/autocomplete/Autocomplete.d.ts +4 -61
  97. package/types/autocomplete/AutocompleteCTX.d.ts +4 -3
  98. package/types/autocomplete/AutocompleteDataTestids.d.ts +1 -7
  99. package/types/autocomplete/config/useAutocomplete.d.ts +3 -2
  100. package/types/autocomplete/parts/container/Container.d.ts +1 -2
  101. package/types/autocomplete/parts/container/styled.d.ts +0 -1
  102. package/types/autocomplete/parts/{controls → container}/useKeyboardNavigation.d.ts +0 -0
  103. package/types/autocomplete/parts/menu-list/MenuList.d.ts +1 -2
  104. package/types/autocomplete/parts/menu-list/styled.d.ts +1 -4
  105. package/types/autocomplete/parts/menu-list/useItemRenderer.d.ts +2 -3
  106. package/types/autocomplete/react-desc-prop-types.d.ts +8 -18
  107. package/types/autocomplete/sharedTypes.d.ts +1 -3
  108. package/types/autocomplete/tests/general.test.d.ts +1 -0
  109. package/types/autocomplete/tests/utils.d.ts +5 -0
  110. package/types/autocomplete/utils/listHelper.d.ts +2 -2
  111. package/types/checkbox/ControlledCheckbox.d.ts +1 -1
  112. package/types/checkbox/react-desc-prop-types.d.ts +367 -1
  113. package/types/combobox/ComboBox.d.ts +2 -2
  114. package/types/combobox/parts/dropdown-indicator/DropdownIndicator.d.ts +1 -0
  115. package/types/combobox/react-desc-prop-types.d.ts +381 -3
  116. package/types/combobox/utils/listHelper.d.ts +4 -1
  117. package/types/index.d.ts +1 -0
  118. package/types/large-text-input/DSControlledLargeTextInput.d.ts +5 -0
  119. package/types/large-text-input/exported-related/data-test-ids.d.ts +5 -0
  120. package/types/large-text-input/exported-related/index.d.ts +2 -0
  121. package/types/large-text-input/exported-related/theming.d.ts +6 -0
  122. package/types/large-text-input/index.d.ts +2 -0
  123. package/types/large-text-input/react-desc-prop-types.d.ts +447 -0
  124. package/types/large-text-input/styles.d.ts +3 -0
  125. package/types/large-text-input/tests/DSControlledLargeTextInput.test.d.ts +1 -0
  126. package/types/mask-hook/hooks/index.d.ts +1 -1
  127. package/types/mask-hook/hooks/useNumberMask.d.ts +2 -1
  128. package/types/mask-hook/hooks/usePhoneMask.d.ts +2 -1
  129. package/types/mask-hook/hooks/useSSNMask.d.ts +2 -1
  130. package/types/mask-hook/hooks/useZipCodeMask.d.ts +4 -0
  131. package/types/text-input/DSInputText.d.ts +1 -1
  132. package/types/text-input/config/useInputText.d.ts +110 -110
  133. package/cjs/autocomplete/config/constants.js +0 -14
  134. package/cjs/autocomplete/config/useGetPropsWithDefault.js +0 -11
  135. package/cjs/autocomplete/index.d.js +0 -2
  136. package/cjs/autocomplete/parts/a11y-messages/MultiAllyMessages.js +0 -33
  137. package/cjs/autocomplete/parts/a11y-messages/SingleAllyMessages.js +0 -28
  138. package/cjs/autocomplete/parts/a11y-messages/index.js +0 -11
  139. package/cjs/autocomplete/parts/a11y-messages/styled.js +0 -15
  140. package/cjs/autocomplete/parts/controls/Controls.js +0 -63
  141. package/cjs/autocomplete/parts/controls/index.js +0 -9
  142. package/cjs/autocomplete/parts/controls/styled.js +0 -44
  143. package/cjs/autocomplete/parts/controls/useControlsInput.js +0 -44
  144. package/cjs/autocomplete/parts/controls/useMaskedOnChange.js +0 -28
  145. package/cjs/autocomplete/parts/menu-list/useMenuList.js +0 -69
  146. package/cjs/autocomplete/propTypes.js +0 -25
  147. package/cjs/autocomplete/utils/hooks/useKeyboardNavigation.js +0 -97
  148. package/cjs/autocomplete/utils/hooks/useOnElementResize.js +0 -37
  149. package/cjs/text-input/exported-related/name.js +0 -7
  150. package/cjs/text-input/exported-related/slots.js +0 -11
  151. package/esm/autocomplete/config/constants.js +0 -10
  152. package/esm/autocomplete/config/useGetPropsWithDefault.js +0 -7
  153. package/esm/autocomplete/index.d.js +0 -1
  154. package/esm/autocomplete/parts/a11y-messages/MultiAllyMessages.js +0 -25
  155. package/esm/autocomplete/parts/a11y-messages/SingleAllyMessages.js +0 -20
  156. package/esm/autocomplete/parts/a11y-messages/index.js +0 -2
  157. package/esm/autocomplete/parts/a11y-messages/styled.js +0 -7
  158. package/esm/autocomplete/parts/controls/Controls.js +0 -55
  159. package/esm/autocomplete/parts/controls/index.js +0 -1
  160. package/esm/autocomplete/parts/controls/styled.js +0 -32
  161. package/esm/autocomplete/parts/controls/useControlsInput.js +0 -40
  162. package/esm/autocomplete/parts/controls/useMaskedOnChange.js +0 -24
  163. package/esm/autocomplete/parts/menu-list/useMenuList.js +0 -65
  164. package/esm/autocomplete/propTypes.js +0 -21
  165. package/esm/autocomplete/utils/hooks/useKeyboardNavigation.js +0 -93
  166. package/esm/autocomplete/utils/hooks/useOnElementResize.js +0 -33
  167. package/esm/text-input/exported-related/name.js +0 -3
  168. package/esm/text-input/exported-related/slots.js +0 -7
  169. package/types/autocomplete/config/constants.d.ts +0 -8
  170. package/types/autocomplete/config/useGetPropsWithDefault.d.ts +0 -2
  171. package/types/autocomplete/parts/a11y-messages/MultiAllyMessages.d.ts +0 -3
  172. package/types/autocomplete/parts/a11y-messages/SingleAllyMessages.d.ts +0 -3
  173. package/types/autocomplete/parts/a11y-messages/index.d.ts +0 -2
  174. package/types/autocomplete/parts/a11y-messages/styled.d.ts +0 -1
  175. package/types/autocomplete/parts/controls/Controls.d.ts +0 -3
  176. package/types/autocomplete/parts/controls/index.d.ts +0 -1
  177. package/types/autocomplete/parts/controls/styled.d.ts +0 -8
  178. package/types/autocomplete/parts/controls/useControlsInput.d.ts +0 -9
  179. package/types/autocomplete/parts/controls/useMaskedOnChange.d.ts +0 -2
  180. package/types/autocomplete/parts/menu-list/useMenuList.d.ts +0 -2
  181. package/types/autocomplete/propTypes.d.ts +0 -51
  182. package/types/autocomplete/utils/hooks/useKeyboardNavigation.d.ts +0 -4
  183. package/types/autocomplete/utils/hooks/useOnElementResize.d.ts +0 -3
  184. package/types/mask-hook/hooks/useZipCode.d.ts +0 -3
  185. package/types/text-input/exported-related/name.d.ts +0 -1
  186. package/types/text-input/exported-related/slots.d.ts +0 -5
@@ -3,18 +3,10 @@ import { noop } from 'lodash';
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/no-empty-function
5
5
  const defaultProps = {
6
- placeholder: '',
7
- options: [],
8
- selectedValues: '',
9
- hasError: false,
10
- isLoading: false,
11
- autoFocus: false,
6
+ zIndex: 10,
7
+ withoutPortal: false,
12
8
  startPlacementPreference: 'bottom-start',
13
- placementOrderPreference: ['bottom-start', 'bottom-end'],
14
- onChange: noop,
15
- onKeyDown: noop,
16
- onFilter: noop,
17
- onMenuOpen: noop
9
+ placementOrderPreference: ['bottom-start', 'bottom-end']
18
10
  };
19
11
  const defaultContext = {
20
12
  props: defaultProps,
@@ -25,9 +17,6 @@ const defaultContext = {
25
17
  setReferenceElement: noop,
26
18
  inputRef: /*#__PURE__*/createRef(),
27
19
  listRef: /*#__PURE__*/createRef(),
28
- wrapperListRef: /*#__PURE__*/createRef(),
29
- controlsWrapperRef: /*#__PURE__*/createRef(),
30
- selectedOptionsRef: /*#__PURE__*/createRef(),
31
20
  focusOptionIdx: '',
32
21
  setCurrentOption: noop
33
22
  };
@@ -1,13 +1,7 @@
1
1
  const AutocompleteDataTestid = {
2
- INPUT: 'autocomplete-input',
3
2
  LIST: 'autocomplete-menu-list',
4
- SELECTED_VALUES: 'autocomplete-selected-values',
5
- SELECT_ALL_BUTTON: 'autocomplete-all-btn',
6
- CLEAR_ALL_BUTTON: 'autocomplete-clear-btn',
7
- DROPDOWN: 'autocomplete-dropdown-btn',
8
3
  OPTION: 'autocomplete-option',
9
- SHOW_ALL_BUTTON: 'autocomplete-show-all-btn',
10
- SHOW_SELECTED_OPTIONS_BUTTON: 'autocomplete-selected-options-btn'
4
+ CONTAINER: 'autocomplete-container'
11
5
  };
12
6
 
13
7
  export { AutocompleteDataTestid };
@@ -1,30 +1,37 @@
1
- import 'core-js/modules/esnext.async-iterator.filter.js';
2
- import 'core-js/modules/esnext.iterator.constructor.js';
3
- import 'core-js/modules/esnext.iterator.filter.js';
4
1
  import 'core-js/modules/esnext.async-iterator.for-each.js';
5
2
  import 'core-js/modules/esnext.iterator.for-each.js';
6
3
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
4
  import 'core-js/modules/web.dom-collections.iterator.js';
8
- import { useState, useRef, useCallback, useMemo } from 'react';
5
+ import 'core-js/modules/esnext.async-iterator.filter.js';
6
+ import 'core-js/modules/esnext.iterator.constructor.js';
7
+ import 'core-js/modules/esnext.iterator.filter.js';
8
+ import { useRef, useState, useCallback, useEffect, useMemo } from 'react';
9
+ import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
9
10
  import { useVirtual } from 'react-virtual';
10
- import { useGetAutocompleteWithDefaultsProps } from './useGetPropsWithDefault.js';
11
+ import { propTypes } from '../react-desc-prop-types.js';
12
+ import { defaultProps } from '../AutocompleteCTX.js';
13
+ import { getFirstOption } from '../utils/listHelper.js';
11
14
 
12
15
  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; }
13
16
 
14
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; }
15
18
  const useAutocomplete = props => {
19
+ const defaultPropsWithInnerRef = _objectSpread(_objectSpread({}, defaultProps), {}, {
20
+ innerRef: useRef(null)
21
+ });
22
+
23
+ const propsWithDefault = useMemoMergePropsWithDefault(props, defaultPropsWithInnerRef);
24
+ useValidateTypescriptPropTypes(propsWithDefault, propTypes);
16
25
  const [showPopover, setShowPopover] = useState(false);
17
26
  const [referenceElement, setReferenceElement] = useState(null);
18
27
  const [focusOptionIdx, setCurrentOption] = useState('');
19
28
  const inputRef = useRef(null);
20
29
  const listRef = useRef(null);
21
- const wrapperListRef = useRef(null);
22
30
  const selectedOptionsRef = useRef(null);
23
- const controlsWrapperRef = useRef(null);
24
- const propsWithDefaults = useGetAutocompleteWithDefaultsProps(props);
25
31
  const {
26
- options
27
- } = propsWithDefaults; // ===========================================================================
32
+ options,
33
+ filter
34
+ } = propsWithDefault; // ===========================================================================
28
35
  // Virtualization setup
29
36
  // ===========================================================================
30
37
 
@@ -43,8 +50,16 @@ const useAutocomplete = props => {
43
50
  };
44
51
  virtualListHelpers.scrollToIndex(options.findIndex(opt => opt.dsId === dsId), opts);
45
52
  }, [options, virtualListHelpers]);
53
+ useEffect(() => {
54
+ if (filter.length === 0 || options.length === 0) {
55
+ setShowPopover(false);
56
+ }
57
+ }, [filter, options.length, setShowPopover]);
58
+ useEffect(() => {
59
+ setCurrentOption(getFirstOption(options));
60
+ }, [options, showPopover]);
46
61
  const ctx = useMemo(() => ({
47
- props: _objectSpread({}, propsWithDefaults),
62
+ props: _objectSpread({}, propsWithDefault),
48
63
  virtualListHelpers,
49
64
  showPopover,
50
65
  referenceElement,
@@ -52,13 +67,11 @@ const useAutocomplete = props => {
52
67
  listRef,
53
68
  focusOptionIdx,
54
69
  selectedOptionsRef,
55
- controlsWrapperRef,
56
- wrapperListRef,
57
70
  setCurrentOption,
58
71
  scrollOptionIntoView,
59
72
  setReferenceElement,
60
73
  setShowPopover
61
- }), [scrollOptionIntoView, propsWithDefaults, virtualListHelpers, focusOptionIdx, wrapperListRef, showPopover, referenceElement, inputRef, selectedOptionsRef, controlsWrapperRef, listRef]);
74
+ }), [scrollOptionIntoView, propsWithDefault, virtualListHelpers, focusOptionIdx, showPopover, referenceElement, inputRef, selectedOptionsRef, listRef]);
62
75
  return ctx;
63
76
  };
64
77
 
@@ -1,40 +1,56 @@
1
1
  import _jsx from '@babel/runtime/helpers/esm/jsx';
2
- import { useContext, useCallback } from 'react';
2
+ import 'core-js/modules/esnext.async-iterator.filter.js';
3
+ import 'core-js/modules/esnext.iterator.constructor.js';
4
+ import 'core-js/modules/esnext.iterator.filter.js';
5
+ import React, { useContext, useEffect, useCallback } from 'react';
3
6
  import { DSPopperJS } from '@elliemae/ds-popperjs';
4
7
  import { AutocompleteContext } from '../../AutocompleteCTX.js';
5
- import { StyledPopperWrapper, StyledContainerInline, StyledContainerWithPopper } from './styled.js';
6
- import { Controls } from '../controls/Controls.js';
8
+ import { StyledContainerWithPopper, StyledPopperWrapper } from './styled.js';
7
9
  import { MenuList } from '../menu-list/MenuList.js';
8
- import { jsxs, Fragment } from 'react/jsx-runtime';
9
-
10
- var _Controls, _MenuList, _MenuList2;
10
+ import { useKeyboardNavigation } from './useKeyboardNavigation.js';
11
+ import { AutocompleteDataTestid } from '../../AutocompleteDataTestids.js';
12
+ import { jsxs } from 'react/jsx-runtime';
11
13
 
14
+ var _StyledPopperWrapper;
12
15
  const Container = () => {
13
16
  const {
14
17
  props: {
15
- inline,
16
18
  startPlacementPreference,
19
+ children,
20
+ filter,
17
21
  placementOrderPreference
18
22
  },
19
23
  showPopover,
20
- inputRef,
21
24
  setReferenceElement,
22
25
  setShowPopover,
23
26
  referenceElement
24
27
  } = useContext(AutocompleteContext);
28
+ useEffect(() => {
29
+ const closePopper = () => {
30
+ setShowPopover(false);
31
+ };
32
+
33
+ window.addEventListener('blur', closePopper);
34
+ return () => {
35
+ window.removeEventListener('blur', closePopper);
36
+ };
37
+ }, [setShowPopover]);
25
38
  const handleCloseMenu = useCallback(() => {
26
39
  setShowPopover(false);
27
- if (inputRef.current) inputRef.current.blur();
28
- }, [inputRef, setShowPopover]);
29
- const handleMouseDown = useCallback(e => {
30
- e.preventDefault();
31
- }, []);
32
- const StyledContainer = inline ? StyledContainerInline : StyledContainerWithPopper;
33
- return /*#__PURE__*/jsxs(Fragment, {
34
- children: [/*#__PURE__*/jsxs(StyledContainer, {
35
- ref: setReferenceElement,
36
- children: [_Controls || (_Controls = /*#__PURE__*/_jsx(Controls, {})), inline ? _MenuList || (_MenuList = /*#__PURE__*/_jsx(MenuList, {})) : null]
37
- }), /*#__PURE__*/_jsx(DSPopperJS, {
40
+ }, [setShowPopover]);
41
+ const input = React.Children.only(children);
42
+ const {
43
+ onInputKeyDown
44
+ } = useKeyboardNavigation();
45
+ return /*#__PURE__*/jsxs(StyledContainerWithPopper, {
46
+ ref: setReferenceElement,
47
+ role: "combobox",
48
+ "aria-autocomplete": "list",
49
+ "aria-controls": "autocomplete-listbox",
50
+ "aria-expanded": showPopover,
51
+ onKeyDown: onInputKeyDown,
52
+ "data-testid": AutocompleteDataTestid.CONTAINER,
53
+ children: [input, filter && /*#__PURE__*/_jsx(DSPopperJS, {
38
54
  customOffset: [0, 5],
39
55
  closeContextMenu: handleCloseMenu,
40
56
  referenceElement: referenceElement,
@@ -45,10 +61,9 @@ const Container = () => {
45
61
  withoutArrow: true,
46
62
  withoutAnimation: true,
47
63
  zIndex: 10
48
- }, void 0, /*#__PURE__*/_jsx(StyledPopperWrapper, {
49
- tabIndex: -1,
50
- onMouseDown: handleMouseDown
51
- }, void 0, _MenuList2 || (_MenuList2 = /*#__PURE__*/_jsx(MenuList, {}))))]
64
+ }, void 0, _StyledPopperWrapper || (_StyledPopperWrapper = /*#__PURE__*/_jsx(StyledPopperWrapper, {
65
+ tabIndex: -1
66
+ }, void 0, /*#__PURE__*/_jsx(MenuList, {}))))]
52
67
  });
53
68
  };
54
69
 
@@ -3,11 +3,8 @@ import styled from 'styled-components';
3
3
  const StyledContainerWithPopper = /*#__PURE__*/styled.div.withConfig({
4
4
  componentId: "sc-xupfk9-0"
5
5
  })(["width:100%;height:28px;position:relative;"]);
6
- const StyledContainerInline = /*#__PURE__*/styled.div.withConfig({
7
- componentId: "sc-xupfk9-1"
8
- })(["width:100%;position:relative;"]);
9
6
  const StyledPopperWrapper = /*#__PURE__*/styled.div.withConfig({
10
- componentId: "sc-xupfk9-2"
7
+ componentId: "sc-xupfk9-1"
11
8
  })(["background:#fff;overflow:auto;position:relative;"]);
12
9
 
13
- export { StyledContainerInline, StyledContainerWithPopper, StyledPopperWrapper };
10
+ export { StyledContainerWithPopper, StyledPopperWrapper };
@@ -10,7 +10,7 @@ const isOptionFocuseable = opt => !['section', 'separator'].includes(opt.type);
10
10
  const useKeyboardNavigation = () => {
11
11
  const {
12
12
  props: {
13
- onValueChange,
13
+ onSelect,
14
14
  options
15
15
  },
16
16
  setShowPopover,
@@ -21,25 +21,18 @@ const useKeyboardNavigation = () => {
21
21
  } = useContext(AutocompleteContext);
22
22
  const currentItemIndex = options.findIndex(opt => opt.dsId === focusOptionIdx);
23
23
  const currentItem = options.find(item => item.type === 'option' && item.dsId === focusOptionIdx);
24
- const selectOption = useCallback(e => {
25
- if (onValueChange) onValueChange(currentItem.label, e);
26
- setShowPopover(false);
27
- }, [currentItem, setShowPopover, onValueChange]);
28
24
  const onInputKeyDown = useCallback(e => {
29
- const targetElement = e.target;
30
-
31
- if (['ArrowDown', 'ArrowUp', 'Enter'].includes(e.key) || e.keyCode >= 48 && e.keyCode <= 90) {
25
+ if ((e.keyCode >= 48 && e.keyCode <= 90 || e.key === 'Backspace') && !showPopover) {
32
26
  setShowPopover(true);
33
- } // =============================================================================
27
+ } else if (e.key === 'Tab') setShowPopover(false); // =============================================================================
34
28
  // ENTER AND SPACE KEY SELECT OPTIONS AND OPEN CLOSE THE POPOVER
35
29
  // =============================================================================
36
30
 
37
31
 
38
- if (e.keyCode === 32 && targetElement.value === '' || e.key === 'Enter') {
39
- if (showPopover) {
40
- e.preventDefault();
41
- selectOption(e);
42
- }
32
+ if (e.key === 'Enter' && showPopover) {
33
+ e.preventDefault();
34
+ onSelect(currentItem === null || currentItem === void 0 ? void 0 : currentItem.label, e);
35
+ setShowPopover(false);
43
36
  } // =============================================================================
44
37
  // ARROWS UP AND DOWN
45
38
  // =============================================================================
@@ -52,8 +45,6 @@ const useKeyboardNavigation = () => {
52
45
  const nextItemIndex = findInCircularList(options, currentItemIndex, isOptionFocuseable);
53
46
  setCurrentOption(options[nextItemIndex].dsId);
54
47
  scrollOptionIntoView(options[nextItemIndex].dsId);
55
- } else {
56
- setShowPopover(true);
57
48
  }
58
49
  }
59
50
 
@@ -64,13 +55,6 @@ const useKeyboardNavigation = () => {
64
55
  const nextItemIndex = findInCircularList(options, currentItemIndex, isOptionFocuseable, -1);
65
56
  setCurrentOption(options[nextItemIndex].dsId);
66
57
  scrollOptionIntoView(options[nextItemIndex].dsId);
67
- } else {
68
- setShowPopover(true);
69
- setTimeout(() => {
70
- const nextItemIndex = findInCircularList(options, 0, isOptionFocuseable, -1);
71
- setCurrentOption(options[nextItemIndex].dsId);
72
- scrollOptionIntoView(options[nextItemIndex].dsId);
73
- });
74
58
  }
75
59
  } // =============================================================================
76
60
  // ESCAPE
@@ -80,7 +64,7 @@ const useKeyboardNavigation = () => {
80
64
  if (e.key === 'Escape') {
81
65
  setShowPopover(false);
82
66
  }
83
- }, [scrollOptionIntoView, currentItemIndex, options, showPopover, setCurrentOption, setShowPopover, selectOption]);
67
+ }, [currentItem === null || currentItem === void 0 ? void 0 : currentItem.label, currentItemIndex, onSelect, options, scrollOptionIntoView, setCurrentOption, setShowPopover, showPopover]);
84
68
  return {
85
69
  onInputKeyDown
86
70
  };
@@ -1,83 +1,50 @@
1
1
  import _jsx from '@babel/runtime/helpers/esm/jsx';
2
- import { useContext, useMemo, useCallback } from 'react';
3
- import { DSCircularProgressIndicator } from '@elliemae/ds-circular-progress-indicator';
4
- import { Grid } from '@elliemae/ds-grid';
2
+ import { useContext, useCallback } from 'react';
5
3
  import { StyledListWrapper, StyledVirtualListWrapper, StyledList } from './styled.js';
6
4
  import { AutocompleteDataTestid } from '../../AutocompleteDataTestids.js';
7
5
  import { AutocompleteContext } from '../../AutocompleteCTX.js';
8
- import { useOnElementResize } from '../../utils/hooks/useOnElementResize.js';
9
6
  import { useItemRenderer } from './useItemRenderer.js';
10
- import { useMenuList } from './useMenuList.js';
11
- import { jsx, Fragment } from 'react/jsx-runtime';
7
+ import { jsx } from 'react/jsx-runtime';
12
8
 
13
9
  const MenuList = () => {
14
- var _inputRef$current2;
15
-
16
10
  const {
17
11
  props: {
18
- menuMinWidth,
19
- menuMaxHeight,
20
- options,
21
- isLoading
12
+ options
22
13
  },
23
14
  referenceElement,
24
15
  inputRef,
25
16
  listRef,
26
17
  showPopover,
27
- wrapperListRef,
28
- controlsWrapperRef,
29
18
  virtualListHelpers: {
30
19
  totalSize
31
20
  }
32
21
  } = useContext(AutocompleteContext);
33
22
  const ItemRenderer = useItemRenderer();
34
- useMenuList();
35
- const {
36
- width
37
- } = useOnElementResize(controlsWrapperRef);
38
- const listWidth = useMemo(() => menuMinWidth || "".concat(referenceElement === null || referenceElement === void 0 ? void 0 : referenceElement.offsetWidth), // eslint-disable-next-line react-hooks/exhaustive-deps
39
- [menuMinWidth, referenceElement, width]);
40
23
  const handleOnFocus = useCallback(() => {
41
24
  var _inputRef$current;
42
25
 
43
26
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
44
27
  }, [inputRef]);
45
- return /*#__PURE__*/jsx(StyledListWrapper, {
28
+ return /*#__PURE__*/_jsx(StyledListWrapper, {
46
29
  tabIndex: -1,
47
- ref: wrapperListRef,
48
30
  onMouseDown: e => e.preventDefault(),
49
- minWidth: listWidth,
50
- id: "combo-listbox",
51
- role: "listbox",
52
- children: isLoading && ((_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.value) !== '' ? /*#__PURE__*/_jsx(Grid, {
53
- justifyContent: "center",
54
- alignItems: "center",
31
+ minWidth: referenceElement === null || referenceElement === void 0 ? void 0 : referenceElement.offsetWidth,
32
+ id: "autocomplete-listbox",
33
+ role: "listbox"
34
+ }, void 0, options.length > 0 && /*#__PURE__*/jsx(StyledVirtualListWrapper, {
35
+ tabIndex: -1,
36
+ ref: listRef,
37
+ children: /*#__PURE__*/_jsx(StyledList, {
38
+ tabIndex: -1,
39
+ "aria-expanded": showPopover,
40
+ onFocus: handleOnFocus,
41
+ "data-testid": AutocompleteDataTestid.LIST,
55
42
  style: {
56
- padding: 20
43
+ height: totalSize,
44
+ margin: '8px 0px'
57
45
  }
58
- }, void 0, /*#__PURE__*/_jsx(DSCircularProgressIndicator, {
59
- size: "l",
60
- loading: isLoading,
61
- waiting: false,
62
- showTooltip: false
63
- })) : /*#__PURE__*/jsx(Fragment, {
64
- children: options.length > 0 && /*#__PURE__*/jsx(StyledVirtualListWrapper, {
65
- tabIndex: -1,
66
- maxHeight: menuMaxHeight,
67
- ref: listRef,
68
- children: /*#__PURE__*/_jsx(StyledList, {
69
- tabIndex: -1,
70
- "aria-expanded": showPopover,
71
- onFocus: handleOnFocus,
72
- "data-testid": AutocompleteDataTestid.LIST,
73
- style: {
74
- height: totalSize,
75
- margin: '8px 0px'
76
- }
77
- }, void 0, ItemRenderer)
78
- })
79
- })
80
- });
46
+ }, void 0, ItemRenderer)
47
+ }));
81
48
  };
82
49
 
83
50
  export { MenuList };
@@ -2,23 +2,22 @@ import styled from 'styled-components';
2
2
 
3
3
  const StyledListWrapper = /*#__PURE__*/styled.div.withConfig({
4
4
  componentId: "sc-qt1kwv-0"
5
- })(["min-width:", ";"], props => props.inline ? '100%' : "".concat(props.minWidth, "px"));
5
+ })(["min-width:", ";"], _ref => {
6
+ let {
7
+ minWidth
8
+ } = _ref;
9
+ return minWidth ? "".concat(minWidth, "px") : '100%';
10
+ });
6
11
  const StyledList = /*#__PURE__*/styled.ul.withConfig({
7
12
  componentId: "sc-qt1kwv-1"
8
13
  })(["position:relative;padding:0;"]);
9
14
  const StyledVirtualListWrapper = /*#__PURE__*/styled.div.withConfig({
10
15
  componentId: "sc-qt1kwv-2"
11
- })(["overflow-y:auto;margin-top:", ";max-height:", ";"], _ref => {
12
- let {
13
- withHeader
14
- } = _ref;
15
- return withHeader ? '28px' : '';
16
- }, _ref2 => {
16
+ })(["overflow-y:auto;max-height:", ";"], _ref2 => {
17
17
  let {
18
- maxHeight,
19
- inline
18
+ maxHeight
20
19
  } = _ref2;
21
- return inline ? '' : "".concat(!maxHeight ? '400' : maxHeight, "px");
20
+ return "".concat(!maxHeight ? '400' : maxHeight, "px");
22
21
  });
23
22
 
24
23
  export { StyledList, StyledListWrapper, StyledVirtualListWrapper };
@@ -7,75 +7,69 @@ import 'core-js/modules/esnext.iterator.filter.js';
7
7
  import 'core-js/modules/esnext.async-iterator.for-each.js';
8
8
  import 'core-js/modules/esnext.iterator.for-each.js';
9
9
  import { useContext, useCallback, useMemo } from 'react';
10
- import { SingleMenuItem } from '@elliemae/ds-form';
10
+ import { Section, SingleMenuItem } from '@elliemae/ds-form';
11
11
  import { AutocompleteContext } from '../../AutocompleteCTX.js';
12
- import { isSelected } from '../../utils/listHelper.js';
13
12
  import { AutocompleteDataTestid } from '../../AutocompleteDataTestids.js';
14
13
  import { jsx, Fragment } from 'react/jsx-runtime';
15
14
 
16
15
  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; }
17
16
 
18
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; }
19
-
20
18
  const useItemRenderer = () => {
21
19
  const {
22
20
  props: {
23
21
  options,
24
- onChange,
25
- selectedValues,
26
- onFilter
22
+ onSelect
27
23
  },
28
24
  inputRef,
29
25
  setShowPopover,
30
26
  focusOptionIdx,
31
27
  virtualListHelpers
32
28
  } = useContext(AutocompleteContext);
33
- const {
34
- virtualItems
35
- } = virtualListHelpers;
36
29
  const handleClick = useCallback((option, e) => {
37
- var _inputRef$current;
38
-
39
- if (inputRef.current) inputRef.current.value = option.label;
40
- onFilter(option.label);
41
- onChange(option.label);
30
+ onSelect(option.label, e);
42
31
  setShowPopover(false);
43
- (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
44
32
  e.stopPropagation();
45
33
  e.preventDefault();
46
- }, [onFilter, onChange, setShowPopover, inputRef]);
47
- const handleOnMouseDown = useCallback(e => {
48
- e.preventDefault();
49
- }, []);
50
- const ItemRenderer = useMemo(() => virtualItems.map(vItem => {
51
- const option = options[vItem.index];
52
- const generalProps = {
53
- wrapperStyles: {
54
- position: 'absolute',
55
- top: vItem.start,
56
- left: 0,
57
- width: '100%'
58
- },
59
- key: "".concat(option.dsId),
60
- innerRef: vItem.measureRef
61
- };
34
+ }, [onSelect, setShowPopover]);
35
+ return useMemo(() => {
36
+ if (virtualListHelpers) {
37
+ return virtualListHelpers.virtualItems.map(vItem => {
38
+ const option = options[vItem.index];
39
+ const generalProps = {
40
+ wrapperStyles: {
41
+ position: 'absolute',
42
+ top: vItem.start,
43
+ left: 0,
44
+ width: '100%'
45
+ },
46
+ key: "".concat(option.dsId),
47
+ innerRef: vItem.measureRef
48
+ };
49
+
50
+ if (option.type === 'section') {
51
+ return /*#__PURE__*/jsx(Section, _objectSpread({
52
+ label: option.label
53
+ }, generalProps));
54
+ }
55
+
56
+ if (option.type === 'option') {
57
+ return /*#__PURE__*/jsx(SingleMenuItem, _objectSpread(_objectSpread({}, generalProps), {}, {
58
+ value: option.value,
59
+ label: option.label,
60
+ dataTestid: AutocompleteDataTestid.OPTION,
61
+ disabled: option.disabled,
62
+ onClick: e => handleClick(option, e),
63
+ isActive: option.dsId === focusOptionIdx
64
+ }));
65
+ }
62
66
 
63
- if (option.type === 'option') {
64
- return /*#__PURE__*/jsx(SingleMenuItem, _objectSpread(_objectSpread({}, generalProps), {}, {
65
- value: option.value,
66
- label: option.label,
67
- dataTestid: AutocompleteDataTestid.OPTION,
68
- disabled: option.disabled,
69
- onClick: e => handleClick(option, e),
70
- onMouseDown: handleOnMouseDown,
71
- isActive: option.dsId === focusOptionIdx,
72
- isSelected: isSelected(selectedValues, option)
73
- }));
67
+ return /*#__PURE__*/jsx(Fragment, {});
68
+ });
74
69
  }
75
70
 
76
- return /*#__PURE__*/jsx(Fragment, {});
77
- }), [options, focusOptionIdx, selectedValues, inputRef, virtualItems]);
78
- return ItemRenderer;
71
+ return null;
72
+ }, [options, focusOptionIdx, inputRef, virtualListHelpers]);
79
73
  };
80
74
 
81
75
  export { useItemRenderer };
@@ -1,14 +1,11 @@
1
1
  import { PropTypes } from '@elliemae/ds-props-helpers';
2
2
 
3
3
  /* eslint-disable @typescript-eslint/no-unused-vars */
4
- function noop() {}
5
4
  const propTypes = {
6
- placeholder: PropTypes.string.description('input s placeholder value').defaultValue(''),
7
- options: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).description('List of options').defaultValue([]),
8
- value: PropTypes.oneOfType([PropTypes.string]).description('Array of option or single option selected'),
9
- autoFocus: PropTypes.bool.description('Whether the combo box uses auto focus or not').defaultValue('false'),
10
- hasError: PropTypes.bool.description('Whether the combo box has error or not').defaultValue('false'),
11
- onChange: PropTypes.func.description('function triggered when an option is selected it will send the options selected').defaultValue('')
5
+ options: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired.description('List of options').defaultValue([]),
6
+ filter: PropTypes.string.isRequired.description('String value to filter the options').defaultValue(''),
7
+ onSelect: PropTypes.func.isRequired.description('function triggered when an option is selected it will send the options selected').defaultValue(''),
8
+ children: PropTypes.node.isRequired.description('React component to apply autocomplete functionality').defaultValue('')
12
9
  };
13
10
 
14
- export { noop, propTypes };
11
+ export { propTypes };
@@ -1,26 +1,11 @@
1
1
  import 'core-js/modules/esnext.async-iterator.filter.js';
2
2
  import 'core-js/modules/esnext.iterator.constructor.js';
3
3
  import 'core-js/modules/esnext.iterator.filter.js';
4
- import 'core-js/modules/esnext.async-iterator.some.js';
5
- import 'core-js/modules/esnext.iterator.some.js';
6
4
 
7
5
  const getSelectableOptions = options => options ? options.filter(option => option.type === 'option' && !option.disabled) : [];
8
6
  const getOptions = options => options ? options.filter(option => option.type === 'option') : [];
9
7
  const isSelectedValueEmpty = value => Array.isArray(value) ? value.length === 0 : !value;
10
8
  const isSelectedValueMultiple = value => Array.isArray(value);
11
- const isSelected = (value, activeOption) => {
12
- if (isSelectedValueMultiple(value)) {
13
- const multiValue = value;
14
- return multiValue.some(item => (item === null || item === void 0 ? void 0 : item.value) === (activeOption === null || activeOption === void 0 ? void 0 : activeOption.value));
15
- }
16
-
17
- if (typeof value === 'string') {
18
- return false;
19
- }
20
-
21
- const singleValue = value;
22
- return (singleValue === null || singleValue === void 0 ? void 0 : singleValue.value) === activeOption.value;
23
- };
24
9
  const findInCircularList = function (list, from, criteria) {
25
10
  let step = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
26
11
 
@@ -30,5 +15,12 @@ const findInCircularList = function (list, from, criteria) {
30
15
 
31
16
  return from; // return same item
32
17
  };
18
+ const getFirstOption = options => {
19
+ for (let i = 0; i < options.length; i += 1) if (!['section', 'separator'].includes(options[i].type)) {
20
+ return options[i].dsId;
21
+ }
22
+
23
+ return '';
24
+ };
33
25
 
34
- export { findInCircularList, getOptions, getSelectableOptions, isSelected, isSelectedValueEmpty, isSelectedValueMultiple };
26
+ export { findInCircularList, getFirstOption, getOptions, getSelectableOptions, isSelectedValueEmpty, isSelectedValueMultiple };
@@ -30,6 +30,7 @@ const DSControlledCheckbox = props => {
30
30
  label,
31
31
  hasError,
32
32
  innerRef,
33
+ wrapLabel,
33
34
  tabIndex,
34
35
  ariaLabel: legacyAriaLabel,
35
36
  ariaControls: legacyAriaControls,
@@ -82,7 +83,7 @@ const DSControlledCheckbox = props => {
82
83
  readOnly: readOnly,
83
84
  checked: checked,
84
85
  "data-testid": "ds-checkbox-label"
85
- }, void 0, /*#__PURE__*/_jsx(SimpleTruncatedTooltipText, {
86
+ }, void 0, wrapLabel ? label : /*#__PURE__*/_jsx(SimpleTruncatedTooltipText, {
86
87
  value: label
87
88
  })));
88
89
  };
@@ -10,12 +10,14 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
10
10
 
11
11
  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; }
12
12
  const defaultProps = {
13
+ wrapLabel: false,
13
14
  hasError: false,
14
15
  tabIndex: undefined,
15
16
  checked: false
16
17
  };
17
18
  const propTypes = _objectSpread(_objectSpread({}, globalAttributesPropTypes), {}, {
18
19
  label: PropTypes.string.description('Checkbox Label property. This label is also going to be used as an aria-label for screen readers.'),
20
+ wrapLabel: PropTypes.bool.description('Whether to wrap or truncate label'),
19
21
  hasError: PropTypes.bool.description('Whether the checkbox has error or not.'),
20
22
  innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]).description('Checkbox input ref.')
21
23
  });