@monolith-forensics/monolith-ui 1.1.69 → 1.1.71
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.
|
@@ -128,6 +128,11 @@ const StyledInputContainer = styled.div `
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// focus within
|
|
132
|
+
&:focus-within {
|
|
133
|
+
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
134
|
+
}
|
|
135
|
+
|
|
131
136
|
&:focus {
|
|
132
137
|
border: 1px solid ${(props) => props.theme.palette.primary.main};
|
|
133
138
|
}
|
|
@@ -262,9 +262,14 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
|
|
|
262
262
|
}, debounceTime);
|
|
263
263
|
const handleBlur = () => {
|
|
264
264
|
var _a, _b;
|
|
265
|
-
|
|
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,18 +310,12 @@ 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") {
|
|
311
|
-
if (currentInputValue && currentInputValue !== "" && allowCustomValue) {
|
|
312
|
-
handleAddItem(currentInputValue);
|
|
313
|
-
setSearchValue("");
|
|
314
|
-
update();
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
// TODO: decide what to do when user presses enter after typing a search value
|
|
318
|
-
}
|
|
319
317
|
toggleOpen();
|
|
318
|
+
return;
|
|
320
319
|
}
|
|
321
320
|
// Arrow down
|
|
322
321
|
if (e.key === "ArrowDown") {
|
|
@@ -332,6 +331,7 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
|
|
|
332
331
|
onChange === null || onChange === void 0 ? void 0 : onChange((newItem === null || newItem === void 0 ? void 0 : newItem.value) || newItem, newItem);
|
|
333
332
|
return newItem;
|
|
334
333
|
});
|
|
334
|
+
return;
|
|
335
335
|
}
|
|
336
336
|
// Arrow up
|
|
337
337
|
if (e.key === "ArrowUp") {
|
|
@@ -347,10 +347,11 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
|
|
|
347
347
|
onChange === null || onChange === void 0 ? void 0 : onChange((newItem === null || newItem === void 0 ? void 0 : newItem.value) || newItem, newItem);
|
|
348
348
|
return newItem;
|
|
349
349
|
});
|
|
350
|
+
return;
|
|
350
351
|
}
|
|
351
352
|
// Tab key
|
|
352
353
|
if (e.key === "Tab") {
|
|
353
|
-
if (allowCustomValue &&
|
|
354
|
+
if (allowCustomValue && !selected && !!currentInputValue) {
|
|
354
355
|
handleAddItem(currentInputValue);
|
|
355
356
|
setSearchValue("");
|
|
356
357
|
}
|
|
@@ -362,7 +363,9 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
|
|
|
362
363
|
}
|
|
363
364
|
setSearchValue("");
|
|
364
365
|
setIsOpen(false);
|
|
366
|
+
return;
|
|
365
367
|
}
|
|
368
|
+
setSelected(null); // Reset selected value when input value changes
|
|
366
369
|
};
|
|
367
370
|
const handleFocus = () => {
|
|
368
371
|
if (openOnFocus) {
|
|
@@ -392,12 +395,12 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
|
|
|
392
395
|
!referenceElement.contains(target) && // Check if the target is not inside the reference (input)
|
|
393
396
|
!floatingElement.contains(target) // Check if the target is not inside the floating element (content)
|
|
394
397
|
) {
|
|
395
|
-
|
|
398
|
+
handleBlur();
|
|
396
399
|
}
|
|
397
400
|
};
|
|
398
401
|
document.addEventListener("click", close);
|
|
399
402
|
return () => document.removeEventListener("click", close);
|
|
400
|
-
}, [refs.floating, refs.reference]);
|
|
403
|
+
}, [refs.floating, refs.reference, handleBlur]);
|
|
401
404
|
// Handle default value
|
|
402
405
|
useEffect(() => {
|
|
403
406
|
if (defaultValue) {
|
|
@@ -455,7 +458,7 @@ DropDownProps = {}, debounceTime = 300, sort = false, }) => {
|
|
|
455
458
|
useEffect(() => {
|
|
456
459
|
debouncedHandleChange(inputValue);
|
|
457
460
|
}, [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
|
|
461
|
+
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
462
|
e.preventDefault();
|
|
460
463
|
e.stopPropagation();
|
|
461
464
|
} })) : arrow ? (_jsx(ArrowButton, { onClick: (e) => {
|