@elliemae/ds-controlled-form 2.3.0-next.5 → 2.3.0-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/cjs/controlled-combobox/ComboBox.js +3 -6
  2. package/cjs/controlled-combobox/ComboBoxCTX.js +3 -3
  3. package/cjs/controlled-combobox/ComboboxDataTestids.js +2 -1
  4. package/cjs/controlled-combobox/config/useComboBox.js +15 -70
  5. package/cjs/controlled-combobox/config/useCorrectOptions.js +77 -0
  6. package/cjs/controlled-combobox/parts/a11y-messages/FocusMenuItem.js +46 -0
  7. package/cjs/controlled-combobox/parts/a11y-messages/{MultiAllyMessages.js → SelectedValuesAllyMsg.js} +16 -7
  8. package/cjs/controlled-combobox/parts/a11y-messages/index.js +4 -4
  9. package/cjs/controlled-combobox/parts/container/Container.js +40 -15
  10. package/cjs/controlled-combobox/parts/container/styled.js +9 -6
  11. package/cjs/controlled-combobox/parts/controls/Controls.js +30 -19
  12. package/cjs/controlled-combobox/parts/controls/styled.js +22 -10
  13. package/cjs/controlled-combobox/parts/controls/useOnPillsNavigation.js +51 -0
  14. package/cjs/controlled-combobox/parts/controls-input/ControlsInput.js +9 -9
  15. package/cjs/controlled-combobox/parts/controls-input/useControlsInput.js +14 -8
  16. package/cjs/controlled-combobox/parts/dropdown-indicator/DropdownIndicator.js +6 -3
  17. package/cjs/controlled-combobox/parts/dropdown-indicator/styled.js +2 -3
  18. package/cjs/controlled-combobox/parts/header-list/HeaderList.js +6 -6
  19. package/cjs/controlled-combobox/parts/header-list/useHeaderListHandlers.js +4 -4
  20. package/cjs/controlled-combobox/parts/menu-list/MenuList.js +9 -11
  21. package/cjs/controlled-combobox/parts/menu-list/styled.js +1 -1
  22. package/cjs/controlled-combobox/parts/menu-list/useItemRenderer.js +11 -11
  23. package/cjs/controlled-combobox/parts/menu-list/useMenuList.js +11 -13
  24. package/cjs/controlled-combobox/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +19 -15
  25. package/cjs/controlled-combobox/parts/multi-selected-values-container/useGroupPills.js +5 -5
  26. package/cjs/controlled-combobox/react-desc-prop-types.js +42 -0
  27. package/cjs/controlled-combobox/{index.d.js → sharedTypes.js} +0 -0
  28. package/cjs/controlled-combobox/utils/hooks/useKeyboardNavigation.js +19 -15
  29. package/cjs/controlled-combobox/utils/listHelper.js +2 -2
  30. package/esm/controlled-combobox/ComboBox.js +4 -7
  31. package/esm/controlled-combobox/ComboBoxCTX.js +4 -4
  32. package/esm/controlled-combobox/ComboboxDataTestids.js +2 -1
  33. package/esm/controlled-combobox/config/useComboBox.js +17 -72
  34. package/esm/controlled-combobox/config/useCorrectOptions.js +73 -0
  35. package/esm/controlled-combobox/parts/a11y-messages/FocusMenuItem.js +38 -0
  36. package/esm/controlled-combobox/parts/a11y-messages/SelectedValuesAllyMsg.js +34 -0
  37. package/esm/controlled-combobox/parts/a11y-messages/index.js +2 -2
  38. package/esm/controlled-combobox/parts/container/Container.js +38 -15
  39. package/esm/controlled-combobox/parts/container/styled.js +9 -6
  40. package/esm/controlled-combobox/parts/controls/Controls.js +31 -20
  41. package/esm/controlled-combobox/parts/controls/styled.js +22 -10
  42. package/esm/controlled-combobox/parts/controls/useOnPillsNavigation.js +47 -0
  43. package/esm/controlled-combobox/parts/controls-input/ControlsInput.js +9 -9
  44. package/esm/controlled-combobox/parts/controls-input/useControlsInput.js +14 -8
  45. package/esm/controlled-combobox/parts/dropdown-indicator/DropdownIndicator.js +6 -3
  46. package/esm/controlled-combobox/parts/dropdown-indicator/styled.js +3 -3
  47. package/esm/controlled-combobox/parts/header-list/HeaderList.js +6 -6
  48. package/esm/controlled-combobox/parts/header-list/useHeaderListHandlers.js +4 -4
  49. package/esm/controlled-combobox/parts/menu-list/MenuList.js +10 -12
  50. package/esm/controlled-combobox/parts/menu-list/styled.js +1 -1
  51. package/esm/controlled-combobox/parts/menu-list/useItemRenderer.js +11 -11
  52. package/esm/controlled-combobox/parts/menu-list/useMenuList.js +11 -13
  53. package/esm/controlled-combobox/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +20 -16
  54. package/esm/controlled-combobox/parts/multi-selected-values-container/useGroupPills.js +5 -5
  55. package/esm/controlled-combobox/{propTypes.js → react-desc-prop-types.js} +16 -6
  56. package/esm/controlled-combobox/{index.d.js → sharedTypes.js} +0 -0
  57. package/esm/controlled-combobox/utils/hooks/useKeyboardNavigation.js +19 -15
  58. package/esm/controlled-combobox/utils/listHelper.js +2 -2
  59. package/package.json +30 -38
  60. package/types/controlled-combobox/ComboBox.d.ts +4 -70
  61. package/types/controlled-combobox/ComboBoxCTX.d.ts +4 -3
  62. package/types/controlled-combobox/ComboboxDataTestids.d.ts +1 -0
  63. package/types/controlled-combobox/config/useComboBox.d.ts +3 -2
  64. package/types/controlled-combobox/config/useCorrectOptions.d.ts +3 -0
  65. package/types/controlled-combobox/parts/a11y-messages/FocusMenuItem.d.ts +3 -0
  66. package/types/controlled-combobox/parts/a11y-messages/SelectedValuesAllyMsg.d.ts +3 -0
  67. package/types/controlled-combobox/parts/a11y-messages/index.d.ts +2 -2
  68. package/types/controlled-combobox/parts/controls/styled.d.ts +10 -2
  69. package/types/controlled-combobox/parts/controls/useOnPillsNavigation.d.ts +4 -0
  70. package/types/controlled-combobox/parts/dropdown-indicator/styled.d.ts +2 -1
  71. package/types/controlled-combobox/react-desc-prop-types.d.ts +53 -0
  72. package/types/controlled-combobox/sharedTypes.d.ts +29 -0
  73. package/types/controlled-combobox/utils/hooks/useKeyboardNavigation.d.ts +1 -1
  74. package/types/controlled-combobox/utils/listHelper.d.ts +7 -7
  75. package/types/controlled-date-time-picker/parts/Pickers/Calendar/Styleds.d.ts +3 -12
  76. package/types/controlled-date-time-picker/parts/Pickers/CalendarWithTimeWheel/Styleds.d.ts +1 -4
  77. package/types/controlled-date-time-picker/parts/Pickers/TimeWheel/Styleds.d.ts +3 -12
  78. package/types/controlled-date-time-picker/parts/Styleds.d.ts +1 -4
  79. package/cjs/controlled-combobox/config/constants.js +0 -14
  80. package/cjs/controlled-combobox/config/useGetPropsWithDefault.js +0 -11
  81. package/cjs/controlled-combobox/parts/a11y-messages/SingleAllyMessages.js +0 -28
  82. package/cjs/controlled-combobox/parts/single-selected-value-container/SingleSelectedValueContainer.js +0 -28
  83. package/cjs/controlled-combobox/parts/single-selected-value-container/index.js +0 -9
  84. package/cjs/controlled-combobox/parts/single-selected-value-container/styled.js +0 -15
  85. package/cjs/controlled-combobox/propTypes.js +0 -28
  86. package/esm/controlled-combobox/config/constants.js +0 -10
  87. package/esm/controlled-combobox/config/useGetPropsWithDefault.js +0 -7
  88. package/esm/controlled-combobox/parts/a11y-messages/MultiAllyMessages.js +0 -25
  89. package/esm/controlled-combobox/parts/a11y-messages/SingleAllyMessages.js +0 -20
  90. package/esm/controlled-combobox/parts/single-selected-value-container/SingleSelectedValueContainer.js +0 -20
  91. package/esm/controlled-combobox/parts/single-selected-value-container/index.js +0 -1
  92. package/esm/controlled-combobox/parts/single-selected-value-container/styled.js +0 -7
  93. package/types/controlled-combobox/config/constants.d.ts +0 -8
  94. package/types/controlled-combobox/config/useGetPropsWithDefault.d.ts +0 -2
  95. package/types/controlled-combobox/parts/a11y-messages/MultiAllyMessages.d.ts +0 -3
  96. package/types/controlled-combobox/parts/a11y-messages/SingleAllyMessages.d.ts +0 -3
  97. package/types/controlled-combobox/parts/single-selected-value-container/SingleSelectedValueContainer.d.ts +0 -3
  98. package/types/controlled-combobox/parts/single-selected-value-container/index.d.ts +0 -1
  99. package/types/controlled-combobox/parts/single-selected-value-container/styled.d.ts +0 -1
  100. package/types/controlled-combobox/propTypes.d.ts +0 -60
  101. package/types/controlled-combobox/tests/combobox-special-keys.test.d.ts +0 -1
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
+ var dsPropsHelpers = require('@elliemae/ds-props-helpers');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
16
+
17
+ 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; }
18
+
19
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
+ const ComboboxPropTypes = _objectSpread(_objectSpread({}, dsPropsHelpers.globalAttributesPropTypes), {}, {
21
+ placeholder: dsPropsHelpers.PropTypes.string.description('input s placeholder value').defaultValue(''),
22
+ options: dsPropsHelpers.PropTypes.oneOfType([dsPropsHelpers.PropTypes.array, dsPropsHelpers.PropTypes.object]).description('List of options').defaultValue([]),
23
+ selectedValues: dsPropsHelpers.PropTypes.oneOfType([dsPropsHelpers.PropTypes.arrayOf(dsPropsHelpers.PropTypes.object), dsPropsHelpers.PropTypes.object]).description('Array of option or single option selected'),
24
+ disabled: dsPropsHelpers.PropTypes.bool.description('wheter or not the input is disabled').defaultValue('false'),
25
+ autoFocus: dsPropsHelpers.PropTypes.bool.description('Whether the combo box uses auto focus or not').defaultValue('false'),
26
+ hasError: dsPropsHelpers.PropTypes.bool.description('Whether the combo box has error or not').defaultValue('false'),
27
+ onChange: dsPropsHelpers.PropTypes.func.description('function triggered when an option is selected it will send the options selected').defaultValue(''),
28
+ onSelectAll: dsPropsHelpers.PropTypes.func.description('function triggered when ALL button is selected from the header menu list').defaultValue(''),
29
+ onFilter: dsPropsHelpers.PropTypes.func.description('function triggered when user type in the combobox input').defaultValue(''),
30
+ onCreate: dsPropsHelpers.PropTypes.func.description('function triggered when user select "create" a new item whenever is not a match in the all option list').defaultValue(''),
31
+ onClearAll: dsPropsHelpers.PropTypes.func.description('function triggered when user select CLEAR button from the header menu list').defaultValue(''),
32
+ onCancel: dsPropsHelpers.PropTypes.func.description('function triggered when user press ESC key').defaultValue(''),
33
+ onMenuOpen: dsPropsHelpers.PropTypes.func.description('function triggered when user open the menu list').defaultValue(''),
34
+ inputMinWidth: dsPropsHelpers.PropTypes.any.description('Minimum width for the combo box input controller').defaultValue(undefined),
35
+ menuMinWidth: dsPropsHelpers.PropTypes.any.description('Minimum width for the dropdown menu').defaultValue(undefined),
36
+ menuMaxHeight: dsPropsHelpers.PropTypes.any.description('Maximum height for the dropdown menu').defaultValue(undefined),
37
+ withoutPortal: dsPropsHelpers.PropTypes.bool.description('Whether the combobox menu is rendered in a portal or not').defaultValue(false),
38
+ zIndex: dsPropsHelpers.PropTypes.number.description('The z-index of the combobox menu').defaultValue(10),
39
+ innerRef: dsPropsHelpers.PropTypes.object.description('ref to the component s container')
40
+ });
41
+
42
+ exports.ComboboxPropTypes = ComboboxPropTypes;
@@ -9,7 +9,7 @@ var React = require('react');
9
9
  var ComboBoxCTX = require('../../ComboBoxCTX.js');
10
10
  var listHelper = require('../listHelper.js');
11
11
 
12
- const isOptionFocuseable = opt => !['section', 'separator'].includes(opt.type);
12
+ const isOptionFocuseable = opt => !['section', 'separator'].includes(opt.type) && !opt.disabled;
13
13
 
14
14
  const useKeyboardNavigation = () => {
15
15
  const {
@@ -23,13 +23,13 @@ const useKeyboardNavigation = () => {
23
23
  options,
24
24
  selectedValues,
25
25
  onFilter,
26
- withoutPortal
26
+ withoutPortal,
27
+ innerRef
27
28
  },
28
29
  setShowPopover,
29
30
  showPopover,
30
31
  setShowSelectedValue,
31
32
  focusOptionIdx,
32
- inputRef,
33
33
  setCurrentOption,
34
34
  scrollOptionIntoView,
35
35
  selectAllCheckboxRef,
@@ -40,16 +40,17 @@ const useKeyboardNavigation = () => {
40
40
  const currentItem = options.find(item => item.dsId === focusOptionIdx);
41
41
  const selectOption = React.useCallback(() => {
42
42
  if (multiple) {
43
- if (inputRef.current) onFilter(inputRef.current.value);
43
+ if (innerRef.current) onFilter(innerRef.current.value);
44
44
  } else {
45
45
  onFilter('');
46
- if (inputRef.current) inputRef.current.value = '';
46
+ if (innerRef.current) innerRef.current.value = '';
47
47
  setShowSelectedValue(true);
48
48
  }
49
49
 
50
- onChange(options.find(item => item.dsId === focusOptionIdx));
51
- setShowPopover(multiple ? true : !showPopover);
52
- }, [multiple, options, focusOptionIdx, setShowPopover, showPopover, onFilter, inputRef, setShowSelectedValue, onChange]);
50
+ const selectedOption = options.find(item => item.dsId === focusOptionIdx);
51
+ onChange(selectedOption);
52
+ if (!selectedOption.disabled && !multiple) setShowPopover(false);
53
+ }, [multiple, options, focusOptionIdx, setShowPopover, onFilter, innerRef, setShowSelectedValue, onChange]);
53
54
  const onInputKeyDown = React.useCallback(e => {
54
55
  const targetElement = e.target; // =============================================================================
55
56
  // CUSTOM KEYS
@@ -62,7 +63,7 @@ const useKeyboardNavigation = () => {
62
63
  if (e.key === 'Enter' && (currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) === 'creatable') {
63
64
  onCreate(targetElement.value);
64
65
  onFilter('');
65
- if (inputRef.current) inputRef.current.value = '';
66
+ if (innerRef.current) innerRef.current.value = '';
66
67
  return;
67
68
  } // =============================================================================
68
69
  // Enter and space on selection
@@ -71,6 +72,7 @@ const useKeyboardNavigation = () => {
71
72
 
72
73
  if (e.key === 'Enter' || e.keyCode === 32 && e.altKey) {
73
74
  e.preventDefault();
75
+ e.stopPropagation();
74
76
 
75
77
  if (!showPopover && !inline) {
76
78
  setShowPopover(true);
@@ -92,6 +94,7 @@ const useKeyboardNavigation = () => {
92
94
 
93
95
  if (e.key === 'ArrowDown') {
94
96
  e.preventDefault();
97
+ e.stopPropagation();
95
98
 
96
99
  if (showPopover || inline) {
97
100
  const nextItemIndex = listHelper.findInCircularList(options, currentItemIndex, isOptionFocuseable);
@@ -104,6 +107,7 @@ const useKeyboardNavigation = () => {
104
107
 
105
108
  if (e.key === 'ArrowUp') {
106
109
  e.preventDefault();
110
+ e.stopPropagation();
107
111
 
108
112
  if (showPopover || inline) {
109
113
  const nextItemIndex = listHelper.findInCircularList(options, currentItemIndex, isOptionFocuseable, -1);
@@ -123,13 +127,13 @@ const useKeyboardNavigation = () => {
123
127
 
124
128
 
125
129
  if (e.key === 'Escape') {
126
- var _inputRef$current;
130
+ var _innerRef$current;
127
131
 
128
132
  if (onCancel) onCancel();
129
133
 
130
- if (inputRef.current && ((_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value) !== '') {
134
+ if (innerRef.current && ((_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.value) !== '') {
131
135
  onFilter('');
132
- inputRef.current.value = '';
136
+ innerRef.current.value = '';
133
137
  }
134
138
 
135
139
  if (!inline) setShowPopover(false);
@@ -158,10 +162,10 @@ const useKeyboardNavigation = () => {
158
162
  e.preventDefault();
159
163
  element.focus();
160
164
  }
161
- }
165
+ } // if (e.key === 'Tab' && multiple) {
166
+ // }
162
167
 
163
- if (e.key === 'Tab' && inline) ;
164
- }, [currentItemIndex, options, currentItem, inputRef, multiple, showPopover, selectedValues, inline, scrollOptionIntoView, onKeyDown, onSelectAll, onChange, onCreate, onFilter, setCurrentOption, setShowPopover, setShowSelectedValue, selectOption, onCancel, selectAllCheckboxRef, toggleSelectionButtonRef, withoutPortal]);
168
+ }, [currentItemIndex, options, currentItem, innerRef, multiple, showPopover, selectedValues, inline, scrollOptionIntoView, onKeyDown, onSelectAll, onChange, onCreate, onFilter, setCurrentOption, setShowPopover, setShowSelectedValue, selectOption, onCancel, selectAllCheckboxRef, toggleSelectionButtonRef, withoutPortal]);
165
169
  return {
166
170
  onInputKeyDown
167
171
  };
@@ -8,8 +8,8 @@ require('core-js/modules/esnext.iterator.filter.js');
8
8
  require('core-js/modules/esnext.async-iterator.some.js');
9
9
  require('core-js/modules/esnext.iterator.some.js');
10
10
 
11
- const getSelectableOptions = options => options ? options.filter(option => option.type === 'option' && !option.disabled) : [];
12
- const getOptions = options => options ? options.filter(option => option.type === 'option') : [];
11
+ const getSelectableOptions = options => options.filter(option => option.type === 'option' && !option.disabled);
12
+ const getOptions = options => options.filter(option => option.type === 'option');
13
13
  const isSelectedValueEmpty = value => Array.isArray(value) ? value.length === 0 : !value;
14
14
  const isSelectedValueMultiple = value => Array.isArray(value);
15
15
  const isSelected = (value, activeOption) => {
@@ -1,17 +1,14 @@
1
1
  import _jsx from '@babel/runtime/helpers/esm/jsx';
2
2
  import 'react';
3
- import { describe } from 'react-desc';
4
- import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
3
+ import { describe } from '@elliemae/ds-props-helpers';
5
4
  import { useComboBox } from './config/useComboBox.js';
6
5
  import { Container } from './parts/container/Container.js';
7
- import { propTypes } from './propTypes.js';
8
- import { defaultProps, ComboBoxContext } from './ComboBoxCTX.js';
6
+ import { ComboBoxContext } from './ComboBoxCTX.js';
7
+ import { ComboboxPropTypes } from './react-desc-prop-types.js';
9
8
 
10
9
  var _Container;
11
10
 
12
11
  const DSComboBox = props => {
13
- const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
14
- useValidateTypescriptPropTypes(propsWithDefault, propTypes);
15
12
  const ctx = useComboBox(props);
16
13
  return /*#__PURE__*/_jsx(ComboBoxContext.Provider, {
17
14
  value: ctx
@@ -19,6 +16,6 @@ const DSComboBox = props => {
19
16
  };
20
17
 
21
18
  const DSComboBoxWithSchema = describe(DSComboBox);
22
- DSComboBoxWithSchema.propTypes = propTypes;
19
+ DSComboBoxWithSchema.propTypes = ComboboxPropTypes;
23
20
 
24
21
  export { DSComboBox, DSComboBoxWithSchema };
@@ -1,4 +1,4 @@
1
- import { createContext, createRef } from 'react';
1
+ import { createRef, createContext } from 'react';
2
2
  import { noop } from 'lodash';
3
3
 
4
4
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -14,13 +14,14 @@ const defaultProps = {
14
14
  onClearAll: noop,
15
15
  onSelectAll: noop,
16
16
  onCreate: noop,
17
- withToggle: false,
17
+ onBlur: noop,
18
18
  withoutPortal: true,
19
19
  zIndex: 10,
20
20
  onChange: noop,
21
21
  onKeyDown: noop,
22
22
  onFilter: noop,
23
- onMenuOpen: noop
23
+ onMenuOpen: noop,
24
+ innerRef: /*#__PURE__*/createRef()
24
25
  };
25
26
  const defaultContext = {
26
27
  props: defaultProps,
@@ -32,7 +33,6 @@ const defaultContext = {
32
33
  setHasFocus: noop,
33
34
  pillGroupRef: /*#__PURE__*/createRef(),
34
35
  setReferenceElement: noop,
35
- inputRef: /*#__PURE__*/createRef(),
36
36
  listRef: /*#__PURE__*/createRef(),
37
37
  wrapperListRef: /*#__PURE__*/createRef(),
38
38
  controlsWrapperRef: /*#__PURE__*/createRef(),
@@ -7,7 +7,8 @@ const ComboboxDataTestid = {
7
7
  DROPDOWN: 'combobox-dropdown-btn',
8
8
  OPTION: 'combobox-option',
9
9
  SELECT_ALL_CHECKBOX: 'combobox-select-all-checkbox',
10
- SHOW_SELECTED_OPTIONS_TOGGLE: 'combobox-selected-options-toggle'
10
+ SHOW_SELECTED_OPTIONS_TOGGLE: 'combobox-selected-options-toggle',
11
+ ALLY_SELECTED_VALUES: 'combobox-ally-selected-values'
11
12
  };
12
13
 
13
14
  export { ComboboxDataTestid };
@@ -1,93 +1,40 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import 'core-js/modules/web.dom-collections.iterator.js';
3
- import 'core-js/modules/esnext.async-iterator.for-each.js';
4
- import 'core-js/modules/esnext.iterator.constructor.js';
5
- import 'core-js/modules/esnext.iterator.for-each.js';
6
- import 'core-js/modules/esnext.async-iterator.find.js';
7
- import 'core-js/modules/esnext.iterator.find.js';
8
1
  import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
9
3
  import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import 'core-js/modules/web.dom-collections.iterator.js';
10
8
  import { useState, useRef, useCallback, useMemo } from 'react';
11
- import { noop } from 'lodash';
12
- import { v4 } from 'uuid';
13
9
  import { useVirtual } from 'react-virtual';
14
- import { useGetComboBoxWithDefaultsProps } from './useGetPropsWithDefault.js';
10
+ import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
11
+ import { defaultProps } from '../ComboBoxCTX.js';
12
+ import { ComboboxPropTypes } from '../react-desc-prop-types.js';
13
+ import { useCorrectOptions } from './useCorrectOptions.js';
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
18
  const useComboBox = props => {
19
+ const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);
20
+ useValidateTypescriptPropTypes(propsWithDefaults, ComboboxPropTypes);
20
21
  const [showPopover, setShowPopover] = useState(false);
21
22
  const [referenceElement, setReferenceElement] = useState(null);
22
23
  const [showSelectedValue, setShowSelectedValue] = useState(false);
23
24
  const [showSelectedOptions, setShowSelectedOptions] = useState(false);
24
25
  const [hasFocus, setHasFocus] = useState(false);
25
26
  const [focusOptionIdx, setCurrentOption] = useState('');
26
- const inputRef = useRef(null);
27
27
  const listRef = useRef(null);
28
28
  const wrapperListRef = useRef(null);
29
29
  const selectedOptionsRef = useRef(null);
30
30
  const controlsWrapperRef = useRef(null);
31
31
  const selectAllCheckboxRef = useRef(null);
32
32
  const toggleSelectionButtonRef = useRef(null);
33
- const pillGroupRef = useRef(null);
34
- const propsWithDefaults = useGetComboBoxWithDefaultsProps(props);
35
- const {
36
- options,
37
- selectedValues,
38
- onCreate
39
- } = propsWithDefaults; // ---------------------------------------------------------------------------
33
+ const pillGroupRef = useRef(null); // ---------------------------------------------------------------------------
40
34
  // Menu Options with/out selected filter
41
35
  // ---------------------------------------------------------------------------
42
36
 
43
- const selectedValuesWithSections = useCallback(() => {
44
- var _items2;
45
-
46
- const multiSelectedValue = selectedValues;
47
- const items = [];
48
- options.forEach(option => {
49
- const isSelectedValue = multiSelectedValue.find(item => item.dsId === option.dsId);
50
-
51
- if (isSelectedValue) {
52
- items.push(option);
53
- }
54
-
55
- if (option.type === 'section') {
56
- var _items;
57
-
58
- if (((_items = items[items.length - 1]) === null || _items === void 0 ? void 0 : _items.type) === 'section') {
59
- items[items.length - 1] = option;
60
- } else {
61
- items.push(option);
62
- }
63
- }
64
- });
65
-
66
- if (((_items2 = items[items.length - 1]) === null || _items2 === void 0 ? void 0 : _items2.type) === 'section') {
67
- items.pop();
68
- }
69
-
70
- return items;
71
- }, [options, selectedValues]);
72
- const correctOptions = useMemo(() => {
73
- if (showSelectedOptions && Array.isArray(selectedValues) && selectedValues.length > 0) {
74
- return selectedValuesWithSections();
75
- }
76
-
77
- if (onCreate !== noop && inputRef.current && inputRef.current.value !== '') {
78
- var _inputRef$current;
79
-
80
- const creatableUuid = v4();
81
- const creatableItem = {
82
- dsId: "creatable-".concat(creatableUuid),
83
- label: (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.value,
84
- type: 'creatable'
85
- };
86
- return [creatableItem, ...options];
87
- }
88
-
89
- return options;
90
- }, [options, onCreate, selectedValuesWithSections, selectedValues, showSelectedOptions]); // ===========================================================================
37
+ const correctOptions = useCorrectOptions(propsWithDefaults, showSelectedOptions); // ===========================================================================
91
38
  // Virtualization setup
92
39
  // ===========================================================================
93
40
 
@@ -100,11 +47,10 @@ const useComboBox = props => {
100
47
  // Scroll into view function
101
48
  // ===========================================================================
102
49
 
103
- const scrollOptionIntoView = useCallback(function (dsId) {
104
- let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
50
+ const scrollOptionIntoView = useCallback(dsId => {
51
+ virtualListHelpers.scrollToIndex(correctOptions.findIndex(opt => opt.dsId === dsId), {
105
52
  align: 'center'
106
- };
107
- virtualListHelpers.scrollToIndex(correctOptions.findIndex(opt => opt.dsId === dsId), opts);
53
+ });
108
54
  }, [correctOptions, virtualListHelpers]);
109
55
  const ctx = useMemo(() => ({
110
56
  props: _objectSpread(_objectSpread({}, propsWithDefaults), {}, {
@@ -113,7 +59,6 @@ const useComboBox = props => {
113
59
  virtualListHelpers,
114
60
  showPopover,
115
61
  referenceElement,
116
- inputRef,
117
62
  showSelectedValue,
118
63
  listRef,
119
64
  focusOptionIdx,
@@ -132,7 +77,7 @@ const useComboBox = props => {
132
77
  setShowSelectedValue,
133
78
  setReferenceElement,
134
79
  setShowPopover
135
- }), [scrollOptionIntoView, correctOptions, propsWithDefaults, virtualListHelpers, focusOptionIdx, showSelectedValue, wrapperListRef, showSelectedOptions, showPopover, pillGroupRef, referenceElement, inputRef, selectedOptionsRef, controlsWrapperRef, selectAllCheckboxRef, toggleSelectionButtonRef, hasFocus, listRef]);
80
+ }), [scrollOptionIntoView, correctOptions, propsWithDefaults, virtualListHelpers, focusOptionIdx, showSelectedValue, wrapperListRef, showSelectedOptions, showPopover, pillGroupRef, referenceElement, selectedOptionsRef, controlsWrapperRef, selectAllCheckboxRef, toggleSelectionButtonRef, hasFocus, listRef]);
136
81
  return ctx;
137
82
  };
138
83
 
@@ -0,0 +1,73 @@
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+ import 'core-js/modules/esnext.async-iterator.find.js';
5
+ import 'core-js/modules/esnext.iterator.find.js';
6
+ import 'core-js/modules/web.dom-collections.iterator.js';
7
+ import { useCallback, useMemo } from 'react';
8
+ import { v4 } from 'uuid';
9
+ import { noop } from 'lodash';
10
+
11
+ const useCorrectOptions = (propsWithDefaults, showSelectedOptions) => {
12
+ const {
13
+ options,
14
+ selectedValues,
15
+ onCreate,
16
+ innerRef
17
+ } = propsWithDefaults;
18
+ const selectedValuesWithSections = useCallback(() => {
19
+ var _items2;
20
+
21
+ const multiSelectedValue = selectedValues;
22
+ const items = [];
23
+ options.forEach(option => {
24
+ const isSelectedValue = multiSelectedValue.find(item => item.dsId === option.dsId);
25
+
26
+ if (isSelectedValue) {
27
+ items.push(option);
28
+ }
29
+
30
+ if (option.type === 'section') {
31
+ var _items;
32
+
33
+ if (((_items = items[items.length - 1]) === null || _items === void 0 ? void 0 : _items.type) === 'section') {
34
+ items[items.length - 1] = option;
35
+ } else {
36
+ items.push(option);
37
+ }
38
+ }
39
+ });
40
+
41
+ if (((_items2 = items[items.length - 1]) === null || _items2 === void 0 ? void 0 : _items2.type) === 'section') {
42
+ items.pop();
43
+ }
44
+
45
+ return items;
46
+ }, [options, selectedValues]);
47
+ const correctOptions = useMemo(() => {
48
+ if (showSelectedOptions && Array.isArray(selectedValues) && selectedValues.length > 0) {
49
+ return selectedValuesWithSections();
50
+ }
51
+
52
+ if (onCreate !== noop && innerRef.current && innerRef.current.value !== '' && options.findIndex(option => {
53
+ var _innerRef$current;
54
+
55
+ return option.type === 'option' && option.label === (innerRef === null || innerRef === void 0 ? void 0 : (_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.value);
56
+ }) === -1) {
57
+ var _innerRef$current2;
58
+
59
+ const creatableUuid = v4();
60
+ const creatableItem = {
61
+ dsId: "creatable-".concat(creatableUuid),
62
+ label: (_innerRef$current2 = innerRef.current) === null || _innerRef$current2 === void 0 ? void 0 : _innerRef$current2.value,
63
+ type: 'creatable'
64
+ };
65
+ return [creatableItem, ...options];
66
+ }
67
+
68
+ return options;
69
+ }, [options, onCreate, innerRef, selectedValuesWithSections, selectedValues, showSelectedOptions]);
70
+ return correctOptions;
71
+ };
72
+
73
+ export { useCorrectOptions };
@@ -0,0 +1,38 @@
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'core-js/modules/esnext.async-iterator.find.js';
3
+ import 'core-js/modules/esnext.iterator.constructor.js';
4
+ import 'core-js/modules/esnext.iterator.find.js';
5
+ import { useContext, useMemo } from 'react';
6
+ import { ComboBoxContext } from '../../ComboBoxCTX.js';
7
+ import { StyledA11ySelectedValues } from './styled.js';
8
+ import { getSelectableOptions } from '../../utils/listHelper.js';
9
+ import { jsx, Fragment } from 'react/jsx-runtime';
10
+
11
+ const FocusMenuItem = () => {
12
+ const {
13
+ props: {
14
+ options
15
+ },
16
+ focusOptionIdx,
17
+ showPopover
18
+ } = useContext(ComboBoxContext);
19
+ const selectabledOptions = getSelectableOptions(options);
20
+ const focusOption = options.find(option => option.dsId === focusOptionIdx);
21
+ const focusSelectableOptionIdx = selectabledOptions.findIndex(option => option.dsId === focusOptionIdx);
22
+ const msg = useMemo(() => {
23
+ if (showPopover) {
24
+ return /*#__PURE__*/_jsx(StyledA11ySelectedValues, {
25
+ "aria-live": "polite",
26
+ "aria-atomic": "false",
27
+ "aria-relevant": "additions text"
28
+ }, void 0, "option ".concat(focusOption === null || focusOption === void 0 ? void 0 : focusOption.label, " focused.").concat(focusSelectableOptionIdx + 1, " of ").concat(selectabledOptions.length, " "));
29
+ }
30
+
31
+ return /*#__PURE__*/jsx(Fragment, {});
32
+ }, [showPopover, focusOption, focusSelectableOptionIdx, selectabledOptions]);
33
+ return /*#__PURE__*/jsx(Fragment, {
34
+ children: msg
35
+ });
36
+ };
37
+
38
+ export { FocusMenuItem };
@@ -0,0 +1,34 @@
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'core-js/modules/esnext.async-iterator.map.js';
3
+ import 'core-js/modules/esnext.iterator.map.js';
4
+ import { useContext, useMemo } from 'react';
5
+ import { ComboBoxContext } from '../../ComboBoxCTX.js';
6
+ import { StyledA11ySelectedValues } from './styled.js';
7
+ import { ComboboxDataTestid } from '../../ComboboxDataTestids.js';
8
+
9
+ const SelectedValuesAllyMsg = () => {
10
+ const {
11
+ props: {
12
+ selectedValues
13
+ }
14
+ } = useContext(ComboBoxContext);
15
+ const msg = useMemo(() => {
16
+ if (Array.isArray(selectedValues)) {
17
+ return "Options selected: ".concat(selectedValues.map(item => item.label).join(', '));
18
+ }
19
+
20
+ if (selectedValues) {
21
+ return "Option selected: ".concat(selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.label);
22
+ }
23
+
24
+ return '';
25
+ }, [selectedValues]);
26
+ return /*#__PURE__*/_jsx(StyledA11ySelectedValues, {
27
+ "data-testid": ComboboxDataTestid.ALLY_SELECTED_VALUES,
28
+ "aria-live": "polite",
29
+ "aria-atomic": "false",
30
+ "aria-relevant": "additions text"
31
+ }, void 0, msg);
32
+ };
33
+
34
+ export { SelectedValuesAllyMsg };
@@ -1,2 +1,2 @@
1
- export { MultiAllyMessages } from './MultiAllyMessages.js';
2
- export { SingleAllyMessages } from './SingleAllyMessages.js';
1
+ export { SelectedValuesAllyMsg } from './SelectedValuesAllyMsg.js';
2
+ export { FocusMenuItem } from './FocusMenuItem.js';
@@ -1,5 +1,13 @@
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
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
1
7
  import _jsx from '@babel/runtime/helpers/esm/jsx';
8
+ import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
2
9
  import { useContext, useCallback } from 'react';
10
+ import { useGetGlobalAttributes } from '@elliemae/ds-props-helpers';
3
11
  import { DSPopperJS } from '@elliemae/ds-popperjs';
4
12
  import { ComboBoxContext } from '../../ComboBoxCTX.js';
5
13
  import { StyledPopperWrapper, StyledContainerInline, StyledContainerWithPopper } from './styled.js';
@@ -9,38 +17,53 @@ import { jsxs, Fragment } from 'react/jsx-runtime';
9
17
 
10
18
  var _Controls, _MenuList, _MenuList2;
11
19
 
20
+ const _excluded = ["placeholder", "onKeyDown", "onChange"];
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
12
26
  const Container = () => {
13
27
  const {
14
- props: {
15
- inline,
16
- startPlacementPreference,
17
- placementOrderPreference,
18
- withoutPortal,
19
- zIndex
20
- },
28
+ props,
21
29
  showPopover,
22
- inputRef,
30
+ innerRef,
23
31
  setReferenceElement,
24
32
  setShowPopover,
25
33
  referenceElement
26
34
  } = useContext(ComboBoxContext);
35
+ const {
36
+ inline,
37
+ disabled,
38
+ startPlacementPreference,
39
+ placementOrderPreference,
40
+ withoutPortal,
41
+ zIndex
42
+ } = props;
27
43
  const handleCloseMenu = useCallback(() => {
28
44
  setShowPopover(false);
29
- if (inputRef.current) inputRef.current.blur();
30
- }, [inputRef, setShowPopover]);
45
+ if (innerRef.current) innerRef.current.blur();
46
+ }, [innerRef, setShowPopover]);
31
47
  const handleMouseDown = useCallback(e => {
32
48
  e.preventDefault();
33
49
  }, []);
34
50
  const handleOnClickContainer = useCallback(() => {
35
- setShowPopover(!showPopover);
36
- }, [setShowPopover, showPopover]);
51
+ if (!disabled) setShowPopover(!showPopover);
52
+ }, [setShowPopover, disabled, showPopover]);
37
53
  const StyledContainer = inline ? StyledContainerInline : StyledContainerWithPopper;
54
+ const globalAttributes = useGetGlobalAttributes(props, {
55
+ onClick: handleOnClickContainer
56
+ }); // Removing possible collisionable props
57
+
58
+ const rest = _objectWithoutProperties(globalAttributes, _excluded);
59
+
38
60
  return /*#__PURE__*/jsxs(Fragment, {
39
- children: [/*#__PURE__*/jsxs(StyledContainer, {
61
+ children: [/*#__PURE__*/jsxs(StyledContainer, _objectSpread(_objectSpread({
40
62
  ref: setReferenceElement,
41
- onClick: handleOnClickContainer,
63
+ onClick: handleOnClickContainer
64
+ }, rest), {}, {
42
65
  children: [_Controls || (_Controls = /*#__PURE__*/_jsx(Controls, {})), inline ? _MenuList || (_MenuList = /*#__PURE__*/_jsx(MenuList, {})) : null]
43
- }), !inline ? /*#__PURE__*/_jsx(DSPopperJS, {
66
+ })), !inline ? /*#__PURE__*/_jsx(DSPopperJS, {
44
67
  customOffset: [0, 5],
45
68
  closeContextMenu: handleCloseMenu,
46
69
  referenceElement: referenceElement,
@@ -1,13 +1,16 @@
1
1
  import styled from 'styled-components';
2
2
 
3
- const StyledContainerWithPopper = /*#__PURE__*/styled.div.withConfig({
3
+ const StyledGenericContainer = /*#__PURE__*/styled.div.withConfig({
4
4
  componentId: "sc-16uoof1-0"
5
- })(["width:100%;height:28px;position:relative;"]);
6
- const StyledContainerInline = /*#__PURE__*/styled.div.withConfig({
5
+ })(["position:relative;"]);
6
+ const StyledContainerWithPopper = /*#__PURE__*/styled(StyledGenericContainer).withConfig({
7
7
  componentId: "sc-16uoof1-1"
8
- })(["width:100%;position:relative;"]);
9
- const StyledPopperWrapper = /*#__PURE__*/styled.div.withConfig({
8
+ })(["width:100%;height:28px;"]);
9
+ const StyledContainerInline = /*#__PURE__*/styled(StyledGenericContainer).withConfig({
10
10
  componentId: "sc-16uoof1-2"
11
- })(["background:#fff;overflow:auto;position:relative;"]);
11
+ })(["width:100%;"]);
12
+ const StyledPopperWrapper = /*#__PURE__*/styled(StyledGenericContainer).withConfig({
13
+ componentId: "sc-16uoof1-3"
14
+ })(["overflow:auto;"]);
12
15
 
13
16
  export { StyledContainerInline, StyledContainerWithPopper, StyledPopperWrapper };