zavadil-react-common 2.0.5 → 2.0.7
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {Form, Spinner} from "react-bootstrap";
|
|
2
2
|
import {StringUtil} from "zavadil-ts-common";
|
|
3
|
+
import {useEffect} from "react";
|
|
3
4
|
|
|
4
5
|
export type GenericSelectOption<T> = {
|
|
5
6
|
id?: T | null;
|
|
@@ -18,10 +19,25 @@ export type GenericSelectProps<T> = {
|
|
|
18
19
|
export type StringSelectProps = GenericSelectProps<string>;
|
|
19
20
|
|
|
20
21
|
export function StringSelect({value, options, disabled, onChange, showEmptyOption, emptyOptionLabel}: StringSelectProps) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
useEffect(
|
|
23
|
+
() => {
|
|
24
|
+
if (StringUtil.isBlank(value)) {
|
|
25
|
+
if (options.length > 0 && showEmptyOption !== true) {
|
|
26
|
+
onChange(options[0].id);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
const option = options.find((o) => o.id === value);
|
|
30
|
+
if (!option) {
|
|
31
|
+
if (showEmptyOption !== true && options.length > 0) {
|
|
32
|
+
onChange(options[0].id);
|
|
33
|
+
} else {
|
|
34
|
+
onChange('');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
[value, options, showEmptyOption, onChange]
|
|
40
|
+
);
|
|
25
41
|
|
|
26
42
|
return (
|
|
27
43
|
<Form.Select
|