Skip to content

Commit

Permalink
fix: Descriptions key prop issue (#44278)
Browse files Browse the repository at this point in the history
* fix: descriptions throw react key prop error in jsx mode

* chore: update test

---------

Co-authored-by: MadCcc <1075746765@qq.com>
  • Loading branch information
RedJue and MadCcc committed Aug 17, 2023
1 parent 7179dc8 commit 73cfd37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions components/descriptions/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
});
});
2 changes: 1 addition & 1 deletion components/descriptions/hooks/useRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

1 comment on commit 73cfd37

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.