Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Description children missing key #45757

Merged
merged 1 commit into from Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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