@monolith-forensics/monolith-ui 1.2.113 → 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.
@@ -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 = 150, sort = false, disabled = false, }) => {
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");
@@ -310,31 +310,30 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
310
310
  const value = e.target.value;
311
311
  setInputValue(value || "");
312
312
  debouncedHandleChange(value);
313
- setIsOpen(true);
313
+ if (!isOpen)
314
+ setIsOpen(true);
314
315
  };
315
316
  const debouncedHandleChange = useDebouncedCallback((value) => {
316
317
  if (searchFn) {
317
318
  searchFn(value);
318
319
  }
319
320
  else {
320
- setSearchValue(value);
321
+ handleSearch(value);
321
322
  }
322
- if (allowCustomValue && value) {
323
- 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)); });
324
325
  if (existingItem)
325
326
  handleChangeSelection(existingItem);
326
- else
327
- handleChangeSelection(null);
327
+ else {
328
+ handleChangeSelection({
329
+ value: value,
330
+ label: value,
331
+ });
332
+ }
328
333
  }
329
334
  update();
330
335
  }, debounceTime);
331
336
  const handleBlur = () => {
332
- // add custom value if prop is set
333
- // and input value is not empty
334
- // and no item is selected
335
- if (allowCustomValue && !_value && !!inputValue) {
336
- handleAddItem(inputValue);
337
- }
338
337
  setIsOpen(false);
339
338
  setSearchValue("");
340
339
  };
@@ -358,13 +357,12 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
358
357
  };
359
358
  const handleChangeSelection = useCallback((option) => {
360
359
  !isControlled.current && setValueState(option);
360
+ setInputValue((option === null || option === void 0 ? void 0 : option.label) || "");
361
361
  onChange === null || onChange === void 0 ? void 0 : onChange(option === null || option === void 0 ? void 0 : option.value, option);
362
362
  }, [onChange]);
363
363
  const handleAddItem = useCallback((newItem) => {
364
- const newValue = { label: newItem, value: newItem };
365
- setCustomItems((prev) => [...prev, newValue]);
366
- handleChangeSelection(newValue);
367
- onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newValue);
364
+ setCustomItems((prev) => [...prev, newItem]);
365
+ onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newItem);
368
366
  }, [onItemAdded, isObjectArray, handleChangeSelection]);
369
367
  const handleKeyDown = (e) => {
370
368
  var _a;
@@ -398,6 +396,7 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
398
396
  newItem = filteredItems[index + 1];
399
397
  }
400
398
  !isControlled.current && setValueState(newItem);
399
+ setInputValue(newItem.label || "");
401
400
  onChange === null || onChange === void 0 ? void 0 : onChange(newItem.value, newItem);
402
401
  return;
403
402
  }
@@ -419,19 +418,14 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
419
418
  newItem = filteredItems[index - 1];
420
419
  }
421
420
  !isControlled.current && setValueState(newItem);
421
+ setInputValue(newItem.label || "");
422
422
  onChange === null || onChange === void 0 ? void 0 : onChange(newItem.value, newItem);
423
423
  return;
424
424
  }
425
425
  // Tab key
426
426
  if (e.key === "Tab") {
427
- if (allowCustomValue && !_value && !!currentInputValue) {
428
- handleAddItem(currentInputValue);
429
- setSearchValue("");
430
- }
431
- else if (!_value) {
432
- // clear input
427
+ if (!_value)
433
428
  setInputValue("");
434
- }
435
429
  setSearchValue("");
436
430
  setIsOpen(false);
437
431
  return;
@@ -442,6 +436,13 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
442
436
  setIsOpen(true);
443
437
  }
444
438
  };
439
+ const handleSearch = (value) => {
440
+ if (searchable) {
441
+ setSearchValue(value);
442
+ update();
443
+ onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchValue);
444
+ }
445
+ };
445
446
  const referenceEl = (_b = refs === null || refs === void 0 ? void 0 : refs.reference) === null || _b === void 0 ? void 0 : _b.current;
446
447
  const contentWidth = ((_e = (_d = (_c = referenceEl === null || referenceEl === void 0 ? void 0 : referenceEl.getClientRects) === null || _c === void 0 ? void 0 : _c.call(referenceEl)) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.width) || "100%";
447
448
  const scrollEl = scrollContainerRef === null || scrollContainerRef === void 0 ? void 0 : scrollContainerRef.current;
@@ -471,10 +472,6 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
471
472
  document.addEventListener("click", close);
472
473
  return () => document.removeEventListener("click", close);
473
474
  }, [refs.floating, refs.reference, handleBlur]);
474
- // handle input value change
475
- useEffect(() => {
476
- setInputValue((_value === null || _value === void 0 ? void 0 : _value.label) || "");
477
- }, [_value]);
478
475
  // handle scroll item into view
479
476
  useEffect(() => {
480
477
  var _a, _b;
@@ -483,13 +480,6 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
483
480
  item.scrollIntoView({ block: "nearest" });
484
481
  }
485
482
  }, [_value]);
486
- // make calls to onSearch callback
487
- useEffect(() => {
488
- if (searchable) {
489
- update();
490
- onSearch === null || onSearch === void 0 ? void 0 : onSearch(searchValue);
491
- }
492
- }, [searchValue]);
493
483
  useEffect(() => {
494
484
  if (bottomHeight < 250) {
495
485
  setPlacement("top-start");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.2.113",
3
+ "version": "1.2.115",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",