react-core-ts 2.1.36 → 2.1.38
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 +2 -6
- package/dist/AutoCompleteWithSelectedList.js.map +1 -1
- package/dist/AutoCompleteWithTabFilter.js +2 -6
- 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/ReactAutoComplete.js +18 -12
- package/dist/ReactAutoComplete.js.map +1 -1
- package/dist/dropdownFilterTabs.js +2 -8
- package/dist/dropdownFilterTabs.js.map +1 -1
- package/dist/dummyAutoCompleteWithSelectedList.js +5 -4
- package/dist/dummyAutoCompleteWithSelectedList.js.map +1 -1
- package/dist/styles/styles/components/autocomplete.css +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/package.json +1 -1
- package/src/AutoComplete.tsx +5 -4
- package/src/AutoCompleteWithSelectedList.tsx +5 -10
- package/src/AutoCompleteWithTabFilter.tsx +5 -10
- package/src/AutoCompleteWithTreeStructure.tsx +5 -6
- package/src/ExpandableAutoComplete.tsx +5 -10
- package/src/ReactAutoComplete.tsx +20 -9
- package/src/dropdownFilterTabs.tsx +4 -12
- package/src/dummyAutoCompleteWithSelectedList.tsx +5 -4
- package/src/styles/components/autocomplete.css +1 -1
- package/src/utilities/getKeyValue.ts +34 -0
|
@@ -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
|
}
|