@monolith-forensics/monolith-ui 1.2.114 → 1.2.115
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/dist/SelectBox/SelectBox.js +12 -22
- package/package.json +1 -1
|
@@ -202,7 +202,7 @@ const resolveValue = (value, data) => {
|
|
|
202
202
|
return value;
|
|
203
203
|
};
|
|
204
204
|
const SelectBox = styled(({ className, data = [], placeholder = "Select...", arrow = true, onChange, onSearch, searchFn, onScroll, loading, defaultValue, value, onItemAdded, size = "sm", variant = "outlined", width = "100%", allowCustomValue = false, searchable = false, clearable = false, label, description, required = false, error, openOnFocus = true, renderOption, actionComponent, focused, grouped, OptionTooltip, // Custom tooltip component for search menu items
|
|
205
|
-
DropDownProps = {}, debounceTime =
|
|
205
|
+
DropDownProps = {}, debounceTime = 175, sort = false, disabled = false, }) => {
|
|
206
206
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
207
207
|
const theme = useTheme();
|
|
208
208
|
const isObjectArray = (_a = Object.keys((data === null || data === void 0 ? void 0 : data[0]) || {})) === null || _a === void 0 ? void 0 : _a.includes("label");
|
|
@@ -320,22 +320,20 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
320
320
|
else {
|
|
321
321
|
handleSearch(value);
|
|
322
322
|
}
|
|
323
|
-
if (allowCustomValue && value) {
|
|
324
|
-
const existingItem = resolvedOptions.find((item) => item.value.toLowerCase() === value.toLowerCase());
|
|
323
|
+
if (!!allowCustomValue && !!value) {
|
|
324
|
+
const existingItem = resolvedOptions.find((item) => { var _a, _b, _c; return ((_b = (_a = item === null || item === void 0 ? void 0 : item.value) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a)) === ((_c = value === null || value === void 0 ? void 0 : value.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(value)); });
|
|
325
325
|
if (existingItem)
|
|
326
326
|
handleChangeSelection(existingItem);
|
|
327
|
-
else
|
|
328
|
-
handleChangeSelection(
|
|
327
|
+
else {
|
|
328
|
+
handleChangeSelection({
|
|
329
|
+
value: value,
|
|
330
|
+
label: value,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
329
333
|
}
|
|
330
334
|
update();
|
|
331
335
|
}, debounceTime);
|
|
332
336
|
const handleBlur = () => {
|
|
333
|
-
// add custom value if prop is set
|
|
334
|
-
// and input value is not empty
|
|
335
|
-
// and no item is selected
|
|
336
|
-
if (allowCustomValue && !_value && !!inputValue) {
|
|
337
|
-
handleAddItem(inputValue);
|
|
338
|
-
}
|
|
339
337
|
setIsOpen(false);
|
|
340
338
|
setSearchValue("");
|
|
341
339
|
};
|
|
@@ -363,10 +361,8 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
363
361
|
onChange === null || onChange === void 0 ? void 0 : onChange(option === null || option === void 0 ? void 0 : option.value, option);
|
|
364
362
|
}, [onChange]);
|
|
365
363
|
const handleAddItem = useCallback((newItem) => {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
handleChangeSelection(newValue);
|
|
369
|
-
onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newValue);
|
|
364
|
+
setCustomItems((prev) => [...prev, newItem]);
|
|
365
|
+
onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newItem);
|
|
370
366
|
}, [onItemAdded, isObjectArray, handleChangeSelection]);
|
|
371
367
|
const handleKeyDown = (e) => {
|
|
372
368
|
var _a;
|
|
@@ -428,14 +424,8 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
428
424
|
}
|
|
429
425
|
// Tab key
|
|
430
426
|
if (e.key === "Tab") {
|
|
431
|
-
if (
|
|
432
|
-
handleAddItem(currentInputValue);
|
|
433
|
-
setSearchValue("");
|
|
434
|
-
}
|
|
435
|
-
else if (!_value) {
|
|
436
|
-
// clear input
|
|
427
|
+
if (!_value)
|
|
437
428
|
setInputValue("");
|
|
438
|
-
}
|
|
439
429
|
setSearchValue("");
|
|
440
430
|
setIsOpen(false);
|
|
441
431
|
return;
|