react-core-ts 2.1.35 → 2.1.37
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/dist/AutoComplete.js +5 -4
- package/dist/AutoComplete.js.map +1 -1
- package/dist/AutoCompleteWithSelectedList.js +13 -9
- package/dist/AutoCompleteWithSelectedList.js.map +1 -1
- package/dist/AutoCompleteWithTabFilter.js +14 -10
- package/dist/AutoCompleteWithTabFilter.js.map +1 -1
- package/dist/AutoCompleteWithTreeStructure.js +3 -5
- package/dist/AutoCompleteWithTreeStructure.js.map +1 -1
- package/dist/ExpandableAutoComplete.js +2 -6
- package/dist/ExpandableAutoComplete.js.map +1 -1
- package/dist/dropdownFilterTabs.js +14 -12
- package/dist/dropdownFilterTabs.js.map +1 -1
- package/dist/dummyAutoCompleteWithSelectedList.js +5 -4
- package/dist/dummyAutoCompleteWithSelectedList.js.map +1 -1
- package/dist/utilities/getKeyValue.d.ts +4 -0
- package/dist/utilities/getKeyValue.js +21 -1
- package/dist/utilities/getKeyValue.js.map +1 -1
- package/docs/App.tsx +1 -1
- package/package.json +1 -1
- package/src/AutoComplete.tsx +5 -4
- package/src/AutoCompleteWithSelectedList.tsx +18 -13
- package/src/AutoCompleteWithTabFilter.tsx +19 -14
- package/src/AutoCompleteWithTreeStructure.tsx +5 -6
- package/src/ExpandableAutoComplete.tsx +5 -10
- package/src/dropdownFilterTabs.tsx +18 -16
- package/src/dummyAutoCompleteWithSelectedList.tsx +5 -4
- package/src/utilities/getKeyValue.ts +34 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeToLowerString = exports.getKeyValue = void 0;
|
|
3
|
+
exports.isSelectionMatchValue = exports.isSelectionMatch = exports.safeToLowerString = exports.getKeyValue = void 0;
|
|
4
4
|
// Utility function to safely get a value by key (which may be empty, null, or a number) and fallback to a default key
|
|
5
5
|
function getKeyValue(obj, key, fallbackKey) {
|
|
6
6
|
if (key !== undefined && key !== null && key !== '') {
|
|
@@ -17,4 +17,24 @@ function safeToLowerString(val) {
|
|
|
17
17
|
return String(val).toLowerCase();
|
|
18
18
|
}
|
|
19
19
|
exports.safeToLowerString = safeToLowerString;
|
|
20
|
+
/** Match selected item to a suggestion — id when both exist, otherwise desc. */
|
|
21
|
+
function isSelectionMatch(selectedItem, item, desc, descId) {
|
|
22
|
+
var selectedId = getKeyValue(selectedItem, descId, 'id');
|
|
23
|
+
var itemId = getKeyValue(item, descId, 'id');
|
|
24
|
+
if (selectedId && itemId) {
|
|
25
|
+
return selectedId === itemId;
|
|
26
|
+
}
|
|
27
|
+
return (getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name'));
|
|
28
|
+
}
|
|
29
|
+
exports.isSelectionMatch = isSelectionMatch;
|
|
30
|
+
/** Match a suggestion to a string value (single-select input). */
|
|
31
|
+
function isSelectionMatchValue(item, selectedValue, desc, descId) {
|
|
32
|
+
var normalized = safeToLowerString(selectedValue);
|
|
33
|
+
var itemId = getKeyValue(item, descId, 'id');
|
|
34
|
+
if (itemId && itemId === normalized) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return getKeyValue(item, desc, 'name') === normalized;
|
|
38
|
+
}
|
|
39
|
+
exports.isSelectionMatchValue = isSelectionMatchValue;
|
|
20
40
|
//# sourceMappingURL=getKeyValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getKeyValue.js","sourceRoot":"","sources":["../../src/utilities/getKeyValue.ts"],"names":[],"mappings":";;;AAAA,sHAAsH;AACtH,SAAgB,WAAW,CAAC,GAAQ,EAAE,GAAQ,EAAE,WAAmB;IACjE,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,EAAE;QACnD,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD;IACD,IAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,OAAO,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC;AAPD,kCAOC;AAED,SAAgB,iBAAiB,CAAC,GAAQ;IACxC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACjD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC;AAHD,8CAGC"}
|
|
1
|
+
{"version":3,"file":"getKeyValue.js","sourceRoot":"","sources":["../../src/utilities/getKeyValue.ts"],"names":[],"mappings":";;;AAAA,sHAAsH;AACtH,SAAgB,WAAW,CAAC,GAAQ,EAAE,GAAQ,EAAE,WAAmB;IACjE,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,EAAE;QACnD,IAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD;IACD,IAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IACrC,OAAO,WAAW,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC;AAPD,kCAOC;AAED,SAAgB,iBAAiB,CAAC,GAAQ;IACxC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACjD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC;AAHD,8CAGC;AAED,gFAAgF;AAChF,SAAgB,gBAAgB,CAC9B,YAAiB,EACjB,IAAS,EACT,IAAY,EACZ,MAAc;IAEd,IAAM,UAAU,GAAG,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC3D,IAAM,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAE/C,IAAI,UAAU,IAAI,MAAM,EAAE;QACxB,OAAO,UAAU,KAAK,MAAM,CAAC;KAC9B;IAED,OAAO,CACL,WAAW,CAAC,YAAY,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAC5E,CAAC;AACJ,CAAC;AAhBD,4CAgBC;AAED,kEAAkE;AAClE,SAAgB,qBAAqB,CACnC,IAAS,EACT,aAAqB,EACrB,IAAY,EACZ,MAAc;IAEd,IAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;IACpD,IAAM,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/C,IAAI,MAAM,IAAI,MAAM,KAAK,UAAU,EAAE;QACnC,OAAO,IAAI,CAAC;KACb;IACD,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,UAAU,CAAC;AACxD,CAAC;AAZD,sDAYC"}
|
package/docs/App.tsx
CHANGED
package/package.json
CHANGED
package/src/AutoComplete.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import { useSuggestions } from './utilities/autosuggestions';
|
|
|
12
12
|
import { debounce } from './utilities/debounce';
|
|
13
13
|
import { deepEqual } from './utilities/deepEqual';
|
|
14
14
|
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
15
|
+
import { isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
15
16
|
import { Close, DropArrow, Search, Spinner } from './utilities/icons';
|
|
16
17
|
import Tooltip from './utilities/tooltip';
|
|
17
18
|
|
|
@@ -283,12 +284,12 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
|
|
|
283
284
|
selectedItems: ValueProps[] | string,
|
|
284
285
|
): boolean => {
|
|
285
286
|
if (Array.isArray(selectedItems)) {
|
|
286
|
-
return selectedItems.some(
|
|
287
|
-
(selectedItem
|
|
287
|
+
return selectedItems.some((selectedItem) =>
|
|
288
|
+
isSelectionMatch(selectedItem, item, desc, descId),
|
|
288
289
|
);
|
|
289
|
-
} else {
|
|
290
|
-
return item[desc] === selectedItems;
|
|
291
290
|
}
|
|
291
|
+
|
|
292
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
292
293
|
};
|
|
293
294
|
|
|
294
295
|
const handleLoadMore = () => {
|
|
@@ -18,7 +18,7 @@ import { deepEqual } from './utilities/deepEqual';
|
|
|
18
18
|
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
19
19
|
import { AllDropArrow, DropArrow, Search, Spinner } from './utilities/icons';
|
|
20
20
|
import { default as Tooltip } from './utilities/NewTooltip';
|
|
21
|
-
import { getKeyValue,
|
|
21
|
+
import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
22
22
|
import {
|
|
23
23
|
clampDropdownToViewportPreferRightAlign,
|
|
24
24
|
MAX_DROPDOWN_WIDTH_WITH_TABS_PX,
|
|
@@ -648,17 +648,12 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
648
648
|
selectedItems: ValueProps[] | string
|
|
649
649
|
): boolean => {
|
|
650
650
|
if (Array.isArray(selectedItems)) {
|
|
651
|
-
return selectedItems.some(
|
|
652
|
-
(selectedItem)
|
|
653
|
-
getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name') ||
|
|
654
|
-
getKeyValue(selectedItem, descId, 'id') === getKeyValue(item, descId, 'id')
|
|
655
|
-
);
|
|
656
|
-
} else {
|
|
657
|
-
return (
|
|
658
|
-
getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
|
|
659
|
-
getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
|
|
651
|
+
return selectedItems.some((selectedItem) =>
|
|
652
|
+
isSelectionMatch(selectedItem, item, desc, descId),
|
|
660
653
|
);
|
|
661
654
|
}
|
|
655
|
+
|
|
656
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
662
657
|
};
|
|
663
658
|
|
|
664
659
|
const handleLoadMore = () => {
|
|
@@ -751,17 +746,27 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
751
746
|
setSearchValue('');
|
|
752
747
|
setInputValue('');
|
|
753
748
|
handlePickSuggestions('', 1);
|
|
749
|
+
setAllDataLoaded(false);
|
|
754
750
|
} else {
|
|
755
751
|
resetSuggections?.();
|
|
756
752
|
const activeTabVal =
|
|
757
753
|
tab.length > 0 ? tab?.[index].id : undefined;
|
|
758
|
-
|
|
754
|
+
const normalizedSearchValue = searchValue?.trim();
|
|
755
|
+
const tabSearchValue =
|
|
756
|
+
!tabInlineSearch && allDataLoaded && !normalizedSearchValue
|
|
757
|
+
? '*'
|
|
758
|
+
: searchValue;
|
|
759
|
+
handlePickSuggestions(tabSearchValue, 1, false, activeTabVal);
|
|
759
760
|
}
|
|
760
|
-
setAllDataLoaded(false);
|
|
761
761
|
} else if (!tabInlineSearch) {
|
|
762
762
|
resetSuggections?.();
|
|
763
763
|
const activeTabVal = tab.length > 0 ? tab?.[index].id : undefined;
|
|
764
|
-
|
|
764
|
+
const normalizedSearchValue = searchValue?.trim();
|
|
765
|
+
const tabSearchValue =
|
|
766
|
+
!tabInlineSearch && allDataLoaded && !normalizedSearchValue
|
|
767
|
+
? '*'
|
|
768
|
+
: searchValue;
|
|
769
|
+
handlePickSuggestions(tabSearchValue, 1, false, activeTabVal);
|
|
765
770
|
}
|
|
766
771
|
setActiveTab(index);
|
|
767
772
|
}
|
|
@@ -16,7 +16,7 @@ import { deepEqual } from './utilities/deepEqual';
|
|
|
16
16
|
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
17
17
|
import { AllDropArrow, DropArrow, Search, Spinner, Tools } from './utilities/icons';
|
|
18
18
|
import { default as Tooltip } from './utilities/NewTooltip';
|
|
19
|
-
import { getKeyValue,
|
|
19
|
+
import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
20
20
|
import {
|
|
21
21
|
clampDropdownToViewportPreferRightAlign,
|
|
22
22
|
MAX_DROPDOWN_WIDTH_WITH_TABS_PX,
|
|
@@ -710,17 +710,12 @@ const AutoCompleteWithTabFilter = forwardRef<
|
|
|
710
710
|
selectedItems: ValueProps[] | string
|
|
711
711
|
): boolean => {
|
|
712
712
|
if (Array.isArray(selectedItems)) {
|
|
713
|
-
return selectedItems.some(
|
|
714
|
-
(selectedItem)
|
|
715
|
-
getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name') ||
|
|
716
|
-
getKeyValue(selectedItem, descId, 'id') === getKeyValue(item, descId, 'id')
|
|
717
|
-
);
|
|
718
|
-
} else {
|
|
719
|
-
return (
|
|
720
|
-
getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
|
|
721
|
-
getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
|
|
713
|
+
return selectedItems.some((selectedItem) =>
|
|
714
|
+
isSelectionMatch(selectedItem, item, desc, descId),
|
|
722
715
|
);
|
|
723
716
|
}
|
|
717
|
+
|
|
718
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
724
719
|
};
|
|
725
720
|
|
|
726
721
|
const handleLoadMore = () => {
|
|
@@ -828,21 +823,31 @@ const AutoCompleteWithTabFilter = forwardRef<
|
|
|
828
823
|
setSearchValue('');
|
|
829
824
|
setInputValue('');
|
|
830
825
|
handlePickSuggestions('', 1);
|
|
826
|
+
setAllDataLoaded(false);
|
|
831
827
|
} else {
|
|
832
828
|
resetSuggections?.();
|
|
833
829
|
const activeTabVal =
|
|
834
830
|
tab.length > 0 ? tab?.[index].id : undefined;
|
|
835
|
-
|
|
831
|
+
const normalizedSearchValue = searchValue?.trim();
|
|
832
|
+
const tabSearchValue =
|
|
833
|
+
!tabInlineSearch && allDataLoaded && !normalizedSearchValue
|
|
834
|
+
? '*'
|
|
835
|
+
: searchValue;
|
|
836
|
+
handlePickSuggestions(tabSearchValue, 1, false, activeTabVal);
|
|
836
837
|
}
|
|
837
|
-
setAllDataLoaded(false);
|
|
838
838
|
} else if (!tabInlineSearch) {
|
|
839
839
|
resetSuggections?.();
|
|
840
840
|
const activeTabVal = tab.length > 0 ? tab?.[index].id : undefined;
|
|
841
|
-
|
|
841
|
+
const normalizedSearchValue = searchValue?.trim();
|
|
842
|
+
const tabSearchValue =
|
|
843
|
+
!tabInlineSearch && allDataLoaded && !normalizedSearchValue
|
|
844
|
+
? '*'
|
|
845
|
+
: searchValue;
|
|
846
|
+
handlePickSuggestions(tabSearchValue, 1, false, activeTabVal);
|
|
842
847
|
}
|
|
843
848
|
setActiveTab(index);
|
|
844
849
|
}
|
|
845
|
-
}, [activeTab, clearTabSwitch, handleClearSelected, tabInlineSearch, tab, searchValue, handlePickSuggestions, resetSuggections]);
|
|
850
|
+
}, [activeTab, clearTabSwitch, handleClearSelected, tabInlineSearch, tab, searchValue, handlePickSuggestions, resetSuggections, allDataLoaded]);
|
|
846
851
|
|
|
847
852
|
const getSelectedRowLimit = useCallback(() => {
|
|
848
853
|
let maxHeight = 36;
|
|
@@ -10,6 +10,7 @@ import { buildTree } from './utilities/convertFlatArraytoTreeStructure';
|
|
|
10
10
|
import { deepEqual } from './utilities/deepEqual';
|
|
11
11
|
import { default as Tooltip } from './utilities/expandableTootltip';
|
|
12
12
|
import { Search, Spinner } from './utilities/icons';
|
|
13
|
+
import { isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
13
14
|
|
|
14
15
|
type ValueProps = {
|
|
15
16
|
[key: string]: string;
|
|
@@ -196,14 +197,12 @@ const AutoCompleteWithTreeStructure = forwardRef<
|
|
|
196
197
|
selectedItems: ValueProps[] | string
|
|
197
198
|
): boolean => {
|
|
198
199
|
if (Array.isArray(selectedItems)) {
|
|
199
|
-
return selectedItems.some(
|
|
200
|
-
(selectedItem)
|
|
201
|
-
selectedItem[desc] === item[desc] ||
|
|
202
|
-
selectedItem[descId] === item[descId]
|
|
200
|
+
return selectedItems.some((selectedItem) =>
|
|
201
|
+
isSelectionMatch(selectedItem, item, desc, descId),
|
|
203
202
|
);
|
|
204
|
-
} else {
|
|
205
|
-
return item[desc] === selectedItems;
|
|
206
203
|
}
|
|
204
|
+
|
|
205
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
207
206
|
};
|
|
208
207
|
useEffect(() => {
|
|
209
208
|
if (!deepEqual(selectedItems, propsSeelctedItems))
|
|
@@ -19,7 +19,7 @@ import { deepEqual } from './utilities/deepEqual';
|
|
|
19
19
|
import { default as Tooltip } from './utilities/NewTooltip';
|
|
20
20
|
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
21
21
|
import { AllDropArrow, Search, Spinner } from './utilities/icons';
|
|
22
|
-
import { getKeyValue,
|
|
22
|
+
import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
type ValueProps = {
|
|
@@ -456,17 +456,12 @@ const ExpandableAutoComplete = forwardRef<
|
|
|
456
456
|
selectedItems: ValueProps[] | string
|
|
457
457
|
): boolean => {
|
|
458
458
|
if (Array.isArray(selectedItems)) {
|
|
459
|
-
return selectedItems.some(
|
|
460
|
-
(selectedItem)
|
|
461
|
-
getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name') ||
|
|
462
|
-
getKeyValue(selectedItem, descId, 'id') === getKeyValue(item, descId, 'id')
|
|
463
|
-
);
|
|
464
|
-
} else {
|
|
465
|
-
return (
|
|
466
|
-
getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
|
|
467
|
-
getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
|
|
459
|
+
return selectedItems.some((selectedItem) =>
|
|
460
|
+
isSelectionMatch(selectedItem, item, desc, descId),
|
|
468
461
|
);
|
|
469
462
|
}
|
|
463
|
+
|
|
464
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
470
465
|
};
|
|
471
466
|
|
|
472
467
|
const handleLoadMore = () => {
|
|
@@ -17,7 +17,7 @@ import { deepEqual } from './utilities/deepEqual';
|
|
|
17
17
|
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
18
18
|
import { AllDropArrow, DropArrow, Search, Spinner } from './utilities/icons';
|
|
19
19
|
import { default as Tooltip } from './utilities/NewTooltip';
|
|
20
|
-
import { getKeyValue,
|
|
20
|
+
import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
21
21
|
import {
|
|
22
22
|
clampDropdownToViewportPreferRightAlign,
|
|
23
23
|
MAX_DROPDOWN_WIDTH_WITH_TABS_PX,
|
|
@@ -736,19 +736,11 @@ const DropdownFilterTabs = forwardRef<
|
|
|
736
736
|
}
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
-
return (
|
|
740
|
-
getKeyValue(selectedItem, desc, 'name') ===
|
|
741
|
-
getKeyValue(item, desc, 'name') ||
|
|
742
|
-
getKeyValue(selectedItem, descId, 'id') ===
|
|
743
|
-
getKeyValue(item, descId, 'id')
|
|
744
|
-
);
|
|
739
|
+
return isSelectionMatch(selectedItem, item, desc, descId);
|
|
745
740
|
});
|
|
746
|
-
} else {
|
|
747
|
-
return (
|
|
748
|
-
getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
|
|
749
|
-
getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
|
|
750
|
-
);
|
|
751
741
|
}
|
|
742
|
+
|
|
743
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
752
744
|
}, [tab, currentTabId, desc, descId]);
|
|
753
745
|
|
|
754
746
|
const handleLoadMore = () => {
|
|
@@ -788,22 +780,32 @@ const DropdownFilterTabs = forwardRef<
|
|
|
788
780
|
setSearchValue('');
|
|
789
781
|
setInputValue('');
|
|
790
782
|
handlePickSuggestions('', 1);
|
|
783
|
+
setAllDataLoaded(false);
|
|
791
784
|
} else {
|
|
792
785
|
resetSuggections?.();
|
|
793
786
|
const activeTabVal =
|
|
794
787
|
tab.length > 0 ? tab?.[index].id : undefined;
|
|
795
|
-
|
|
788
|
+
const normalizedSearchValue = searchValue?.trim();
|
|
789
|
+
const tabSearchValue =
|
|
790
|
+
!tabInlineSearch && allDataLoaded && !normalizedSearchValue
|
|
791
|
+
? '*'
|
|
792
|
+
: searchValue;
|
|
793
|
+
handlePickSuggestions(tabSearchValue, 1, false, activeTabVal);
|
|
796
794
|
}
|
|
797
|
-
setAllDataLoaded(false);
|
|
798
795
|
} else {
|
|
799
796
|
resetSuggections?.();
|
|
800
797
|
const activeTabVal = tab.length > 0 ? tab?.[index].id : undefined;
|
|
801
|
-
|
|
798
|
+
const normalizedSearchValue = searchValue?.trim();
|
|
799
|
+
const tabSearchValue =
|
|
800
|
+
!tabInlineSearch && allDataLoaded && !normalizedSearchValue
|
|
801
|
+
? '*'
|
|
802
|
+
: searchValue;
|
|
803
|
+
handlePickSuggestions(tabSearchValue, 1, false, activeTabVal);
|
|
802
804
|
}
|
|
803
805
|
setActiveTab(index);
|
|
804
806
|
setFocusedIndex(0); // Reset focused index when switching tabs
|
|
805
807
|
}
|
|
806
|
-
}, [activeTab, clearTabSwitch, handleClearSelected, tabInlineSearch, tab, searchValue, handlePickSuggestions, resetSuggections]);
|
|
808
|
+
}, [activeTab, clearTabSwitch, handleClearSelected, tabInlineSearch, tab, searchValue, handlePickSuggestions, resetSuggections, allDataLoaded]);
|
|
807
809
|
|
|
808
810
|
const getSelectedRowLimit = useCallback(() => {
|
|
809
811
|
let maxHeight = 36;
|
|
@@ -9,6 +9,7 @@ import { debounce } from './utilities/debounce';
|
|
|
9
9
|
import { deepEqual } from './utilities/deepEqual';
|
|
10
10
|
import { default as Tooltip } from './utilities/expandableTootltip';
|
|
11
11
|
import { filterSuggestions } from './utilities/filterSuggestions';
|
|
12
|
+
import { isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
|
|
12
13
|
import { DropArrow, Search, Spinner } from './utilities/icons';
|
|
13
14
|
|
|
14
15
|
const AutoCompleteWithSelectedList = forwardRef<
|
|
@@ -333,12 +334,12 @@ const AutoCompleteWithSelectedList = forwardRef<
|
|
|
333
334
|
selectedItems: ValueProps[] | string
|
|
334
335
|
): boolean => {
|
|
335
336
|
if (Array.isArray(selectedItems)) {
|
|
336
|
-
return selectedItems.some(
|
|
337
|
-
(selectedItem
|
|
337
|
+
return selectedItems.some((selectedItem) =>
|
|
338
|
+
isSelectionMatch(selectedItem, item, desc, descId),
|
|
338
339
|
);
|
|
339
|
-
} else {
|
|
340
|
-
return item[desc] === selectedItems;
|
|
341
340
|
}
|
|
341
|
+
|
|
342
|
+
return isSelectionMatchValue(item, selectedItems, desc, descId);
|
|
342
343
|
};
|
|
343
344
|
|
|
344
345
|
const handleLoadMore = () => {
|
|
@@ -11,4 +11,38 @@ export function getKeyValue(obj: any, key: any, fallbackKey: string): string {
|
|
|
11
11
|
export function safeToLowerString(val: any): string {
|
|
12
12
|
if (val === undefined || val === null) return '';
|
|
13
13
|
return String(val).toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Match selected item to a suggestion — id when both exist, otherwise desc. */
|
|
17
|
+
export function isSelectionMatch(
|
|
18
|
+
selectedItem: any,
|
|
19
|
+
item: any,
|
|
20
|
+
desc: string,
|
|
21
|
+
descId: string,
|
|
22
|
+
): boolean {
|
|
23
|
+
const selectedId = getKeyValue(selectedItem, descId, 'id');
|
|
24
|
+
const itemId = getKeyValue(item, descId, 'id');
|
|
25
|
+
|
|
26
|
+
if (selectedId && itemId) {
|
|
27
|
+
return selectedId === itemId;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name')
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Match a suggestion to a string value (single-select input). */
|
|
36
|
+
export function isSelectionMatchValue(
|
|
37
|
+
item: any,
|
|
38
|
+
selectedValue: string,
|
|
39
|
+
desc: string,
|
|
40
|
+
descId: string,
|
|
41
|
+
): boolean {
|
|
42
|
+
const normalized = safeToLowerString(selectedValue);
|
|
43
|
+
const itemId = getKeyValue(item, descId, 'id');
|
|
44
|
+
if (itemId && itemId === normalized) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return getKeyValue(item, desc, 'name') === normalized;
|
|
14
48
|
}
|