fix: Avatar.Group key lost (#26098)

* fix: avatargroup key lost

* Update components/avatar/group.tsx
This commit is contained in:
xrkffgg 2020-08-09 18:54:53 +08:00 committed by GitHub
parent e7e83fb357
commit d5ca5880ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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';
@ -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) {
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}