diginet-core-ui 1.4.9 → 1.4.10
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/components/form-control/dropdown/index.js +126 -103
- package/package.json +1 -1
- package/readme.md +6 -0
|
@@ -18,7 +18,7 @@ const {
|
|
|
18
18
|
const
|
|
19
19
|
// timing = {},
|
|
20
20
|
currentValue = {},
|
|
21
|
-
currentObjectDefault = {},
|
|
21
|
+
// currentObjectDefault = {},
|
|
22
22
|
isSearch = {},
|
|
23
23
|
allValue = {};
|
|
24
24
|
const separatorPattern = /\{\w+\}/g;
|
|
@@ -43,6 +43,17 @@ const convertSearchDelayTime = searchDelayTime => {
|
|
|
43
43
|
};
|
|
44
44
|
return typeof searchDelayTime === 'number' ? searchDelayTime : (((_searchDelayTime$matc = searchDelayTime.match(/[^a-z]+/i)) === null || _searchDelayTime$matc === void 0 ? void 0 : _searchDelayTime$matc[0]) || 1) * units[((_searchDelayTime$matc2 = searchDelayTime.match(/ms|s|m/i)) === null || _searchDelayTime$matc2 === void 0 ? void 0 : _searchDelayTime$matc2[0]) || 's'];
|
|
45
45
|
};
|
|
46
|
+
const uniqBy = (arr, iteratee) => {
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
return arr.filter(item => {
|
|
49
|
+
const val = iteratee(item);
|
|
50
|
+
if (seen.has(val)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
seen.add(val);
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
56
|
+
};
|
|
46
57
|
const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
47
58
|
action = {},
|
|
48
59
|
allowSearch,
|
|
@@ -133,6 +144,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
133
144
|
substitle: '',
|
|
134
145
|
description: ''
|
|
135
146
|
});
|
|
147
|
+
const [vlObjDefaultState, setVlObjDefaultState] = useState([]);
|
|
136
148
|
let valueTemp = valueProp || defaultValue || [];
|
|
137
149
|
|
|
138
150
|
// only mode multi
|
|
@@ -144,7 +156,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
144
156
|
const _InputCSS = InputCSS(multiple, typeof renderSelectedItem === 'function');
|
|
145
157
|
const _DropdownInputCSS = DropdownInputCSS(viewType, multiple, placeholder, disabled, readOnly, multilineSelectedItem);
|
|
146
158
|
const _IconCSS = IconCSS(viewType);
|
|
147
|
-
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, disabled, placeholder, _DropdownInputCSS.name);
|
|
159
|
+
const _DropdownFormCSS = DropdownFormCSS(viewType, multiple, disabled, readOnly, placeholder, _DropdownInputCSS.name);
|
|
148
160
|
const _DropdownListCSS = DropdownListCSS(loadingState);
|
|
149
161
|
const _DropdownItemCSS = DropdownItemCSS(multiple, selectBox);
|
|
150
162
|
const _DropdownRootCSS = DropdownRootCSS(_DropdownFormCSS.name, _DropdownInputCSS.name);
|
|
@@ -310,7 +322,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
310
322
|
}
|
|
311
323
|
}
|
|
312
324
|
// document.documentElement.style.overflow = 'auto';
|
|
313
|
-
setTxtSearch('');
|
|
325
|
+
// setTxtSearch('');
|
|
314
326
|
onClosed === null || onClosed === void 0 ? void 0 : onClosed();
|
|
315
327
|
};
|
|
316
328
|
|
|
@@ -360,7 +372,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
360
372
|
// convert {id} - {name} to {<data[id]>} - {<data[name]>}
|
|
361
373
|
if (!mask && regexBetween.test(displayExpr)) {
|
|
362
374
|
var _displayExpr;
|
|
363
|
-
mask = (_displayExpr = displayExpr) === null || _displayExpr === void 0 ? void 0 : _displayExpr.replace(regexBetween, _ => data[_]);
|
|
375
|
+
mask = (_displayExpr = displayExpr) === null || _displayExpr === void 0 ? void 0 : _displayExpr.replace(regexBetween, _ => (data === null || data === void 0 ? void 0 : data[_]) || '');
|
|
364
376
|
} else if (!mask) {
|
|
365
377
|
mask = typeof data !== 'object' ? data : '';
|
|
366
378
|
}
|
|
@@ -369,7 +381,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
369
381
|
return text;
|
|
370
382
|
};
|
|
371
383
|
const mapDropdown = () => {
|
|
372
|
-
var
|
|
384
|
+
var _dataSourceUsable2;
|
|
373
385
|
const items = [];
|
|
374
386
|
let dataSourceUsable = [...dataSourceState];
|
|
375
387
|
|
|
@@ -386,22 +398,23 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
386
398
|
}
|
|
387
399
|
});
|
|
388
400
|
}
|
|
389
|
-
if (
|
|
390
|
-
const length =
|
|
401
|
+
if (vlObjDefaultState && vlObjDefaultState !== null && vlObjDefaultState !== void 0 && vlObjDefaultState.length) {
|
|
402
|
+
const length = vlObjDefaultState === null || vlObjDefaultState === void 0 ? void 0 : vlObjDefaultState.length;
|
|
391
403
|
let existItemQuantity = 0;
|
|
392
404
|
for (let index = length - 1; index >= 0; index--) {
|
|
393
|
-
if ((
|
|
394
|
-
dataSourceUsable.unshift(
|
|
405
|
+
if ((vlObjDefaultState[index][valueExpr] || vlObjDefaultState[index][valueExpr] === 0) && !dataSourceUsable.some(data => data[valueExpr] === vlObjDefaultState[index][valueExpr])) {
|
|
406
|
+
dataSourceUsable.unshift(vlObjDefaultState[index]);
|
|
395
407
|
} else {
|
|
396
408
|
// Nếu số lượng phần tử của valueObjectDefault tồn tại trong dataSource nhiều hơn hoặc bằng limit thì không remove nữa
|
|
397
409
|
if (++existItemQuantity > limit) {
|
|
398
410
|
continue;
|
|
399
411
|
}
|
|
400
|
-
currentObjectDefault[unique].splice(index, 1);
|
|
412
|
+
// currentObjectDefault[unique].splice(index, 1);
|
|
401
413
|
}
|
|
402
414
|
}
|
|
403
415
|
}
|
|
404
|
-
|
|
416
|
+
|
|
417
|
+
const length = (_dataSourceUsable2 = dataSourceUsable) === null || _dataSourceUsable2 === void 0 ? void 0 : _dataSourceUsable2.length;
|
|
405
418
|
for (let index = 0; index < length; index++) {
|
|
406
419
|
const data = dataSourceUsable[index];
|
|
407
420
|
if (!data) continue;
|
|
@@ -519,20 +532,20 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
519
532
|
|
|
520
533
|
// remove item cũ và append child item mới khi load more
|
|
521
534
|
const loadMoreItemsDropdown = (i = 0, pattern) => {
|
|
522
|
-
var
|
|
535
|
+
var _displayExpr2;
|
|
523
536
|
const dataSourceUsable = [...dataSourceState];
|
|
524
537
|
// Nếu có load more thì đẩy đội tượng mặc định lên đầu
|
|
525
538
|
let notExistItem = 0;
|
|
526
|
-
if (onLoadMore &&
|
|
527
|
-
const length =
|
|
539
|
+
if (onLoadMore && vlObjDefaultState !== null && vlObjDefaultState !== void 0 && vlObjDefaultState.length) {
|
|
540
|
+
const length = vlObjDefaultState.length;
|
|
528
541
|
for (let index = length - 1; index >= 0; index--) {
|
|
529
|
-
if (!dataSourceUsable.some(data => data[valueExpr] ===
|
|
542
|
+
if (!dataSourceUsable.some(data => data[valueExpr] === vlObjDefaultState[index][valueExpr])) {
|
|
530
543
|
notExistItem++;
|
|
531
|
-
dataSourceUsable.unshift(
|
|
544
|
+
dataSourceUsable.unshift(vlObjDefaultState[index]);
|
|
532
545
|
}
|
|
533
546
|
}
|
|
534
547
|
}
|
|
535
|
-
const length = dataSourceUsable.length;
|
|
548
|
+
const length = dataSourceUsable === null || dataSourceUsable === void 0 ? void 0 : dataSourceUsable.length;
|
|
536
549
|
let num = 0;
|
|
537
550
|
if (displayExpr && Array.isArray(displayExpr)) {
|
|
538
551
|
displayExpr = displayExpr.join(' - ');
|
|
@@ -543,8 +556,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
543
556
|
...dataSourceUsable[i]
|
|
544
557
|
};
|
|
545
558
|
// Nếu đối tượng đã được hiển thị ở trên rồi thì không hiển thị ra nữa
|
|
546
|
-
if (onLoadMore && i > notExistItem &&
|
|
547
|
-
let displayText = typeof data === 'object' ? keyArr ?
|
|
559
|
+
if (onLoadMore && i > notExistItem && vlObjDefaultState.some(valueObject => valueObject[valueExpr] === data[valueExpr])) continue;
|
|
560
|
+
let displayText = typeof data === 'object' ? keyArr ? displayValue(data) : data[displayExpr] || data[valueExpr] : data;
|
|
548
561
|
if (pattern && !new RegExp(pattern).test(displayText.normalize())) continue;
|
|
549
562
|
const value = typeof data === 'object' ? data[valueExpr] : data;
|
|
550
563
|
const icon = getIconFromData(data);
|
|
@@ -599,18 +612,24 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
599
612
|
}
|
|
600
613
|
}
|
|
601
614
|
};
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
615
|
+
|
|
616
|
+
// const renderData = (data, keyArr) => {
|
|
617
|
+
// const pattern = keyArr.join('|').replace(/([{}])/g, '\\$1');
|
|
618
|
+
// const separatorArr = displayExpr.split(new RegExp(pattern));
|
|
619
|
+
// let str = '';
|
|
620
|
+
// let i = 0;
|
|
621
|
+
// for (i; i < keyArr.length; i++) {
|
|
622
|
+
// str +=
|
|
623
|
+
// separatorArr[i] +
|
|
624
|
+
// (data[keyArr[i].replace(/\W/g, '')] !== undefined
|
|
625
|
+
// ? data[keyArr[i].replace(/\W/g, '')]
|
|
626
|
+
// : keyArr[i]);
|
|
627
|
+
// }
|
|
628
|
+
// return str + separatorArr[i];
|
|
629
|
+
// };
|
|
630
|
+
|
|
612
631
|
const getIconFromData = (data, insideChip = false) => {
|
|
613
|
-
if (!iconExpr || iconExpr === 'none') return null;
|
|
632
|
+
if (!data || !iconExpr || iconExpr === 'none') return null;
|
|
614
633
|
let _src;
|
|
615
634
|
if (typeof iconExpr === 'string') _src = data[iconExpr];else {
|
|
616
635
|
let prefix = iconExpr.prefix || '';
|
|
@@ -718,7 +737,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
718
737
|
rows = data;
|
|
719
738
|
} else {
|
|
720
739
|
rows = data && data.rows ? data.rows : dataSourceState;
|
|
721
|
-
const total = data && data.total ? data.total : data.length;
|
|
740
|
+
const total = data && data.total ? data.total : data === null || data === void 0 ? void 0 : data.length;
|
|
722
741
|
setTotalState(total);
|
|
723
742
|
}
|
|
724
743
|
setDataSourceState(isReset ? rows : dataSourceState.concat(rows));
|
|
@@ -738,8 +757,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
738
757
|
offsetHeight
|
|
739
758
|
} = e.target;
|
|
740
759
|
if (scrollHeight === Math.ceil(scrollTop) + offsetHeight && dropdownListRef.current) {
|
|
741
|
-
var _dropdownListRef$curr
|
|
742
|
-
const length = ((_dropdownListRef$curr = dropdownListRef.current.children) === null || _dropdownListRef$curr === void 0 ? void 0 : _dropdownListRef$curr.length) - ((
|
|
760
|
+
var _dropdownListRef$curr;
|
|
761
|
+
const length = ((_dropdownListRef$curr = dropdownListRef.current.children) === null || _dropdownListRef$curr === void 0 ? void 0 : _dropdownListRef$curr.length) - ((vlObjDefaultState === null || vlObjDefaultState === void 0 ? void 0 : vlObjDefaultState.length) || 0);
|
|
743
762
|
dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
744
763
|
if (!!onLoadMore && typeof onLoadMore === 'boolean' && action !== null && action !== void 0 && action.loadData) {
|
|
745
764
|
filter.current.skip = length;
|
|
@@ -955,8 +974,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
955
974
|
});
|
|
956
975
|
};
|
|
957
976
|
const setPreviousValue = () => {
|
|
977
|
+
var _allValue$unique;
|
|
958
978
|
allValue[unique].pop();
|
|
959
|
-
setValueIntoInput(allValue[unique][allValue[unique].length - 1]);
|
|
979
|
+
setValueIntoInput(allValue[unique][((_allValue$unique = allValue[unique]) === null || _allValue$unique === void 0 ? void 0 : _allValue$unique.length) - 1]);
|
|
960
980
|
};
|
|
961
981
|
const setValueIntoInput = source => {
|
|
962
982
|
if (!source && source !== 0) {
|
|
@@ -973,10 +993,11 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
973
993
|
// inputRef.current.value = '';
|
|
974
994
|
// }
|
|
975
995
|
currentValue[unique] = '';
|
|
996
|
+
setValueSingle('');
|
|
976
997
|
}
|
|
977
998
|
return;
|
|
978
999
|
}
|
|
979
|
-
const length = dataSourceState.length;
|
|
1000
|
+
const length = dataSourceState === null || dataSourceState === void 0 ? void 0 : dataSourceState.length;
|
|
980
1001
|
const displayKey = typeof renderSelectedItem === 'string' ? renderSelectedItem : displayExpr;
|
|
981
1002
|
if (displayKey && Array.isArray(displayKey)) {
|
|
982
1003
|
displayExpr = displayExpr.join(' - ');
|
|
@@ -991,7 +1012,6 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
991
1012
|
currentValue[unique] = [];
|
|
992
1013
|
// inputRef.current.innerHTML = '';
|
|
993
1014
|
valueArr.forEach(v => {
|
|
994
|
-
var _currentObjectDefault4;
|
|
995
1015
|
for (let i = 0; i < length; i++) {
|
|
996
1016
|
if (!dataSourceState[i]) continue;
|
|
997
1017
|
if (typeof dataSourceState[i] === 'object' && dataSourceState[i][valueExpr] === v || dataSourceState[i] === v) {
|
|
@@ -999,15 +1019,14 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
999
1019
|
return;
|
|
1000
1020
|
}
|
|
1001
1021
|
}
|
|
1002
|
-
if (
|
|
1003
|
-
const itemOfValue =
|
|
1022
|
+
if (vlObjDefaultState !== null && vlObjDefaultState !== void 0 && vlObjDefaultState.length) {
|
|
1023
|
+
const itemOfValue = vlObjDefaultState.find(valueObject => valueObject[valueExpr] === v || valueObject === v);
|
|
1004
1024
|
if (itemOfValue) {
|
|
1005
1025
|
setMultipleValueHandler(itemOfValue, v, keyArr);
|
|
1006
1026
|
}
|
|
1007
1027
|
}
|
|
1008
1028
|
});
|
|
1009
1029
|
} else {
|
|
1010
|
-
var _currentObjectDefault5;
|
|
1011
1030
|
currentValue[unique] = source;
|
|
1012
1031
|
for (let i = 0; i < length; i++) {
|
|
1013
1032
|
if (!dataSourceState[i]) continue;
|
|
@@ -1016,8 +1035,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1016
1035
|
return;
|
|
1017
1036
|
}
|
|
1018
1037
|
}
|
|
1019
|
-
if (
|
|
1020
|
-
const itemOfValue =
|
|
1038
|
+
if (vlObjDefaultState !== null && vlObjDefaultState !== void 0 && vlObjDefaultState.length) {
|
|
1039
|
+
const itemOfValue = vlObjDefaultState.find(valueObject => valueObject[valueExpr] === source || valueObject === source);
|
|
1021
1040
|
if (itemOfValue) {
|
|
1022
1041
|
setSingleValueHandler(itemOfValue, keyArr);
|
|
1023
1042
|
return;
|
|
@@ -1054,7 +1073,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1054
1073
|
currentValue[unique].push(value);
|
|
1055
1074
|
};
|
|
1056
1075
|
const setSingleValueHandler = (data, keyArr) => {
|
|
1057
|
-
const text = keyArr ?
|
|
1076
|
+
const text = keyArr ? displayValue(data) : typeof renderSelectedItem === 'string' ? data[renderSelectedItem] : data[displayExpr] || data[valueExpr] || data;
|
|
1058
1077
|
const renderContent = content => jsx(Typography, {
|
|
1059
1078
|
type: 'p1',
|
|
1060
1079
|
lineClamp: multilineSelectedItem ? undefined : 1,
|
|
@@ -1104,7 +1123,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1104
1123
|
onClear,
|
|
1105
1124
|
setPreviousValue,
|
|
1106
1125
|
setValue: value => {
|
|
1107
|
-
|
|
1126
|
+
var _allValue$unique2;
|
|
1127
|
+
if (allValue[unique][((_allValue$unique2 = allValue[unique]) === null || _allValue$unique2 === void 0 ? void 0 : _allValue$unique2.length) - 1] !== value) {
|
|
1108
1128
|
allValue[unique].push(value);
|
|
1109
1129
|
}
|
|
1110
1130
|
setValueIntoInput(value);
|
|
@@ -1118,7 +1138,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1118
1138
|
currentRef.onClear = onClear;
|
|
1119
1139
|
currentRef.setPreviousValue = setPreviousValue;
|
|
1120
1140
|
currentRef.setValue = value => {
|
|
1121
|
-
|
|
1141
|
+
var _allValue$unique3;
|
|
1142
|
+
if (allValue[unique][((_allValue$unique3 = allValue[unique]) === null || _allValue$unique3 === void 0 ? void 0 : _allValue$unique3.length) - 1] !== value) {
|
|
1122
1143
|
allValue[unique].push(value);
|
|
1123
1144
|
}
|
|
1124
1145
|
setValueIntoInput(value);
|
|
@@ -1139,19 +1160,27 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1139
1160
|
setShowClear(clearAble && checkHasValue(valueProp !== null && valueProp !== void 0 ? valueProp : defaultValue) && !disabled && !readOnly && !loadingState);
|
|
1140
1161
|
}, [clearAble, valueProp, defaultValue, disabled, readOnly, loadingState]);
|
|
1141
1162
|
useEffect(() => {
|
|
1163
|
+
if (multiple) {
|
|
1164
|
+
if (valueMulti !== null && valueMulti !== void 0 && valueMulti.length) {
|
|
1165
|
+
const dataFilter = getData();
|
|
1166
|
+
dataChosen.current = [...dataFilter].filter(i => [...valueMulti].includes(i === null || i === void 0 ? void 0 : i[valueExpr]));
|
|
1167
|
+
} else dataChosen.current = [];
|
|
1168
|
+
}
|
|
1142
1169
|
if (valueObjectDefault) {
|
|
1143
1170
|
if (Array.isArray(valueObjectDefault)) {
|
|
1144
|
-
currentObjectDefault[unique] = [...valueObjectDefault];
|
|
1171
|
+
// currentObjectDefault[unique] = [...valueObjectDefault];
|
|
1172
|
+
setVlObjDefaultState([...dataChosen.current, ...valueObjectDefault]);
|
|
1145
1173
|
} else if (typeof valueObjectDefault === 'object') {
|
|
1146
|
-
|
|
1174
|
+
var _Object$keys;
|
|
1175
|
+
// currentObjectDefault[unique] =
|
|
1176
|
+
// Object.keys(valueObjectDefault).length !== 0 ? [valueObjectDefault] : [];
|
|
1177
|
+
setVlObjDefaultState(((_Object$keys = Object.keys(valueObjectDefault)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.length) !== 0 ? [...dataChosen.current, valueObjectDefault] : [...dataChosen.current]);
|
|
1147
1178
|
}
|
|
1148
1179
|
} else {
|
|
1149
|
-
currentObjectDefault[unique] = [];
|
|
1180
|
+
// currentObjectDefault[unique] = [];
|
|
1181
|
+
setVlObjDefaultState([...dataChosen.current]);
|
|
1150
1182
|
}
|
|
1151
|
-
|
|
1152
|
-
currentObjectDefault[unique] = null;
|
|
1153
|
-
};
|
|
1154
|
-
}, [valueObjectDefault]);
|
|
1183
|
+
}, [valueObjectDefault, valueMulti]);
|
|
1155
1184
|
useEffect(() => {
|
|
1156
1185
|
allValue[unique] = [];
|
|
1157
1186
|
if (defaultValue !== undefined && JSON.stringify(defaultValue) !== '[]') {
|
|
@@ -1185,7 +1214,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1185
1214
|
// }, [searchDelayTime]);
|
|
1186
1215
|
|
|
1187
1216
|
useEffect(() => {
|
|
1188
|
-
|
|
1217
|
+
var _allValue$unique4;
|
|
1218
|
+
if (allValue[unique][((_allValue$unique4 = allValue[unique]) === null || _allValue$unique4 === void 0 ? void 0 : _allValue$unique4.length) - 1] !== valueProp) {
|
|
1189
1219
|
allValue[unique].push(valueProp);
|
|
1190
1220
|
}
|
|
1191
1221
|
if (multiple && valueProp) {
|
|
@@ -1200,7 +1230,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1200
1230
|
if (valueProp !== undefined && (!dropdownListRef.current || children || JSON.stringify(valueProp) !== JSON.stringify(currentValue[unique]))) {
|
|
1201
1231
|
setValueIntoInput(valueProp);
|
|
1202
1232
|
}
|
|
1203
|
-
}, [valueProp, dataSourceState]);
|
|
1233
|
+
}, [valueProp, dataSourceState, vlObjDefaultState]);
|
|
1204
1234
|
useEffect(() => {
|
|
1205
1235
|
inputRef.current.readOnly = readOnly || inputProps.readOnly;
|
|
1206
1236
|
if (!readOnly && !disabled) {
|
|
@@ -1238,12 +1268,12 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1238
1268
|
inputRef.current.addEventListener('click', onClickInput);
|
|
1239
1269
|
}
|
|
1240
1270
|
if (dropdownListRef.current) {
|
|
1241
|
-
var _dropdownListRef$curr2, _dropdownListRef$curr3
|
|
1271
|
+
var _dropdownListRef$curr2, _dropdownListRef$curr3;
|
|
1242
1272
|
if (!disabled && !readOnly) {
|
|
1243
1273
|
inputRef.current.addEventListener('input', onChangeInput);
|
|
1244
1274
|
}
|
|
1245
1275
|
const length = (_dropdownListRef$curr2 = dropdownListRef.current) === null || _dropdownListRef$curr2 === void 0 ? void 0 : (_dropdownListRef$curr3 = _dropdownListRef$curr2.children) === null || _dropdownListRef$curr3 === void 0 ? void 0 : _dropdownListRef$curr3.length;
|
|
1246
|
-
if (length < dataSourceState.length + (
|
|
1276
|
+
if (length < (dataSourceState === null || dataSourceState === void 0 ? void 0 : dataSourceState.length) + (vlObjDefaultState === null || vlObjDefaultState === void 0 ? void 0 : vlObjDefaultState.length) && !isSearch[unique]) {
|
|
1247
1277
|
loadMoreItemsDropdown(length);
|
|
1248
1278
|
!!onLoadMore && dataSourceState.length < totalState && dropdownListRef.current.addEventListener('scroll', onLoadMoreHandler);
|
|
1249
1279
|
} else {
|
|
@@ -1262,6 +1292,15 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1262
1292
|
!!dropdownListRef.current && dropdownListRef.current.removeEventListener('scroll', onLoadMoreHandler);
|
|
1263
1293
|
};
|
|
1264
1294
|
}, [dataSourceState]);
|
|
1295
|
+
useEffect(() => {
|
|
1296
|
+
if (!openState && txtSearch) {
|
|
1297
|
+
setTxtSearch('');
|
|
1298
|
+
if (action !== null && action !== void 0 && action.loadData && !!onLoadMore) {
|
|
1299
|
+
filter.current.strSearch = '';
|
|
1300
|
+
handleActionLoadData(true);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}, [openState]);
|
|
1265
1304
|
useLayoutEffect(() => {
|
|
1266
1305
|
if (ref.current) {
|
|
1267
1306
|
const {
|
|
@@ -1284,13 +1323,13 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1284
1323
|
}, label) : null, [label, required, disabled, labelProps]);
|
|
1285
1324
|
const getData = () => {
|
|
1286
1325
|
let dataFilter = JSON.parse(JSON.stringify(dataSourceState));
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1326
|
+
// dataFilter = [...dataFilter, ...dataChosen.current];
|
|
1327
|
+
// if (Array.isArray(valueObjectDefault)) {
|
|
1328
|
+
// dataFilter = [...dataFilter, ...vlObjDefaultState];
|
|
1329
|
+
// } else if (typeof valueObjectDefault === 'object') {
|
|
1330
|
+
// dataFilter = [...dataFilter, { ...vlObjDefaultState }];
|
|
1331
|
+
// }
|
|
1332
|
+
dataFilter = uniqBy([...vlObjDefaultState, ...dataFilter], data => data === null || data === void 0 ? void 0 : data[valueExpr]);
|
|
1294
1333
|
return dataFilter;
|
|
1295
1334
|
};
|
|
1296
1335
|
const InputView = useMemo(() => {
|
|
@@ -1312,45 +1351,30 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1312
1351
|
return false;
|
|
1313
1352
|
}
|
|
1314
1353
|
}, valueMulti.map((vl, index) => {
|
|
1315
|
-
|
|
1354
|
+
const dataFilter = getData();
|
|
1316
1355
|
const data = dataFilter.find(v => v[valueExpr] === vl || v === vl);
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1356
|
+
if (data) {
|
|
1357
|
+
const displayText = displayValue(data);
|
|
1358
|
+
let item;
|
|
1359
|
+
if (typeof renderSelectedItem === 'function') {
|
|
1360
|
+
item = renderSelectedItem({
|
|
1361
|
+
data,
|
|
1362
|
+
index
|
|
1363
|
+
});
|
|
1364
|
+
} else {
|
|
1365
|
+
item = jsx(Chip, {
|
|
1366
|
+
css: [parseWidth('100%'), parseMaxWidth('max-content')],
|
|
1367
|
+
key: index,
|
|
1368
|
+
startIcon: getIconFromData(data, true),
|
|
1369
|
+
label: displayText,
|
|
1370
|
+
size: 'medium',
|
|
1371
|
+
disabled: disabled,
|
|
1372
|
+
clearAble: !readOnly && !disabled,
|
|
1373
|
+
onRemove: e => onRemove(e, vl)
|
|
1374
|
+
});
|
|
1332
1375
|
}
|
|
1333
|
-
|
|
1334
|
-
}
|
|
1335
|
-
let item;
|
|
1336
|
-
if (typeof renderSelectedItem === 'function') {
|
|
1337
|
-
item = renderSelectedItem({
|
|
1338
|
-
data,
|
|
1339
|
-
index
|
|
1340
|
-
});
|
|
1341
|
-
} else {
|
|
1342
|
-
item = jsx(Chip, {
|
|
1343
|
-
css: [parseWidth('100%'), parseMaxWidth('max-content')],
|
|
1344
|
-
key: index,
|
|
1345
|
-
startIcon: getIconFromData(data, true),
|
|
1346
|
-
label: text,
|
|
1347
|
-
size: 'medium',
|
|
1348
|
-
disabled: disabled,
|
|
1349
|
-
clearAble: !readOnly && !disabled,
|
|
1350
|
-
onRemove: e => onRemove(e, vl)
|
|
1351
|
-
});
|
|
1376
|
+
return item;
|
|
1352
1377
|
}
|
|
1353
|
-
return item;
|
|
1354
1378
|
})) : typeof renderSelectedItem === 'function' || iconExpr && iconExpr !== 'none' ? jsx("div", {
|
|
1355
1379
|
...inputProps,
|
|
1356
1380
|
style: inputStyle,
|
|
@@ -1394,7 +1418,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
1394
1418
|
onClick: setShowDropdown,
|
|
1395
1419
|
disabled: disabled || readOnly
|
|
1396
1420
|
}) : null));
|
|
1397
|
-
}, [openState, showClear, valueSingle, valueMulti, loadingState, dataSourceState, clearAble, dataSource, disabled, displayExpr, inputProps, inputStyle, multilineSelectedItem, multiple, onChange, placeholder, readOnly, renderSelectedItem, valueExpr, valueObjectDefault, viewType]);
|
|
1421
|
+
}, [openState, showClear, valueSingle, valueMulti, loadingState, dataSourceState, vlObjDefaultState, clearAble, dataSource, disabled, displayExpr, inputProps, inputStyle, multilineSelectedItem, multiple, onChange, placeholder, readOnly, renderSelectedItem, valueExpr, valueObjectDefault, viewType]);
|
|
1398
1422
|
const ErrorView = useMemo(() => {
|
|
1399
1423
|
return error ? jsx(HelperText, {
|
|
1400
1424
|
...helperTextProps,
|
|
@@ -1491,7 +1515,7 @@ const IconCSS = viewType => css`
|
|
|
1491
1515
|
${mgl([2])};
|
|
1492
1516
|
${mgr([viewType !== 'outlined' ? 0 : 4])};
|
|
1493
1517
|
`;
|
|
1494
|
-
const DropdownFormCSS = (viewType, multiple, disabled, placeholder, DropdownInputCSSName) => viewType !== 'outlined' ? css`
|
|
1518
|
+
const DropdownFormCSS = (viewType, multiple, disabled, readOnly, placeholder, DropdownInputCSSName) => viewType !== 'outlined' ? css`
|
|
1495
1519
|
${displayFlex};
|
|
1496
1520
|
${flexRow};
|
|
1497
1521
|
${itemsCenter};
|
|
@@ -1499,7 +1523,7 @@ const DropdownFormCSS = (viewType, multiple, disabled, placeholder, DropdownInpu
|
|
|
1499
1523
|
${boxBorder};
|
|
1500
1524
|
${parseWidth('100%')};
|
|
1501
1525
|
${pdy([multiple ? 0.25 : 1])};
|
|
1502
|
-
${!disabled && css`
|
|
1526
|
+
${!disabled && !readOnly && css`
|
|
1503
1527
|
&:not(:focus-within):hover {
|
|
1504
1528
|
&::before {
|
|
1505
1529
|
${borderBottomColor('system/active')};
|
|
@@ -1559,7 +1583,7 @@ const DropdownFormCSS = (viewType, multiple, disabled, placeholder, DropdownInpu
|
|
|
1559
1583
|
${parseWidth('100%')};
|
|
1560
1584
|
${parseMinHeight(40)};
|
|
1561
1585
|
${mgt([0.5])};
|
|
1562
|
-
${!disabled && css`
|
|
1586
|
+
${!disabled && !readOnly && css`
|
|
1563
1587
|
&:not(:focus-within):hover {
|
|
1564
1588
|
${bgColor('fill/hover')};
|
|
1565
1589
|
${borderColor('system/active')};
|
|
@@ -1736,7 +1760,6 @@ Dropdown.defaultProps = {
|
|
|
1736
1760
|
multilineSelectedItem: false,
|
|
1737
1761
|
multiple: false,
|
|
1738
1762
|
noDataText: getGlobal('noDataText'),
|
|
1739
|
-
onInput: null,
|
|
1740
1763
|
placeholder: getGlobal('dropdownPlaceholder'),
|
|
1741
1764
|
readOnly: false,
|
|
1742
1765
|
required: false,
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -38,6 +38,12 @@ npm test
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Changelog
|
|
41
|
+
## 1.4.10
|
|
42
|
+
- \[Fixed\]: Dropdown – Fix display text when data invalid
|
|
43
|
+
- \[Fixed\]: Dropdown – Fix bug crash when get icon from invalid data
|
|
44
|
+
- \[Fixed\]: Dropdown – Fix not reset data when close dropdown after search
|
|
45
|
+
- \[Fixed\]: Dropdown – Fix not clear display value when set value null
|
|
46
|
+
|
|
41
47
|
## 1.4.9
|
|
42
48
|
- \[Changed\]: IconMenu – Add 16 icon menu of HR Mobile App
|
|
43
49
|
- \[Fixed\]: Chip – Fix width of TabHeader
|