@monolith-forensics/monolith-ui 1.1.69 → 1.1.70

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.
@@ -262,9 +262,14 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
262
262
  }, debounceTime);
263
263
  const handleBlur = () => {
264
264
  var _a, _b;
265
- if (((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value) && allowCustomValue) {
265
+ // add custom value if prop is set
266
+ // and input value is not empty
267
+ // and no item is selected
268
+ if (allowCustomValue && !selected && ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value)) {
266
269
  handleAddItem((_b = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _b === void 0 ? void 0 : _b.value);
267
270
  }
271
+ setIsOpen(false);
272
+ setSearchValue("");
268
273
  };
269
274
  const handleClear = (e) => {
270
275
  e.preventDefault();
@@ -305,6 +310,7 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
305
310
  setSearchValue("");
306
311
  update();
307
312
  setIsOpen(false);
313
+ return;
308
314
  }
309
315
  // Enter key
310
316
  if (e.key === "Enter") {
@@ -317,6 +323,7 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
317
323
  // TODO: decide what to do when user presses enter after typing a search value
318
324
  }
319
325
  toggleOpen();
326
+ return;
320
327
  }
321
328
  // Arrow down
322
329
  if (e.key === "ArrowDown") {
@@ -350,7 +357,7 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
350
357
  }
351
358
  // Tab key
352
359
  if (e.key === "Tab") {
353
- if (allowCustomValue && currentInputValue && currentInputValue !== "") {
360
+ if (allowCustomValue && !selected && !!currentInputValue) {
354
361
  handleAddItem(currentInputValue);
355
362
  setSearchValue("");
356
363
  }
@@ -362,7 +369,9 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
362
369
  }
363
370
  setSearchValue("");
364
371
  setIsOpen(false);
372
+ return;
365
373
  }
374
+ setSelected(null); // Reset selected value when input value changes
366
375
  };
367
376
  const handleFocus = () => {
368
377
  if (openOnFocus) {
@@ -392,12 +401,12 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
392
401
  !referenceElement.contains(target) && // Check if the target is not inside the reference (input)
393
402
  !floatingElement.contains(target) // Check if the target is not inside the floating element (content)
394
403
  ) {
395
- setIsOpen(false);
404
+ handleBlur();
396
405
  }
397
406
  };
398
407
  document.addEventListener("click", close);
399
408
  return () => document.removeEventListener("click", close);
400
- }, [refs.floating, refs.reference]);
409
+ }, [refs.floating, refs.reference, handleBlur]);
401
410
  // Handle default value
402
411
  useEffect(() => {
403
412
  if (defaultValue) {
@@ -455,7 +464,7 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
455
464
  useEffect(() => {
456
465
  debouncedHandleChange(inputValue);
457
466
  }, [inputValue, debouncedHandleChange]);
458
- return (_jsxs("div", { className: className, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { ref: refs.setReference, onMouseDown: () => setIsOpen(true), width: width, onKeyDown: handleKeyDown, "data-open": isOpen, children: [_jsx(Input, { ref: inputRef, onChange: handleInputChange, onFocus: handleFocus, autoFocus: focused, placeholder: placeholder, size: size, readOnly: !searchable, "data-button-right": arrow || clearable, onBlur: handleBlur }), clearable && (selected || !!((_h = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _h === void 0 ? void 0 : _h.value)) ? (_jsx(ClearButton, { className: "input-btn", onClick: handleClear, onMouseDown: (e) => {
467
+ return (_jsxs("div", { className: className, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { ref: refs.setReference, onMouseDown: () => setIsOpen(true), width: width, onKeyDown: handleKeyDown, "data-open": isOpen, children: [_jsx(Input, { ref: inputRef, onChange: handleInputChange, onFocus: handleFocus, autoFocus: focused, placeholder: placeholder, size: size, readOnly: !searchable, "data-button-right": arrow || clearable }), clearable && (selected || !!((_h = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _h === void 0 ? void 0 : _h.value)) ? (_jsx(ClearButton, { className: "input-btn", onClick: handleClear, onMouseDown: (e) => {
459
468
  e.preventDefault();
460
469
  e.stopPropagation();
461
470
  } })) : arrow ? (_jsx(ArrowButton, { onClick: (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.1.69",
3
+ "version": "1.1.70",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",