@etsoo/react 1.4.47 → 1.4.48
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/lib/mu/ComboBox.js +6 -4
- package/lib/mu/SelectEx.js +4 -2
- package/package.json +1 -1
- package/src/mu/ComboBox.tsx +5 -4
- package/src/mu/SelectEx.tsx +3 -2
package/lib/mu/ComboBox.js
CHANGED
|
@@ -10,16 +10,18 @@ import { SearchField } from './SearchField';
|
|
|
10
10
|
*/
|
|
11
11
|
export function ComboBox(props) {
|
|
12
12
|
// Destruct
|
|
13
|
-
const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options
|
|
13
|
+
const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, readOnly = true, onChange, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
|
|
14
14
|
// Value input ref
|
|
15
15
|
const inputRef = React.createRef();
|
|
16
16
|
// Options state
|
|
17
|
-
const [localOptions, setOptions] = React.useState(options);
|
|
17
|
+
const [localOptions, setOptions] = React.useState(options !== null && options !== void 0 ? options : []);
|
|
18
18
|
const isMounted = React.useRef(true);
|
|
19
19
|
// When options change
|
|
20
|
+
// [options] will cause infinite loop
|
|
20
21
|
React.useEffect(() => {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (options != null)
|
|
23
|
+
setOptions(options);
|
|
24
|
+
}, [JSON.stringify(options)]);
|
|
23
25
|
// Local default value
|
|
24
26
|
let localValue = idValue != null
|
|
25
27
|
? localOptions.find((o) => Reflect.get(o, idField) === idValue)
|
package/lib/mu/SelectEx.js
CHANGED
|
@@ -16,9 +16,11 @@ export function SelectEx(props) {
|
|
|
16
16
|
const [localOptions, setOptions] = React.useState(options);
|
|
17
17
|
const isMounted = React.useRef(true);
|
|
18
18
|
// When options change
|
|
19
|
+
// [options] will cause infinite loop
|
|
19
20
|
React.useEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (options != null)
|
|
22
|
+
setOptions(options);
|
|
23
|
+
}, [JSON.stringify(options)]);
|
|
22
24
|
// Local value
|
|
23
25
|
const valueSource = (_a = defaultValue !== null && defaultValue !== void 0 ? defaultValue : value) !== null && _a !== void 0 ? _a : '';
|
|
24
26
|
let localValue;
|
package/package.json
CHANGED
package/src/mu/ComboBox.tsx
CHANGED
|
@@ -56,7 +56,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
|
|
|
56
56
|
onLoadData,
|
|
57
57
|
name,
|
|
58
58
|
inputAutoComplete = 'off',
|
|
59
|
-
options
|
|
59
|
+
options,
|
|
60
60
|
readOnly = true,
|
|
61
61
|
onChange,
|
|
62
62
|
value,
|
|
@@ -69,13 +69,14 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
|
|
|
69
69
|
const inputRef = React.createRef<HTMLInputElement>();
|
|
70
70
|
|
|
71
71
|
// Options state
|
|
72
|
-
const [localOptions, setOptions] = React.useState(options);
|
|
72
|
+
const [localOptions, setOptions] = React.useState(options ?? []);
|
|
73
73
|
const isMounted = React.useRef(true);
|
|
74
74
|
|
|
75
75
|
// When options change
|
|
76
|
+
// [options] will cause infinite loop
|
|
76
77
|
React.useEffect(() => {
|
|
77
|
-
setOptions(options);
|
|
78
|
-
}, [options]);
|
|
78
|
+
if (options != null) setOptions(options);
|
|
79
|
+
}, [JSON.stringify(options)]);
|
|
79
80
|
|
|
80
81
|
// Local default value
|
|
81
82
|
let localValue =
|
package/src/mu/SelectEx.tsx
CHANGED
|
@@ -91,9 +91,10 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
|
|
|
91
91
|
const isMounted = React.useRef(true);
|
|
92
92
|
|
|
93
93
|
// When options change
|
|
94
|
+
// [options] will cause infinite loop
|
|
94
95
|
React.useEffect(() => {
|
|
95
|
-
setOptions(options);
|
|
96
|
-
}, [options]);
|
|
96
|
+
if (options != null) setOptions(options);
|
|
97
|
+
}, [JSON.stringify(options)]);
|
|
97
98
|
|
|
98
99
|
// Local value
|
|
99
100
|
const valueSource = defaultValue ?? value ?? '';
|