Skip to content

Commit a7cc961

Browse files
committed
chore: Adjust select convertChildrenToData logic
resolve ant-design/ant-design#22037
1 parent b5b55a1 commit a7cc961

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/utils/legacyUtil.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function convertChildrenToData(
1616
optionOnly: boolean = false,
1717
): OptionsType {
1818
return toArray(nodes)
19-
.map((node: React.ReactElement): OptionData | OptionGroupData | null => {
19+
.map((node: React.ReactElement, index: number): OptionData | OptionGroupData | null => {
2020
if (!React.isValidElement(node) || !node.type) {
2121
return null;
2222
}
@@ -34,7 +34,8 @@ export function convertChildrenToData(
3434
}
3535

3636
return {
37-
key,
37+
key: `__RC_SELECT_GRP__${key === null ? index : key}__`,
38+
label: key,
3839
...restProps,
3940
options: convertChildrenToData(children),
4041
};

tests/utils.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Utils', () => {
2121
expect(convertChildrenToData(node.props.children)).toEqual([
2222
{ key: 'light', value: 'light', children: 'Light' },
2323
{
24-
key: null,
24+
key: '__RC_SELECT_GRP__1__',
2525
label: 'Group',
2626
options: [{ key: null, children: 'Bamboo', value: 'bamboo' }],
2727
},

0 commit comments

Comments
 (0)