mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
fix: Avatar.Group key lost (#26098)
* fix: avatargroup key lost * Update components/avatar/group.tsx
This commit is contained in:
parent
e7e83fb357
commit
d5ca5880ef
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user