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: Avatar.Group key lost #26098

Merged
merged 2 commits into from Aug 9, 2020
Merged
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
9 changes: 8 additions & 1 deletion components/avatar/group.tsx
@@ -1,6 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import toArray from 'rc-util/lib/Children/toArray';
import { cloneElement } from '../_util/reactNode';
import { ConfigContext } from '../config-provider';
import Avatar from './avatar';
import Popover from '../popover';
Expand Down Expand Up @@ -28,13 +29,19 @@ const Group: React.FC<GroupProps> = props => {
);

const { children, maxPopoverPlacement = 'top' } = props;
const childrenWithProps = toArray(children);
const childrenWithProps = toArray(children).map((child, index) => {
return cloneElement(child, {
key: `avatar-key-${index}`,
});
});

const numOfChildren = childrenWithProps.length;
if (maxCount && maxCount < numOfChildren) {
Copy link
Member

Choose a reason for hiding this comment

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

没进 if 的时候直接用 children 就可以了吧?没必要 toArray 一下。

const childrenShow = childrenWithProps.slice(0, maxCount);
const childrenHidden = childrenWithProps.slice(maxCount, numOfChildren);
childrenShow.push(
<Popover
key="avatar-popover-key"
content={childrenHidden}
trigger="hover"
placement={maxPopoverPlacement}
Expand Down