@councilbox/councilbox-ui 2.0.0 → 2.0.1

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.
@@ -19,6 +19,8 @@ require("./DropDown.css");
19
19
 
20
20
  var _useDynamicStyles2 = _interopRequireDefault(require("../../HOCs/useDynamicStyles"));
21
21
 
22
+ var _utils = require("../../utils");
23
+
22
24
  var _excluded = ["text", "Component", "items", "id", "type", "open", "icon", "requestClose", "anchorOrigin", "transformOrigin", "styleComponent", "variantButton", "stylesButtonText", "sxButton", "forceClose", "sx", "style", "styles", "prefixClass", "setOpen", "className"];
23
25
 
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -238,6 +240,7 @@ var DropDown = function DropDown(_ref2) {
238
240
  };
239
241
 
240
242
  var handleClick = _react.default.useCallback(function (event) {
243
+ console.log('abre cabrón');
241
244
  event === null || event === void 0 ? void 0 : event.stopPropagation();
242
245
  event === null || event === void 0 ? void 0 : event.preventDefault();
243
246
  setIsOpen(true);
@@ -317,44 +320,7 @@ var DropDown = function DropDown(_ref2) {
317
320
  clearTimeout(timeoutRef.current);
318
321
  }
319
322
  };
320
- }, [isOpen, adjustPopoverPosition, debouncedAdjustPopoverPosition, isVisible]); // const handleOptionClick = React.useCallback(
321
- // (option, event) => {
322
- // event?.stopPropagation();
323
- // event?.preventDefault();
324
- // closeDropdown();
325
- // if (option) {
326
- // option.props?.onClick?.({
327
- // target: { value: option.props?.value },
328
- // });
329
- // }
330
- // },
331
- // [closeDropdown]
332
- // );
333
-
334
- /*
335
- if (React.isValidElement(child)) {
336
- if (child.type === React.Fragment) {
337
- return React.cloneElement(child, {}, React.Children.map(child.props.children, applySpacingStyle));
338
- }
339
- return React.cloneElement(child, {
340
- spacingStyle: child.props.spacingStyle || itemSpacingStyle,
341
- });
342
- }
343
- */
344
- // Esto preguntar a Anxo, tiene que pillar tb fragment con fragment y/o sin fragment. (EJ documentCardFile de ovac)
345
- // const enhancedItems = React.useMemo(
346
- // () => React.Children.map(items, (child, index) => {
347
- // if (React.isValidElement(child)) {
348
- // return React.cloneElement(child, {
349
- // key: `${child.props.children}-${index}`,
350
- // onClick: event => handleOptionClick(child, event),
351
- // });
352
- // }
353
- // return child;
354
- // }),
355
- // [items, handleOptionClick]
356
- // );
357
-
323
+ }, [isOpen, adjustPopoverPosition, debouncedAdjustPopoverPosition, isVisible]);
358
324
 
359
325
  var handleOptionClick = _react.default.useCallback(function (option, event) {
360
326
  event === null || event === void 0 ? void 0 : event.preventDefault();
@@ -368,29 +334,8 @@ var DropDown = function DropDown(_ref2) {
368
334
  }
369
335
  }, [closeDropdown]);
370
336
 
371
- var enhanceChild = function enhanceChild(child, index) {
372
- if ( /*#__PURE__*/_react.default.isValidElement(child)) {
373
- if (child.type === _react.default.Fragment) {
374
- return enhanceNode(child.props.children);
375
- }
376
-
377
- return /*#__PURE__*/_react.default.cloneElement(child, {
378
- key: child.key || index,
379
- onClick: function onClick(event) {
380
- return handleOptionClick(child, event);
381
- }
382
- });
383
- }
384
-
385
- return child;
386
- };
387
-
388
- var enhanceNode = function enhanceNode(node) {
389
- return _react.default.Children.map(node, enhanceChild);
390
- };
391
-
392
337
  var enhancedItems = _react.default.useMemo(function () {
393
- return enhanceNode(items);
338
+ return (0, _utils.enhanceClickableChildren)(items, handleOptionClick);
394
339
  }, [items, handleOptionClick]);
395
340
 
396
341
  return /*#__PURE__*/_react.default.createElement("div", _extends({
@@ -38,7 +38,7 @@
38
38
  overflow: hidden auto;
39
39
  min-width: 1rem;
40
40
  min-height: 1rem;
41
- max-height: calc(100% - 2rem);
41
+ max-height: calc(45%);
42
42
  max-width: calc(100% - 2rem);
43
43
  outline: 0px;
44
44
  opacity: 1;
@@ -23,7 +23,13 @@ var _IconButton = _interopRequireDefault(require("../IconButton/IconButton"));
23
23
 
24
24
  var _useDynamicStyles2 = _interopRequireDefault(require("../../HOCs/useDynamicStyles"));
25
25
 
26
- var _excluded = ["children", "className", "onChange", "onInputChange", "label", "value", "inputValue", "style", "styles", "sx", "prefixClass", "options", "getOptionLabel", "getOptionSelected", "defaultValue", "filterOptions", "freeSolo", "clearOnBlur", "selectOnFocus"];
26
+ var _LoadingSection = _interopRequireDefault(require("../LoadingSection/LoadingSection"));
27
+
28
+ var _autoDetectScroll = require("../../utils/autoDetectScroll");
29
+
30
+ var _utils = require("../../utils");
31
+
32
+ var _excluded = ["children", "className", "onChange", "onInputChange", "label", "value", "inputValue", "style", "styles", "sx", "loadingText", "loading", "prefixClass", "options", "getOptionLabel", "clearable", "getOptionSelected", "defaultValue", "filterOptions", "freeSolo", "clearOnBlur", "selectOnFocus"];
27
33
 
28
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
35
 
@@ -62,12 +68,26 @@ var InputAutocomplete = function InputAutocomplete(_ref) {
62
68
  style = _ref.style,
63
69
  styles = _ref.styles,
64
70
  sx = _ref.sx,
71
+ _ref$loadingText = _ref.loadingText,
72
+ loadingText = _ref$loadingText === void 0 ? 'Buscando resultados...' : _ref$loadingText,
73
+ _ref$loading = _ref.loading,
74
+ loading = _ref$loading === void 0 ? false : _ref$loading,
65
75
  propPrefixClass = _ref.prefixClass,
66
76
  options = _ref.options,
67
77
  _ref$getOptionLabel = _ref.getOptionLabel,
68
78
  getOptionLabel = _ref$getOptionLabel === void 0 ? function (option) {
79
+ if (!option) {
80
+ return '';
81
+ }
82
+
83
+ if (typeof option === 'string') {
84
+ return option;
85
+ }
86
+
69
87
  return option.label || option.text || option.translation || option.value;
70
88
  } : _ref$getOptionLabel,
89
+ _ref$clearable = _ref.clearable,
90
+ clearable = _ref$clearable === void 0 ? true : _ref$clearable,
71
91
  _ref$getOptionSelecte = _ref.getOptionSelected,
72
92
  getOptionSelected = _ref$getOptionSelecte === void 0 ? function (option, valueSelected) {
73
93
  return option === valueSelected;
@@ -79,7 +99,7 @@ var InputAutocomplete = function InputAutocomplete(_ref) {
79
99
  _ref$clearOnBlur = _ref.clearOnBlur,
80
100
  clearOnBlur = _ref$clearOnBlur === void 0 ? true : _ref$clearOnBlur,
81
101
  _ref$selectOnFocus = _ref.selectOnFocus,
82
- selectOnFocus = _ref$selectOnFocus === void 0 ? false : _ref$selectOnFocus,
102
+ selectOnFocus = _ref$selectOnFocus === void 0 ? !freeSolo : _ref$selectOnFocus,
83
103
  props = _objectWithoutProperties(_ref, _excluded);
84
104
 
85
105
  var _useDynamicStyles = (0, _useDynamicStyles2.default)(sx),
@@ -88,130 +108,142 @@ var InputAutocomplete = function InputAutocomplete(_ref) {
88
108
 
89
109
  var prefixClass = propPrefixClass || dynamicPrefixClass;
90
110
 
91
- var _React$useState = _react.default.useState(false),
111
+ var _React$useState = _react.default.useState({
112
+ showDropdown: false,
113
+ showSearchInput: false
114
+ }),
92
115
  _React$useState2 = _slicedToArray(_React$useState, 2),
93
- isOpen = _React$useState2[0],
94
- setIsOpen = _React$useState2[1];
95
-
96
- var _React$useState3 = _react.default.useState(false),
116
+ uiState = _React$useState2[0],
117
+ setUIstate = _React$useState2[1];
118
+
119
+ var _React$useState3 = _react.default.useState({
120
+ top: null,
121
+ bottom: null,
122
+ left: '0px',
123
+ width: '0px'
124
+ }),
97
125
  _React$useState4 = _slicedToArray(_React$useState3, 2),
98
- isClosing = _React$useState4[0],
99
- setIsClosing = _React$useState4[1];
126
+ positions = _React$useState4[0],
127
+ setPositions = _React$useState4[1];
100
128
 
101
- var _React$useState5 = _react.default.useState(value || null),
129
+ var _React$useState5 = _react.default.useState(false),
102
130
  _React$useState6 = _slicedToArray(_React$useState5, 2),
103
- selectedValue = _React$useState6[0],
104
- setSelectedValue = _React$useState6[1];
131
+ isClosing = _React$useState6[0],
132
+ setIsClosing = _React$useState6[1];
105
133
 
106
- var _React$useState7 = _react.default.useState(propInputValue || ''),
134
+ var _React$useState7 = _react.default.useState(value || null),
107
135
  _React$useState8 = _slicedToArray(_React$useState7, 2),
108
- inputValue = _React$useState8[0],
109
- setInputValue = _React$useState8[1];
136
+ internalValue = _React$useState8[0],
137
+ setInternalValue = _React$useState8[1];
110
138
 
111
- var _React$useState9 = _react.default.useState(options),
139
+ var _React$useState9 = _react.default.useState(propInputValue || value && getOptionLabel(value) || ''),
112
140
  _React$useState10 = _slicedToArray(_React$useState9, 2),
113
- filteredOptions = _React$useState10[0],
114
- setFilteredOptions = _React$useState10[1];
141
+ internalInputValue = _React$useState10[0],
142
+ setInternalInputValue = _React$useState10[1];
143
+
144
+ var searchTextRef = _react.default.useRef(freeSolo ? internalInputValue : '');
145
+
146
+ var selectedValue = value !== undefined ? value : internalValue;
147
+ var inputValue = propInputValue !== undefined ? propInputValue : internalInputValue;
115
148
 
116
149
  var selectRef = _react.default.useRef(null);
117
150
 
118
151
  var dropdownRef = _react.default.useRef(null);
119
152
 
120
- var shouldShowDropdown = isOpen && filteredOptions.length > 0;
153
+ var inputRef = _react.default.useRef(null);
121
154
 
122
- _react.default.useEffect(function () {
123
- if (propInputValue !== undefined) {
124
- setInputValue(propInputValue);
125
- }
126
- }, [propInputValue]);
127
-
128
- _react.default.useEffect(function () {
129
- setSelectedValue(value);
130
- }, [value]);
155
+ var optionContainerRef = _react.default.useRef(null);
131
156
 
132
- _react.default.useEffect(function () {
157
+ var filteredOptions = _react.default.useMemo(function () {
133
158
  var newFilteredOptions = options;
159
+ var searchValue = searchTextRef.current;
134
160
 
135
- if (filterOptions) {
136
- newFilteredOptions = filterOptions(options, {
137
- inputValue: inputValue
138
- });
139
- } else {
140
- newFilteredOptions = options.filter(function (option) {
141
- var optionLabel = getOptionLabel(option);
142
- return optionLabel.toLowerCase().includes(inputValue.toLowerCase());
143
- });
161
+ if (searchValue) {
162
+ if (filterOptions) {
163
+ newFilteredOptions = filterOptions(options, {
164
+ inputValue: searchValue
165
+ });
166
+ } else {
167
+ newFilteredOptions = options.filter(function (option) {
168
+ var optionLabel = getOptionLabel(option);
169
+ return optionLabel && searchValue && optionLabel.toLowerCase().includes(searchValue.toLowerCase());
170
+ });
171
+ }
144
172
  }
145
173
 
146
- setFilteredOptions(newFilteredOptions);
147
- }, [inputValue, options]);
174
+ return newFilteredOptions;
175
+ }, [options, searchTextRef.current]);
176
+
177
+ var _useKeyItemNavigation = (0, _utils.useKeyItemNavigation)({
178
+ containerRef: optionContainerRef
179
+ }),
180
+ handleKeyDown = _useKeyItemNavigation.handleKeyDown;
181
+
182
+ var shouldShowDropdown = uiState.showDropdown && filteredOptions.length > 0 && !isClosing || loading;
148
183
 
149
184
  var closeDropdown = function closeDropdown() {
150
185
  setIsClosing(true);
151
186
  setTimeout(function () {
152
- setIsOpen(false);
187
+ setUIstate(_objectSpread(_objectSpread({}, uiState), {}, {
188
+ showDropdown: false,
189
+ showSearchInput: !clearOnBlur
190
+ }));
153
191
  setIsClosing(false);
192
+
193
+ if (!freeSolo) {
194
+ searchTextRef.current = '';
195
+ }
154
196
  }, 150);
155
197
  };
156
198
 
157
- var handleOptionClick = function handleOptionClick(e, option) {
158
- var optionLabel = getOptionLabel(option);
159
-
199
+ var updateInputValue = function updateInputValue(e, newValue) {
160
200
  if (props.inputValue === undefined) {
161
- setInputValue(optionLabel);
201
+ setInternalInputValue(newValue);
162
202
  }
163
203
 
164
- if (props.value === undefined) {
165
- setSelectedValue(option);
204
+ if (onInputChange) {
205
+ onInputChange(e, newValue);
166
206
  }
167
207
 
208
+ searchTextRef.current = newValue;
209
+ };
210
+
211
+ var updateValue = function updateValue(e, newValue) {
168
212
  if (onChange) {
169
- onChange(e, option);
213
+ onChange(e, newValue);
214
+ } else {
215
+ setInternalValue(newValue);
170
216
  }
217
+ };
171
218
 
219
+ var handleOptionClick = function handleOptionClick(e, option) {
220
+ var optionLabel = getOptionLabel(option);
221
+ updateInputValue(e, optionLabel);
222
+ updateValue(e, option);
172
223
  closeDropdown();
173
224
  };
174
225
 
175
226
  var handleInputChange = function handleInputChange(e) {
176
- var newInputValue = e.target.value;
177
-
178
- if (props.inputValue === undefined) {
179
- setInputValue(newInputValue);
180
- }
227
+ var newValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
228
+ var newInputValue = newValue || e.target.value;
181
229
 
182
- if (onInputChange) {
183
- onInputChange(e, newInputValue);
230
+ if (freeSolo) {
231
+ updateValue(e, newInputValue);
184
232
  }
185
233
 
186
- setIsOpen(true);
234
+ updateInputValue(e, newInputValue);
187
235
  };
188
236
 
189
237
  var handleInputBlur = function handleInputBlur(e) {
190
- if (!freeSolo) {
191
- var matchedOption = options.find(function (option) {
192
- return getOptionLabel(option).toLowerCase() === inputValue.toLowerCase();
193
- });
194
-
195
- if (matchedOption) {
196
- if (props.value === undefined) {
197
- setSelectedValue(matchedOption);
198
- }
238
+ handleInputChange(e, selectedValue ? getOptionLabel(selectedValue) : '');
199
239
 
200
- if (props.inputValue === undefined) {
201
- setInputValue(getOptionLabel(matchedOption));
202
- }
203
-
204
- if (onChange) {
205
- onChange(e, matchedOption);
206
- }
207
- } else if (props.inputValue === undefined) {
208
- setInputValue(selectedValue ? getOptionLabel(selectedValue) : '');
240
+ if (clearOnBlur) {
241
+ if (!freeSolo) {
242
+ handleInputChange(e, selectedValue ? getOptionLabel(selectedValue) : '');
209
243
  }
210
244
  }
211
245
 
212
- if (clearOnBlur) {
213
- closeDropdown();
214
- }
246
+ closeDropdown();
215
247
  };
216
248
 
217
249
  var handleInputFocus = function handleInputFocus(e) {
@@ -219,54 +251,58 @@ var InputAutocomplete = function InputAutocomplete(_ref) {
219
251
  e.target.select();
220
252
  }
221
253
 
222
- setIsOpen(true);
254
+ setUIstate(_objectSpread(_objectSpread({}, uiState), {}, {
255
+ showDropdown: true,
256
+ showSearchInput: true
257
+ }));
223
258
  };
224
259
 
225
260
  var updateDropdownPosition = function updateDropdownPosition() {
226
261
  var _selectRef$current, _selectRef$current2, _selectRef$current2$c;
227
262
 
228
- if (selectRef.current && selectRef !== null && selectRef !== void 0 && (_selectRef$current = selectRef.current) !== null && _selectRef$current !== void 0 && _selectRef$current.children[0] && selectRef !== null && selectRef !== void 0 && (_selectRef$current2 = selectRef.current) !== null && _selectRef$current2 !== void 0 && (_selectRef$current2$c = _selectRef$current2.children[0]) !== null && _selectRef$current2$c !== void 0 && _selectRef$current2$c.children[0] && dropdownRef.current) {
263
+ if (selectRef.current && selectRef !== null && selectRef !== void 0 && (_selectRef$current = selectRef.current) !== null && _selectRef$current !== void 0 && _selectRef$current.children[0] && selectRef !== null && selectRef !== void 0 && (_selectRef$current2 = selectRef.current) !== null && _selectRef$current2 !== void 0 && (_selectRef$current2$c = _selectRef$current2.children[0]) !== null && _selectRef$current2$c !== void 0 && _selectRef$current2$c.children[0]) {
229
264
  var _selectRef$current3, _selectRef$current3$c, _selectRef$current3$c2;
230
265
 
231
266
  var selectRect = selectRef === null || selectRef === void 0 ? void 0 : (_selectRef$current3 = selectRef.current) === null || _selectRef$current3 === void 0 ? void 0 : (_selectRef$current3$c = _selectRef$current3.children[0]) === null || _selectRef$current3$c === void 0 ? void 0 : (_selectRef$current3$c2 = _selectRef$current3$c.children[0]) === null || _selectRef$current3$c2 === void 0 ? void 0 : _selectRef$current3$c2.getBoundingClientRect();
232
- var dropdownHeight = dropdownRef.current.offsetHeight + 15;
233
- var isOverflowingBelow = selectRect.bottom + dropdownHeight > window.innerHeight;
234
- var topPosition = isOverflowingBelow ? window.innerHeight - dropdownHeight : selectRect.bottom;
235
- dropdownRef.current.style.top = "".concat(topPosition, "px");
236
- dropdownRef.current.style.left = "".concat(selectRect.left, "px");
237
- dropdownRef.current.style.width = "".concat(selectRect.width, "px");
267
+ var isOverflowingBelow = selectRect.bottom > window.innerHeight / 2;
268
+
269
+ var newPositions = _objectSpread({}, positions);
270
+
271
+ if (isOverflowingBelow) {
272
+ newPositions.bottom = "".concat(window.innerHeight - selectRect.top, "px");
273
+ delete newPositions.top;
274
+ } else {
275
+ delete newPositions.bottom;
276
+ newPositions.top = "".concat(selectRect.bottom, "px");
277
+ }
278
+
279
+ newPositions.left = "".concat(selectRect.left, "px");
280
+ newPositions.width = "".concat(selectRect.width, "px");
281
+ setPositions(_objectSpread({}, newPositions));
238
282
  }
239
283
  };
240
284
 
241
285
  _react.default.useEffect(function () {
242
286
  updateDropdownPosition();
243
- }, [isOpen]);
287
+ }, [shouldShowDropdown, document.body.clientHeight > window.innerHeight]);
244
288
 
245
289
  _react.default.useEffect(function () {
246
- var handleResize = function handleResize() {
247
- if (isOpen) {
248
- updateDropdownPosition();
249
- }
250
- };
251
-
252
- window.addEventListener('resize', handleResize);
253
- return function () {
254
- window.removeEventListener('resize', handleResize);
255
- };
256
- }, [isOpen]);
290
+ var referenceEl = (0, _autoDetectScroll.unwrapElement)(inputRef.current);
291
+ var ancestors = (0, _autoDetectScroll.getOverflowAncestors)(referenceEl) || [];
292
+ ancestors.forEach(function (ancestor) {
293
+ ancestor.addEventListener('scroll', updateDropdownPosition, {
294
+ passive: true
295
+ });
296
+ ancestor.addEventListener('resize', updateDropdownPosition);
297
+ });
298
+ }, [inputRef.current]);
257
299
 
258
300
  return /*#__PURE__*/_react.default.createElement("div", {
259
- className: prefixClass("cbx-inputAutocomplete-container ".concat(isOpen ? 'cbx-inputAutocomplete-container-open' : '')),
260
- onClick: function onClick() {
261
- if (isOpen && !inputValue) {
262
- closeDropdown();
263
- } else {
264
- setIsOpen(true);
265
- }
266
- },
301
+ className: prefixClass("cbx-inputAutocomplete-container ".concat(uiState.showSearchInput ? 'cbx-inputAutocomplete-container-open' : '')),
267
302
  style: _objectSpread(_objectSpread(_objectSpread({
268
303
  width: props.fullWidth && '100%'
269
304
  }, styles), style), stylesInLine),
305
+ id: "cbx-prueba",
270
306
  ref: selectRef
271
307
  }, /*#__PURE__*/_react.default.createElement(_InputText.default, _extends({
272
308
  label: label,
@@ -275,48 +311,77 @@ var InputAutocomplete = function InputAutocomplete(_ref) {
275
311
  shrink: !!inputValue || !!selectedValue,
276
312
  prefixClass: prefixClass,
277
313
  fullWidth: props.fullWidth,
314
+ ref: inputRef,
315
+ onKeyDown: function onKeyDown(e) {
316
+ e.preventDefault();
317
+
318
+ if (e.keyCode === 9) {
319
+ closeDropdown();
320
+ }
321
+
322
+ if (e.key === 'Escape') {
323
+ closeDropdown();
324
+ }
325
+
326
+ handleKeyDown(e);
327
+ },
278
328
  onChange: handleInputChange,
279
- onFocus: handleInputFocus,
280
- onBlur: handleInputBlur,
329
+ onClick: handleInputFocus,
281
330
  defaultValue: defaultValue,
282
331
  InputProps: {
283
- endAdornment: inputValue && /*#__PURE__*/_react.default.createElement(_IconButton.default, {
332
+ endAdornment: clearable && inputValue && (loading ? /*#__PURE__*/_react.default.createElement(_LoadingSection.default, {
333
+ size: 20,
334
+ thickness: 3,
335
+ color: "var(--primary)"
336
+ }) : /*#__PURE__*/_react.default.createElement(_IconButton.default, {
284
337
  prefixClass: prefixClass,
285
338
  className: "cbx-inputAutocomplete-icon-button",
286
339
  onClick: function onClick(e) {
287
340
  e.stopPropagation();
288
341
  e.preventDefault();
289
- setFilteredOptions(options);
290
-
291
- if (props.inputValue === undefined) {
292
- setInputValue('');
293
- }
294
-
295
- if (onInputChange) {
296
- onInputChange(e, '');
297
- }
342
+ searchTextRef.current = '';
343
+ updateInputValue(e, '');
344
+ updateValue(e, null);
345
+ inputRef.current.focus();
298
346
  },
299
347
  icon: /*#__PURE__*/_react.default.createElement("i", {
300
348
  className: "ri-close-fill",
301
349
  tabIndex: "-1"
302
350
  })
303
- })
351
+ }))
304
352
  }
305
353
  }, props, {
306
354
  type: 'autocomplete'
307
- })), isOpen && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
355
+ })), (uiState.showDropdown || loading) && (positions.top || positions.bottom) && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
308
356
  className: prefixClass('cbx-inputAutocomplete-presentation')
309
357
  }, /*#__PURE__*/_react.default.createElement(OutsideClickHandler, {
310
358
  excludedRefs: [selectRef, dropdownRef],
311
359
  onOutsideClick: function onOutsideClick() {
312
- closeDropdown();
360
+ handleInputBlur({
361
+ target: {
362
+ value: searchTextRef.current
363
+ }
364
+ });
313
365
  }
314
- }), /*#__PURE__*/_react.default.createElement("div", {
315
- className: prefixClass("cbx-inputAutocomplete-options-container ".concat(shouldShowDropdown && !isClosing ? 'cbx-inputAutocomplete-options-container-open' : 'cbx-inputAutocomplete-options-container-close')),
366
+ }), shouldShowDropdown && /*#__PURE__*/_react.default.createElement("div", {
367
+ className: prefixClass("cbx-inputAutocomplete-options-container ".concat(uiState.showDropdown && !isClosing ? 'cbx-inputAutocomplete-options-container-open' : 'cbx-inputAutocomplete-options-container-close')),
368
+ style: _objectSpread({}, positions),
369
+ onKeyDown: function onKeyDown(e) {
370
+ if (e.keyCode === 9) {
371
+ closeDropdown();
372
+ }
373
+
374
+ if (e.key === 'Escape') {
375
+ closeDropdown();
376
+ }
377
+
378
+ handleKeyDown(e);
379
+ },
316
380
  ref: dropdownRef
317
381
  }, /*#__PURE__*/_react.default.createElement("ul", {
318
- className: prefixClass('cbx-inputAutocomplete-options')
319
- }, filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (item, index) {
382
+ className: prefixClass('cbx-inputAutocomplete-options'),
383
+ ref: optionContainerRef
384
+ }, !loading && (filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map(function (item, index) {
320
385
  return /*#__PURE__*/_react.default.createElement(_MenuItem.default, _extends({}, item, {
321
386
  value: item.value || getOptionLabel(item),
322
387
  key: "".concat(item.value || getOptionLabel(item), "-").concat(index),
@@ -326,7 +391,9 @@ var InputAutocomplete = function InputAutocomplete(_ref) {
326
391
  active: getOptionSelected(item, selectedValue),
327
392
  fullWidth: props.fullWidth
328
393
  }), getOptionLabel(item));
329
- })))), document.body));
394
+ })), loading && /*#__PURE__*/_react.default.createElement(_MenuItem.default, {
395
+ fullWidth: props.fullWidth
396
+ }, loadingText)))), document.body));
330
397
  };
331
398
 
332
399
  InputAutocomplete.displayName = "InputAutocomplete";
@@ -345,7 +412,7 @@ var OutsideClickHandler = function OutsideClickHandler(_ref2) {
345
412
  });
346
413
 
347
414
  if (wrapperRef.current && !wrapperRef.current.contains(event.target) && !clickedExcluded) {
348
- onOutsideClick();
415
+ onOutsideClick(event);
349
416
  }
350
417
  };
351
418
 
@@ -23,11 +23,15 @@
23
23
  max-width: 100%;
24
24
  }
25
25
 
26
- .cbx-menuItem:hover {
26
+ .cbx-menuItem:hover, .cbx-menuItem:focus {
27
27
  text-decoration: none;
28
28
  background-color: var(--gray1);
29
29
  }
30
30
 
31
+ .cbx-menuItem:focus {
32
+ outline: none !important;
33
+ }
34
+
31
35
  .cbx-menuItem-container {
32
36
  justify-content: space-between;
33
37
  }
@@ -118,6 +118,10 @@ var MenuItem = function MenuItem(_ref) {
118
118
  onClick: function onClick(e) {
119
119
  return handleClick(e);
120
120
  },
121
+ onKeyDown: function onKeyDown(e) {
122
+ return e.key === 'Enter' && handleClick(e);
123
+ },
124
+ tabIndex: 0,
121
125
  style: _objectSpread(_objectSpread({}, style), stylesInLine),
122
126
  value: "".concat(value)
123
127
  }, props), /*#__PURE__*/_react.default.createElement("div", {