Skip to content

Commit

Permalink
fix: Description children missing key
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Nov 9, 2023
1 parent e5a213d commit 22c9eaa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions components/descriptions/__tests__/hooks.test.tsx
@@ -0,0 +1,26 @@
import React from 'react';

import Descriptions from '..';
import { render } from '../../../tests/utils';
import useBreakpoint from '../../grid/hooks/useBreakpoint';
import useItems from '../hooks/useItems';

describe('Descriptions.Hooks', () => {
it('Should Descriptions not throw react key prop error in jsx mode', () => {
const Demo = () => {
const screens = useBreakpoint();
const items = useItems(
screens,
undefined,
<Descriptions.Item key="bamboo" label="UserName">
Bamboo
</Descriptions.Item>,
);

return <p>{(items[0] as any).key}</p>;
};

const { container } = render(<Demo />);
expect(container.querySelector('p')?.textContent).toBe('bamboo');
});
});
2 changes: 1 addition & 1 deletion components/descriptions/hooks/useItems.ts
Expand Up @@ -6,7 +6,7 @@ import { matchScreen, type ScreenMap } from '../../_util/responsiveObserver';

// Convert children into items
const transChildren2Items = (childNodes?: React.ReactNode) =>
toArray(childNodes).map((node) => ({ ...node?.props }));
toArray(childNodes).map((node) => ({ ...node?.props, key: node.key }));

export default function useItems(
screens: ScreenMap,
Expand Down

0 comments on commit 22c9eaa

Please sign in to comment.