@etsoo/react 1.4.77 → 1.4.78

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.
@@ -68,6 +68,16 @@ export function SelectEx(props) {
68
68
  }
69
69
  }
70
70
  };
71
+ // Get option id
72
+ const getId = (option) => {
73
+ return Reflect.get(option, idField);
74
+ };
75
+ // Get option label
76
+ const getLabel = (option) => {
77
+ return typeof labelField === 'function'
78
+ ? labelField(option)
79
+ : Reflect.get(option, labelField);
80
+ };
71
81
  // Refs
72
82
  const divRef = React.useRef();
73
83
  // When layout ready
@@ -107,18 +117,19 @@ export function SelectEx(props) {
107
117
  }, renderValue: (selected) => {
108
118
  // The text shows up
109
119
  return localOptions
110
- .filter((option) => Array.isArray(selected)
111
- ? selected.indexOf(option.id) !== -1
112
- : selected === option.id)
113
- .map((option) => option.label)
120
+ .filter((option) => {
121
+ const id = getId(option);
122
+ return Array.isArray(selected)
123
+ ? selected.indexOf(id) !== -1
124
+ : selected === id;
125
+ })
126
+ .map((option) => getLabel(option))
114
127
  .join(', ');
115
128
  }, sx: { minWidth: '150px' }, ...rest }, localOptions.map((option) => {
116
129
  // Option id
117
- const id = option[idField];
130
+ const id = getId(option);
118
131
  // Option label
119
- const label = typeof labelField === 'function'
120
- ? labelField(option)
121
- : option[labelField];
132
+ const label = getLabel(option);
122
133
  // Option
123
134
  return (React.createElement(MenuItem, { key: id, value: id, onClick: (event) => {
124
135
  if (onItemClick) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.77",
3
+ "version": "1.4.78",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  "@emotion/styled": "^11.6.0",
53
53
  "@etsoo/appscript": "^1.2.28",
54
54
  "@etsoo/notificationbase": "^1.1.0",
55
- "@etsoo/shared": "^1.1.6",
55
+ "@etsoo/shared": "^1.1.7",
56
56
  "@mui/icons-material": "^5.3.1",
57
57
  "@mui/material": "^5.3.1",
58
58
  "@reach/router": "^1.3.4",
@@ -143,6 +143,18 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
143
143
  }
144
144
  };
145
145
 
146
+ // Get option id
147
+ const getId = (option: T) => {
148
+ return Reflect.get(option, idField);
149
+ };
150
+
151
+ // Get option label
152
+ const getLabel = (option: T) => {
153
+ return typeof labelField === 'function'
154
+ ? labelField(option)
155
+ : Reflect.get(option, labelField);
156
+ };
157
+
146
158
  // Refs
147
159
  const divRef = React.useRef<HTMLDivElement>();
148
160
 
@@ -198,26 +210,24 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
198
210
  renderValue={(selected) => {
199
211
  // The text shows up
200
212
  return localOptions
201
- .filter((option: any) =>
202
- Array.isArray(selected)
203
- ? selected.indexOf(option.id) !== -1
204
- : selected === option.id
205
- )
206
- .map((option: any) => option.label)
213
+ .filter((option) => {
214
+ const id = getId(option);
215
+ return Array.isArray(selected)
216
+ ? selected.indexOf(id) !== -1
217
+ : selected === id;
218
+ })
219
+ .map((option) => getLabel(option))
207
220
  .join(', ');
208
221
  }}
209
222
  sx={{ minWidth: '150px' }}
210
223
  {...rest}
211
224
  >
212
- {localOptions.map((option: any) => {
225
+ {localOptions.map((option) => {
213
226
  // Option id
214
- const id = option[idField];
227
+ const id = getId(option);
215
228
 
216
229
  // Option label
217
- const label =
218
- typeof labelField === 'function'
219
- ? labelField(option)
220
- : option[labelField];
230
+ const label = getLabel(option);
221
231
 
222
232
  // Option
223
233
  return (