fix: Descriptions key prop issue (#44278)

* fix: descriptions throw react key prop error in jsx mode

* chore: update test

---------

Co-authored-by: MadCcc <1075746765@qq.com>
This commit is contained in:
红果汁
2023-08-17 21:12:10 +08:00
committed by GitHub
parent 7179dc8d4c
commit 73cfd37b77
2 changed files with 17 additions and 1 deletions

View File

@@ -320,4 +320,20 @@ describe('Descriptions', () => {
const view = nestDesc.querySelector('.ant-descriptions-view');
expect(getComputedStyle(view!).border).toBeFalsy();
});
it('Should Descriptions not throw react key prop error in jsx mode', () => {
render(
<Descriptions title="User Info">
<Descriptions.Item key="1" label="UserName">
Zhou Maomao
</Descriptions.Item>
<Descriptions.Item label="Telephone">1810000000</Descriptions.Item>
</Descriptions>,
);
expect(errorSpy).not.toHaveBeenCalledWith(
expect.stringContaining('`key` is not a prop'),
expect.anything(),
expect.anything(),
);
});
});

View File

@@ -27,7 +27,7 @@ function getFilledItem(
// Convert children into items
const transChildren2Items = (childNodes?: React.ReactNode) =>
toArray(childNodes).map((node) => node?.props);
toArray(childNodes).map((node) => ({ ...node?.props }));
// Calculate the sum of span in a row
function getCalcRows(rowItems: DescriptionsItemType[], mergedColumn: number) {