From 4033488bcde6d5c81f69262050af2a30a0fb0770 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Sat, 8 Aug 2020 21:40:30 +0800 Subject: [PATCH 1/2] fix: avatargroup key lost --- components/avatar/group.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/avatar/group.tsx b/components/avatar/group.tsx index d19d8d1dd6fd..eaf613851cad 100644 --- a/components/avatar/group.tsx +++ b/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'; @@ -28,13 +29,19 @@ const Group: React.FC = 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( = props => { } return (
- {children} + {childrenWithProps}
); }; From 32a57b4e022bcdcc7a8a0de452f613e8e2075208 Mon Sep 17 00:00:00 2001 From: xrkffgg Date: Sun, 9 Aug 2020 13:37:54 +0800 Subject: [PATCH 2/2] Update components/avatar/group.tsx --- components/avatar/group.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/avatar/group.tsx b/components/avatar/group.tsx index eaf613851cad..9694d853aa16 100644 --- a/components/avatar/group.tsx +++ b/components/avatar/group.tsx @@ -58,7 +58,7 @@ const Group: React.FC = props => { } return (
- {childrenWithProps} + {children}
); };