@etsoo/materialui 1.0.43 → 1.0.44

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/SelectEx.js CHANGED
@@ -4,6 +4,7 @@ import { MUGlobal } from './MUGlobal';
4
4
  import { ListItemRightIcon } from './ListItemRightIcon';
5
5
  import RefreshIcon from '@mui/icons-material/Refresh';
6
6
  import { Utils } from '@etsoo/shared';
7
+ import { ReactUtils } from '@etsoo/react';
7
8
  /**
8
9
  * Extended select component
9
10
  * @param props Props
@@ -52,7 +53,12 @@ export function SelectEx(props) {
52
53
  localValue = valueSource;
53
54
  }
54
55
  // Value state
55
- const [valueState, setValueState] = React.useState();
56
+ const [valueState, setValueStateBase] = React.useState();
57
+ const valueRef = React.useRef();
58
+ const setValueState = (newValue) => {
59
+ valueRef.current = newValue;
60
+ setValueStateBase(newValue);
61
+ };
56
62
  React.useEffect(() => {
57
63
  if (localValue != null)
58
64
  setValueState(localValue);
@@ -69,22 +75,23 @@ export function SelectEx(props) {
69
75
  const handleChange = (event) => {
70
76
  const value = event.target.value;
71
77
  if (multiple && !Array.isArray(value))
72
- setItemValue([value]);
78
+ return setItemValue([value]);
73
79
  else
74
- setItemValue(value);
80
+ return setItemValue(value);
75
81
  };
76
82
  // Set item
77
83
  const setItemValue = (id) => {
78
- if (id != valueState) {
84
+ var _a;
85
+ if (id != valueRef.current) {
79
86
  setValueState(id);
80
- /*
81
- const input = divRef.current?.querySelector('input');
87
+ const input = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
82
88
  if (input) {
83
89
  // Different value, trigger change event
84
- ReactUtils.triggerChange(input, id as string, false);
90
+ ReactUtils.triggerChange(input, id, false);
85
91
  }
86
- */
92
+ return true;
87
93
  }
94
+ return false;
88
95
  };
89
96
  // Get option id
90
97
  const getId = (option) => {
@@ -147,8 +154,9 @@ export function SelectEx(props) {
147
154
  if (event.defaultPrevented)
148
155
  return;
149
156
  }
150
- doItemChange(localOptions, event.target.value, true);
151
- handleChange(event);
157
+ if (handleChange(event)) {
158
+ doItemChange(localOptions, event.target.value, true);
159
+ }
152
160
  }, renderValue: (selected) => {
153
161
  // The text shows up
154
162
  return localOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.0.43",
3
+ "version": "1.0.44",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/SelectEx.tsx CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  ListType,
24
24
  Utils
25
25
  } from '@etsoo/shared';
26
+ import { ReactUtils } from '@etsoo/react';
26
27
 
27
28
  /**
28
29
  * Extended select component props
@@ -183,7 +184,12 @@ export function SelectEx<
183
184
  }
184
185
 
185
186
  // Value state
186
- const [valueState, setValueState] = React.useState<unknown>();
187
+ const [valueState, setValueStateBase] = React.useState<unknown>();
188
+ const valueRef = React.useRef<unknown>();
189
+ const setValueState = (newValue: unknown) => {
190
+ valueRef.current = newValue;
191
+ setValueStateBase(newValue);
192
+ };
187
193
 
188
194
  React.useEffect(() => {
189
195
  if (localValue != null) setValueState(localValue);
@@ -201,23 +207,23 @@ export function SelectEx<
201
207
  // Change handler
202
208
  const handleChange = (event: SelectChangeEvent<unknown>) => {
203
209
  const value = event.target.value;
204
- if (multiple && !Array.isArray(value)) setItemValue([value]);
205
- else setItemValue(value);
210
+ if (multiple && !Array.isArray(value)) return setItemValue([value]);
211
+ else return setItemValue(value);
206
212
  };
207
213
 
208
214
  // Set item
209
215
  const setItemValue = (id: unknown) => {
210
- if (id != valueState) {
216
+ if (id != valueRef.current) {
211
217
  setValueState(id);
212
218
 
213
- /*
214
219
  const input = divRef.current?.querySelector('input');
215
220
  if (input) {
216
221
  // Different value, trigger change event
217
222
  ReactUtils.triggerChange(input, id as string, false);
218
223
  }
219
- */
224
+ return true;
220
225
  }
226
+ return false;
221
227
  };
222
228
 
223
229
  // Get option id
@@ -314,8 +320,14 @@ export function SelectEx<
314
320
  // event.preventDefault() will block executing
315
321
  if (event.defaultPrevented) return;
316
322
  }
317
- doItemChange(localOptions, event.target.value, true);
318
- handleChange(event);
323
+
324
+ if (handleChange(event)) {
325
+ doItemChange(
326
+ localOptions,
327
+ event.target.value,
328
+ true
329
+ );
330
+ }
319
331
  }}
320
332
  renderValue={(selected) => {
321
333
  // The text shows up