@synerise/ds-collector 0.6.27 → 0.6.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.6.28](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@0.6.27...@synerise/ds-collector@0.6.28) (2023-10-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **collector:** added event capture for "add" ([ce1ec7f](https://github.com/Synerise/synerise-design/commit/ce1ec7f145133b820d5a03dbe0542d74a4b27119))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [0.6.27](https://github.com/Synerise/synerise-design/compare/@synerise/ds-collector@0.6.26...@synerise/ds-collector@0.6.27) (2023-10-18)
7
18
 
8
19
  **Note:** Version bump only for package @synerise/ds-collector
package/dist/Collector.js CHANGED
@@ -95,6 +95,13 @@ var Collector = function Collector(_ref) {
95
95
  var displayLookupKey = useMemo(function () {
96
96
  return (lookupConfig == null ? void 0 : lookupConfig.display) || 'text';
97
97
  }, [lookupConfig]);
98
+ var focusInput = useCallback(function () {
99
+ if (inputRef != null && inputRef.current) {
100
+ inputRef.current.focus({
101
+ preventScroll: true
102
+ });
103
+ }
104
+ }, [inputRef]);
98
105
  var suggestionsIncludesItem = useCallback(function (item) {
99
106
  return filteredSuggestions.some(function (suggestion) {
100
107
  var _suggestion$filterLoo, _suggestion$filterLoo2;
@@ -114,16 +121,12 @@ var Collector = function Collector(_ref) {
114
121
  var onFocusCallback = useCallback(function (event) {
115
122
  event.preventDefault();
116
123
 
117
- if (!event.target.classList.contains(COLLECTOR_CLASSNAME)) {
118
- if (!!inputRef && !!inputRef.current) {
119
- inputRef.current.focus({
120
- preventScroll: true
121
- });
122
- }
123
-
124
+ if (event.target.classList.contains(COLLECTOR_CLASSNAME)) {
125
+ focusInput();
126
+ } else {
124
127
  setFocused(true);
125
128
  }
126
- }, [inputRef]);
129
+ }, [focusInput]);
127
130
  var filterSuggestions = useCallback(function (val) {
128
131
  var filtered = filterValueSuggestions(suggestions, selectedValues, val, filterLookupKey);
129
132
  setFilteredSuggestions(filtered);
@@ -147,14 +150,17 @@ var Collector = function Collector(_ref) {
147
150
  if (!enableCustomFilteringSuggestions) {
148
151
  setFilteredSuggestions([]);
149
152
  }
150
-
151
- !searchValue && allowMultipleValues && setValue(''); // eslint-disable-next-line react-hooks/exhaustive-deps
152
153
  }, [allowMultipleValues, allowCustomValue, selected, enableCustomFilteringSuggestions]);
153
154
  useEffect(function () {
155
+ if (!searchValue && allowMultipleValues) {
156
+ setValue('');
157
+ return;
158
+ }
159
+
154
160
  if (searchValue !== undefined && searchValue !== null) {
155
161
  setValue(searchValue);
156
162
  }
157
- }, [searchValue]);
163
+ }, [allowMultipleValues, searchValue]);
158
164
  useEffect(function () {
159
165
  if (fixedHeight) {
160
166
  setShowGradient(isOverflown(mainContentRef));
@@ -195,11 +201,13 @@ var Collector = function Collector(_ref) {
195
201
  var newValue = createItem(value);
196
202
 
197
203
  if (!newValue) {
204
+ setValue('');
198
205
  return;
199
206
  }
200
207
 
201
208
  if (allowMultipleValues) {
202
209
  onItemSelect(newValue);
210
+ setValue('');
203
211
  } else {
204
212
  onConfirm && onConfirm([newValue]);
205
213
  !keepSearchQueryOnSelect && clear();
@@ -258,19 +266,27 @@ var Collector = function Collector(_ref) {
258
266
  return Number((_containerRef$current = containerRef.current) == null ? void 0 : _containerRef$current.offsetWidth) - DROPDOWN_PADDING;
259
267
  }, [containerRef]);
260
268
 
261
- var focusInput = function focusInput() {
262
- if (inputRef != null && inputRef.current) {
263
- inputRef.current.focus({
264
- preventScroll: true
265
- });
266
- }
269
+ var handleDropdownClick = function handleDropdownClick() {
270
+ focusInput();
267
271
  };
268
272
 
269
- var handleDropdownClick = function handleDropdownClick() {
273
+ var handleDropdownSelect = function handleDropdownSelect(item) {
274
+ onItemSelect && onItemSelect(item);
275
+
276
+ if (!allowMultipleValues && !keepSearchQueryOnSelect && item[filterLookupKey]) {
277
+ setValue(item[filterLookupKey]);
278
+ } else {
279
+ clear();
280
+ }
281
+
270
282
  focusInput();
271
283
  };
272
284
 
273
- var handleChange = disableSearch ? undefined : function (event) {
285
+ var handleInput = disableSearch ? undefined : function (event) {
286
+ if ('inputType' in event.nativeEvent && event.nativeEvent.inputType === 'insertFromPaste' && allowMultipleValues && allowPaste) {
287
+ return;
288
+ }
289
+
274
290
  onSearchValueChange && onSearchValueChange(event.target.value);
275
291
  setValue(event.target.value);
276
292
  if (!enableCustomFilteringSuggestions) filterSuggestions(event.target.value);
@@ -317,7 +333,7 @@ var Collector = function Collector(_ref) {
317
333
  onKeyDown: handleKeyDown,
318
334
  ref: inputRef,
319
335
  value: value,
320
- onChange: handleChange,
336
+ onInput: handleInput,
321
337
  disabled: disabled,
322
338
  transparent: !!disableSearch,
323
339
  hidden: !!disableSearch && !!selectedValues.length,
@@ -331,11 +347,7 @@ var Collector = function Collector(_ref) {
331
347
  return /*#__PURE__*/React.createElement(S.Container, {
332
348
  ref: containerRef,
333
349
  onKeyDown: function onKeyDown(event) {
334
- focusWithArrowKeys(event, 'ds-search-item', function () {
335
- (inputRef == null ? void 0 : inputRef.current) && inputRef.current.focus({
336
- preventScroll: true
337
- });
338
- });
350
+ focusWithArrowKeys(event, 'ds-search-item', focusInput);
339
351
  !value && scrollWithHorizontalArrow(mainContentRef, event);
340
352
  }
341
353
  }, (label || showCount) && /*#__PURE__*/React.createElement(S.ContentAbove, null, label && /*#__PURE__*/React.createElement(S.Label, null, label), showCount && renderCountLabel()), /*#__PURE__*/React.createElement(S.CollectorInput, {
@@ -369,17 +381,7 @@ var Collector = function Collector(_ref) {
369
381
  dropdownItemHeight: dropdownItemHeight,
370
382
  value: value,
371
383
  visible: isFocused && !disabled && (filteredSuggestions.length > 0 || !!value && allowMultipleValues && allowCustomValue),
372
- onSelect: function onSelect(item) {
373
- onItemSelect && onItemSelect(item);
374
-
375
- if (!keepSearchQueryOnSelect && item[filterLookupKey]) {
376
- setValue(item[filterLookupKey]);
377
- } else {
378
- clear();
379
- }
380
-
381
- focusInput();
382
- },
384
+ onSelect: handleDropdownSelect,
383
385
  onClick: handleDropdownClick,
384
386
  renderItem: renderItem,
385
387
  showAddButton: allowCustomValue && allowMultipleValues,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-collector",
3
- "version": "0.6.27",
3
+ "version": "0.6.28",
4
4
  "description": "Collector UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,14 +33,14 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-button": "^0.18.5",
37
- "@synerise/ds-divider": "^0.6.2",
38
- "@synerise/ds-icon": "^0.58.5",
39
- "@synerise/ds-input": "^0.19.5",
40
- "@synerise/ds-menu": "^0.18.2",
41
- "@synerise/ds-scrollbar": "^0.6.10",
42
- "@synerise/ds-search": "^0.8.69",
43
- "@synerise/ds-utils": "^0.24.19",
36
+ "@synerise/ds-button": "^0.18.6",
37
+ "@synerise/ds-divider": "^0.6.3",
38
+ "@synerise/ds-icon": "^0.58.6",
39
+ "@synerise/ds-input": "^0.19.6",
40
+ "@synerise/ds-menu": "^0.18.3",
41
+ "@synerise/ds-scrollbar": "^0.6.11",
42
+ "@synerise/ds-search": "^0.8.70",
43
+ "@synerise/ds-utils": "^0.24.20",
44
44
  "classnames": "2.3.2",
45
45
  "lodash": "^4.17.19"
46
46
  },
@@ -54,5 +54,5 @@
54
54
  "@testing-library/jest-dom": "5.1.1",
55
55
  "@testing-library/react": "^11"
56
56
  },
57
- "gitHead": "1b2696001dd88b4c11413977e38b541b0c78733d"
57
+ "gitHead": "0f860580d5e53dd24a5474aaead7c6d89f8674da"
58
58
  }