ab-ui-library 1.39.0-alpha.3 → 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';
|
|
@@ -90,6 +90,7 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
90
90
|
localChips = _useState10[0],
|
|
91
91
|
setLocalChips = _useState10[1];
|
|
92
92
|
var inputRef = useRef(null);
|
|
93
|
+
var containerRef = useRef(null);
|
|
93
94
|
var _useFormProps = useFormProps(),
|
|
94
95
|
setValue = _useFormProps.setValue;
|
|
95
96
|
var chipTexts = localChips.map(function (chip) {
|
|
@@ -106,6 +107,35 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
106
107
|
formProps.setFieldValue(fieldName, localChips);
|
|
107
108
|
}
|
|
108
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]);
|
|
109
139
|
var handleKeyDown = function handleKeyDown(e) {
|
|
110
140
|
if (disabled) return;
|
|
111
141
|
if (e.key === 'Enter') {
|
|
@@ -152,12 +182,23 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
152
182
|
};
|
|
153
183
|
var handleInputChange = function handleInputChange(e) {
|
|
154
184
|
if (disabled) return;
|
|
155
|
-
|
|
185
|
+
var value = e.target.value;
|
|
186
|
+
setInputValue(value);
|
|
156
187
|
setSelectedOption('');
|
|
188
|
+
|
|
189
|
+
// Filter available options based on input
|
|
190
|
+
filterOptions(value);
|
|
191
|
+
setShowDropdown(availableOptions.length > 0 && value.trim().length > 0);
|
|
157
192
|
};
|
|
158
193
|
var handleInputFocus = function handleInputFocus() {
|
|
159
|
-
if (availableOptions.length > 0
|
|
160
|
-
|
|
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
|
+
}
|
|
161
202
|
}
|
|
162
203
|
};
|
|
163
204
|
var handleRemoveChip = function handleRemoveChip(chipToRemove) {
|
|
@@ -169,13 +210,20 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
169
210
|
});
|
|
170
211
|
setLocalChips(newChips);
|
|
171
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
|
+
}
|
|
172
218
|
if (setValue) {
|
|
173
|
-
|
|
174
|
-
return typeof chip === 'string';
|
|
175
|
-
});
|
|
176
|
-
setValue(fieldName, validChips);
|
|
219
|
+
setValue(fieldName, newChips);
|
|
177
220
|
}
|
|
178
221
|
setChipError('');
|
|
222
|
+
|
|
223
|
+
// Refresh filtered options when chip is removed
|
|
224
|
+
if (showDropdown) {
|
|
225
|
+
filterOptions(inputValue);
|
|
226
|
+
}
|
|
179
227
|
};
|
|
180
228
|
var handleSelectOption = function handleSelectOption(option) {
|
|
181
229
|
isUserInteraction.current = true;
|
|
@@ -186,18 +234,20 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
186
234
|
} catch (e) {
|
|
187
235
|
var message = chipValidationErrorMessage || e.message || 'Invalid value';
|
|
188
236
|
if (allowInvalidChips) {
|
|
189
|
-
var
|
|
237
|
+
var _item = {
|
|
190
238
|
text: option,
|
|
191
239
|
hasError: true,
|
|
192
240
|
errorMessage: message
|
|
193
241
|
};
|
|
194
|
-
var _newChips = [].concat(_toConsumableArray(localChips), [
|
|
242
|
+
var _newChips = [].concat(_toConsumableArray(localChips), [_item]);
|
|
195
243
|
setLocalChips(_newChips);
|
|
244
|
+
|
|
245
|
+
// Update form values consistently
|
|
246
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
247
|
+
formProps.setFieldValue(fieldName, _newChips);
|
|
248
|
+
}
|
|
196
249
|
if (setValue) {
|
|
197
|
-
|
|
198
|
-
return typeof chip === 'string';
|
|
199
|
-
});
|
|
200
|
-
setValue(fieldName, validChips);
|
|
250
|
+
setValue(fieldName, _newChips);
|
|
201
251
|
}
|
|
202
252
|
setInputValue('');
|
|
203
253
|
setShowDropdown(false);
|
|
@@ -210,13 +260,22 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
210
260
|
}
|
|
211
261
|
}
|
|
212
262
|
onAddChip === null || onAddChip === void 0 || onAddChip(option);
|
|
213
|
-
|
|
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]);
|
|
214
271
|
setLocalChips(newChips);
|
|
272
|
+
|
|
273
|
+
// Update form values consistently
|
|
274
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
275
|
+
formProps.setFieldValue(fieldName, newChips);
|
|
276
|
+
}
|
|
215
277
|
if (setValue) {
|
|
216
|
-
|
|
217
|
-
return typeof chip === 'string';
|
|
218
|
-
});
|
|
219
|
-
setValue(fieldName, _validChips);
|
|
278
|
+
setValue(fieldName, newChips);
|
|
220
279
|
}
|
|
221
280
|
setInputValue('');
|
|
222
281
|
setShowDropdown(false);
|
|
@@ -240,33 +299,29 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
240
299
|
};
|
|
241
300
|
var newChips = [].concat(_toConsumableArray(localChips), [item]);
|
|
242
301
|
setLocalChips(newChips);
|
|
302
|
+
|
|
303
|
+
// Update form values consistently
|
|
243
304
|
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
244
305
|
formProps.setFieldValue(fieldName, newChips);
|
|
245
306
|
}
|
|
246
307
|
if (setValue) {
|
|
247
|
-
|
|
248
|
-
return !chip.hasError;
|
|
249
|
-
});
|
|
250
|
-
setValue(fieldName, validChips);
|
|
308
|
+
setValue(fieldName, newChips);
|
|
251
309
|
}
|
|
252
310
|
} catch (e) {
|
|
253
311
|
var message = chipValidationErrorMessage || e.message || 'Invalid value';
|
|
254
312
|
if (allowInvalidChips) {
|
|
255
|
-
var
|
|
313
|
+
var _item2 = {
|
|
256
314
|
text: value,
|
|
257
315
|
hasError: true,
|
|
258
316
|
errorMessage: message
|
|
259
317
|
};
|
|
260
|
-
var _newChips2 = [].concat(_toConsumableArray(localChips), [
|
|
318
|
+
var _newChips2 = [].concat(_toConsumableArray(localChips), [_item2]);
|
|
261
319
|
setLocalChips(_newChips2);
|
|
262
320
|
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
263
321
|
formProps === null || formProps === void 0 || formProps.setFieldValue(fieldName, _newChips2);
|
|
264
322
|
}
|
|
265
323
|
if (setValue) {
|
|
266
|
-
|
|
267
|
-
return !chip.hasError;
|
|
268
|
-
});
|
|
269
|
-
setValue(fieldName, _validChips2);
|
|
324
|
+
setValue(fieldName, _newChips2);
|
|
270
325
|
}
|
|
271
326
|
} else {
|
|
272
327
|
setChipError(message);
|
|
@@ -276,6 +331,11 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
276
331
|
} else {
|
|
277
332
|
var _newChips3 = [].concat(_toConsumableArray(localChips), [value]);
|
|
278
333
|
setLocalChips(_newChips3);
|
|
334
|
+
|
|
335
|
+
// Update form values consistently
|
|
336
|
+
if (formProps !== null && formProps !== void 0 && formProps.setFieldValue) {
|
|
337
|
+
formProps.setFieldValue(fieldName, _newChips3);
|
|
338
|
+
}
|
|
279
339
|
if (setValue) {
|
|
280
340
|
setValue(fieldName, _newChips3);
|
|
281
341
|
}
|
|
@@ -303,7 +363,8 @@ var MultiTextareaWithChips = function MultiTextareaWithChips(_ref) {
|
|
|
303
363
|
return noOptionsPlaceholderText;
|
|
304
364
|
};
|
|
305
365
|
return /*#__PURE__*/React.createElement("div", {
|
|
306
|
-
className: classNames('multi-textarea-chips', className)
|
|
366
|
+
className: classNames('multi-textarea-chips', className),
|
|
367
|
+
ref: containerRef
|
|
307
368
|
}, label && /*#__PURE__*/React.createElement("div", {
|
|
308
369
|
className: "multi-textarea-chips__label"
|
|
309
370
|
}, label), /*#__PURE__*/React.createElement("div", {
|