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.
@@ -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) => selectedItem[desc] === item[desc]
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 = () => {
@@ -156,7 +156,7 @@ body * {
156
156
  }
157
157
 
158
158
  .qbs-autocomplete-notfound {
159
- cursor: pointer;
159
+ cursor: default;
160
160
  padding: 6px 8px;
161
161
  border-radius: 6px;
162
162
  font-size: 12px;
@@ -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
  }