Skip to content

Commit 205ad5a

Browse files
authored
fix(Dropdown): set index correctly (#3138)
1 parent ede7df5 commit 205ad5a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/core/src/components/BaseListItem/BaseListItem.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export type BaseListItemData<Item = Record<string, unknown>> = Item & {
8383
* The color of the chip when displayed in multi-select mode.
8484
*/
8585
chipColor?: ChipsProps["color"];
86+
/**
87+
* The index of the item in the list.
88+
*/
89+
index?: number;
8690
};
8791

8892
export type SideElement =

packages/core/src/components/next/Dropdown/utils/dropdownUtils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export function normalizeOptions<Item extends BaseListItemData>(
2525
}
2626
return matchesFilter;
2727
})
28-
.map(item => ({ ...item, index: indexCounter++ }));
28+
.map(item => {
29+
item.index = indexCounter++;
30+
return item;
31+
});
2932

3033
return filteredGroupOptions.length > 0 ? [{ ...group, options: filteredGroupOptions }] : [];
3134
})
@@ -40,7 +43,10 @@ export function normalizeOptions<Item extends BaseListItemData>(
4043
}
4144
return matchesFilter;
4245
})
43-
.map(item => ({ ...item, index: indexCounter++ }))
46+
.map(item => {
47+
item.index = indexCounter++;
48+
return item;
49+
})
4450
}
4551
];
4652
}

0 commit comments

Comments
 (0)