ab-ui-library 1.39.0-alpha.2 → 1.39.0-alpha.4
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.
|
@@ -2,7 +2,7 @@ import { _ as _extends } from '../../extends-d0c248d6.js';
|
|
|
2
2
|
import { _ as _typeof } from '../../typeof-f5583e42.js';
|
|
3
3
|
import { _ as _toConsumableArray } from '../../toConsumableArray-96c5590c.js';
|
|
4
4
|
import { _ as _slicedToArray } from '../../slicedToArray-31c0261f.js';
|
|
5
|
-
import React, { useState, useRef, useEffect } from 'react';
|
|
5
|
+
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
|
6
6
|
import { Chips } from '../Chips/Chips.js';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
8
|
import { ErrorMessage } from '../../helperComponents/ErrorMessage/ErrorMessage.js';
|
|
@@ -62,6 +62,8 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
62
62
|
typeAndEnterPlaceholderText = _ref$typeAndEnterPlac === void 0 ? 'Type and press Enter...' : _ref$typeAndEnterPlac,
|
|
63
63
|
_ref$noOptionsPlaceho = _ref.noOptionsPlaceholderText,
|
|
64
64
|
noOptionsPlaceholderText = _ref$noOptionsPlaceho === void 0 ? 'No more options available' : _ref$noOptionsPlaceho,
|
|
65
|
+
_ref$fieldName = _ref.fieldName,
|
|
66
|
+
fieldName = _ref$fieldName === void 0 ? 'skills' : _ref$fieldName,
|
|
65
67
|
formProps = _ref.formProps;
|
|
66
68
|
var _useState = useState(''),
|
|
67
69
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -88,6 +90,7 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
88
90
|
localChips = _useState10[0],
|
|
89
91
|
setLocalChips = _useState10[1];
|
|
90
92
|
var inputRef = useRef(null);
|
|
93
|
+
var containerRef = useRef(null);
|
|
91
94
|
var _useFormProps = useFormProps(),
|
|
92
95
|
setValue = _useFormProps.setValue;
|
|
93
96
|
var chipTexts = localChips.map(function (chip) {
|
|
@@ -101,9 +104,38 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
101
104
|
}, [chips]);
|
|
102
105
|
useEffect(function () {
|
|
103
106
|
if (isUserInteraction.current && formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
104
|
-
formProps.setFieldValue(
|
|
107
|
+
formProps.setFieldValue(fieldName, localChips);
|
|
105
108
|
}
|
|
106
|
-
}, [localChips]);
|
|
109
|
+
}, [localChips, fieldName]);
|
|
110
|
+
|
|
111
|
+
// Helper function to filter options
|
|
112
|
+
var filterOptions = useCallback(function (value) {
|
|
113
|
+
if (availableOptions.length > 0) {
|
|
114
|
+
var currentChipTexts = localChips.map(function (chip) {
|
|
115
|
+
return typeof chip === 'string' ? chip : chip.text;
|
|
116
|
+
});
|
|
117
|
+
var filtered = availableOptions.filter(function (option) {
|
|
118
|
+
return option.toLowerCase().includes(value.toLowerCase()) && !currentChipTexts.includes(option);
|
|
119
|
+
});
|
|
120
|
+
setFilteredOptions(filtered);
|
|
121
|
+
}
|
|
122
|
+
}, [availableOptions, localChips]);
|
|
123
|
+
|
|
124
|
+
// Handle click outside to close dropdown
|
|
125
|
+
useEffect(function () {
|
|
126
|
+
var handleClickOutside = function handleClickOutside(event) {
|
|
127
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
128
|
+
setShowDropdown(false);
|
|
129
|
+
setSelectedOption('');
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if (showDropdown) {
|
|
133
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
134
|
+
}
|
|
135
|
+
return function () {
|
|
136
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
137
|
+
};
|
|
138
|
+
}, [showDropdown]);
|
|
107
139
|
var handleKeyDown = function handleKeyDown(e) {
|
|
108
140
|
if (disabled) return;
|
|
109
141
|
if (e.key === 'Enter') {
|
|
@@ -150,12 +182,23 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
150
182
|
};
|
|
151
183
|
var handleInputChange = function handleInputChange(e) {
|
|
152
184
|
if (disabled) return;
|
|
153
|
-
|
|
185
|
+
var value = e.target.value;
|
|
186
|
+
setInputValue(value);
|
|
154
187
|
setSelectedOption('');
|
|
188
|
+
|
|
189
|
+
// Filter available options based on input
|
|
190
|
+
filterOptions(value);
|
|
191
|
+
setShowDropdown(availableOptions.length > 0 && value.trim().length > 0);
|
|
155
192
|
};
|
|
156
193
|
var handleInputFocus = function handleInputFocus() {
|
|
157
|
-
if (availableOptions.length > 0
|
|
158
|
-
|
|
194
|
+
if (availableOptions.length > 0) {
|
|
195
|
+
if (inputValue.trim()) {
|
|
196
|
+
setShowDropdown(true);
|
|
197
|
+
} else {
|
|
198
|
+
// Show all available options when focusing without input
|
|
199
|
+
filterOptions('');
|
|
200
|
+
setShowDropdown(true);
|
|
201
|
+
}
|
|
159
202
|
}
|
|
160
203
|
};
|
|
161
204
|
var handleRemoveChip = function handleRemoveChip(chipToRemove) {
|
|
@@ -167,13 +210,20 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
167
210
|
});
|
|
168
211
|
setLocalChips(newChips);
|
|
169
212
|
onRemoveChip === null || onRemoveChip === void 0 || onRemoveChip(chipToRemove);
|
|
213
|
+
|
|
214
|
+
// Update form values consistently
|
|
215
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
216
|
+
formProps.setFieldValue(fieldName, newChips);
|
|
217
|
+
}
|
|
170
218
|
if (setValue) {
|
|
171
|
-
|
|
172
|
-
return typeof chip === 'string';
|
|
173
|
-
});
|
|
174
|
-
setValue('skills', validChips);
|
|
219
|
+
setValue(fieldName, newChips);
|
|
175
220
|
}
|
|
176
221
|
setChipError('');
|
|
222
|
+
|
|
223
|
+
// Refresh filtered options when chip is removed
|
|
224
|
+
if (showDropdown) {
|
|
225
|
+
filterOptions(inputValue);
|
|
226
|
+
}
|
|
177
227
|
};
|
|
178
228
|
var handleSelectOption = function handleSelectOption(option) {
|
|
179
229
|
isUserInteraction.current = true;
|
|
@@ -184,18 +234,20 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
184
234
|
} catch (e) {
|
|
185
235
|
var message = chipValidationErrorMessage || e.message || 'Invalid value';
|
|
186
236
|
if (allowInvalidChips) {
|
|
187
|
-
var
|
|
237
|
+
var _item = {
|
|
188
238
|
text: option,
|
|
189
239
|
hasError: true,
|
|
190
240
|
errorMessage: message
|
|
191
241
|
};
|
|
192
|
-
var _newChips = [].concat(_toConsumableArray(localChips), [
|
|
242
|
+
var _newChips = [].concat(_toConsumableArray(localChips), [_item]);
|
|
193
243
|
setLocalChips(_newChips);
|
|
244
|
+
|
|
245
|
+
// Update form values consistently
|
|
246
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
247
|
+
formProps.setFieldValue(fieldName, _newChips);
|
|
248
|
+
}
|
|
194
249
|
if (setValue) {
|
|
195
|
-
|
|
196
|
-
return typeof chip === 'string';
|
|
197
|
-
});
|
|
198
|
-
setValue('skills', validChips);
|
|
250
|
+
setValue(fieldName, _newChips);
|
|
199
251
|
}
|
|
200
252
|
setInputValue('');
|
|
201
253
|
setShowDropdown(false);
|
|
@@ -208,13 +260,22 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
208
260
|
}
|
|
209
261
|
}
|
|
210
262
|
onAddChip === null || onAddChip === void 0 || onAddChip(option);
|
|
211
|
-
|
|
263
|
+
|
|
264
|
+
// Create consistent chip item structure
|
|
265
|
+
var item = {
|
|
266
|
+
text: option,
|
|
267
|
+
hasError: false,
|
|
268
|
+
errorMessage: ''
|
|
269
|
+
};
|
|
270
|
+
var newChips = [].concat(_toConsumableArray(localChips), [item]);
|
|
212
271
|
setLocalChips(newChips);
|
|
272
|
+
|
|
273
|
+
// Update form values consistently
|
|
274
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
275
|
+
formProps.setFieldValue(fieldName, newChips);
|
|
276
|
+
}
|
|
213
277
|
if (setValue) {
|
|
214
|
-
|
|
215
|
-
return typeof chip === 'string';
|
|
216
|
-
});
|
|
217
|
-
setValue('skills', _validChips);
|
|
278
|
+
setValue(fieldName, newChips);
|
|
218
279
|
}
|
|
219
280
|
setInputValue('');
|
|
220
281
|
setShowDropdown(false);
|
|
@@ -238,33 +299,29 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
238
299
|
};
|
|
239
300
|
var newChips = [].concat(_toConsumableArray(localChips), [item]);
|
|
240
301
|
setLocalChips(newChips);
|
|
302
|
+
|
|
303
|
+
// Update form values consistently
|
|
241
304
|
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
242
|
-
formProps.setFieldValue(
|
|
305
|
+
formProps.setFieldValue(fieldName, newChips);
|
|
243
306
|
}
|
|
244
307
|
if (setValue) {
|
|
245
|
-
|
|
246
|
-
return !chip.hasError;
|
|
247
|
-
});
|
|
248
|
-
setValue('skills', validChips);
|
|
308
|
+
setValue(fieldName, newChips);
|
|
249
309
|
}
|
|
250
310
|
} catch (e) {
|
|
251
311
|
var message = chipValidationErrorMessage || e.message || 'Invalid value';
|
|
252
312
|
if (allowInvalidChips) {
|
|
253
|
-
var
|
|
313
|
+
var _item2 = {
|
|
254
314
|
text: value,
|
|
255
315
|
hasError: true,
|
|
256
316
|
errorMessage: message
|
|
257
317
|
};
|
|
258
|
-
var _newChips2 = [].concat(_toConsumableArray(localChips), [
|
|
318
|
+
var _newChips2 = [].concat(_toConsumableArray(localChips), [_item2]);
|
|
259
319
|
setLocalChips(_newChips2);
|
|
260
320
|
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
261
|
-
formProps === null || formProps === void 0 || formProps.setFieldValue(
|
|
321
|
+
formProps === null || formProps === void 0 || formProps.setFieldValue(fieldName, _newChips2);
|
|
262
322
|
}
|
|
263
323
|
if (setValue) {
|
|
264
|
-
|
|
265
|
-
return !chip.hasError;
|
|
266
|
-
});
|
|
267
|
-
setValue('skills', _validChips2);
|
|
324
|
+
setValue(fieldName, _newChips2);
|
|
268
325
|
}
|
|
269
326
|
} else {
|
|
270
327
|
setChipError(message);
|
|
@@ -274,8 +331,13 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
274
331
|
} else {
|
|
275
332
|
var _newChips3 = [].concat(_toConsumableArray(localChips), [value]);
|
|
276
333
|
setLocalChips(_newChips3);
|
|
334
|
+
|
|
335
|
+
// Update form values consistently
|
|
336
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
337
|
+
formProps.setFieldValue(fieldName, _newChips3);
|
|
338
|
+
}
|
|
277
339
|
if (setValue) {
|
|
278
|
-
setValue(
|
|
340
|
+
setValue(fieldName, _newChips3);
|
|
279
341
|
}
|
|
280
342
|
}
|
|
281
343
|
setInputValue('');
|
|
@@ -301,7 +363,8 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
301
363
|
return noOptionsPlaceholderText;
|
|
302
364
|
};
|
|
303
365
|
return /*#__PURE__*/React.createElement("div", {
|
|
304
|
-
className: classNames('multi-textarea-chips', className)
|
|
366
|
+
className: classNames('multi-textarea-chips', className),
|
|
367
|
+
ref: containerRef
|
|
305
368
|
}, label && /*#__PURE__*/React.createElement("div", {
|
|
306
369
|
className: "multi-textarea-chips__label"
|
|
307
370
|
}, label), /*#__PURE__*/React.createElement("div", {
|
|
@@ -27,6 +27,7 @@ export interface TMultiTextareaWithChipsProps extends IFormCompProps {
|
|
|
27
27
|
typeAndEnterPlaceholderText?: string;
|
|
28
28
|
noOptionsPlaceholderText?: string;
|
|
29
29
|
autoFormIntegration?: boolean;
|
|
30
|
+
fieldName?: string;
|
|
30
31
|
formProps?: {
|
|
31
32
|
setFieldValue?: (fieldName: string, value: TFormValue, shouldValidate?: {
|
|
32
33
|
shouldValidate: boolean;
|