Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "fix: Remove AvatarGroup and AvatarGroupItem warnings since they break the composition pattern and fixed issue when the children in AvatarGroup is a Fragment containing the AvatarGroupItems.",
"packageName": "@fluentui/react-avatar",
"email": "esteban.230@hotmail.com",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { AvatarGroupItem } from '../AvatarGroupItem/AvatarGroupItem';
import { getNativeElementProps, resolveShorthand } from '@fluentui/react-utilities';
import { MoreHorizontalRegular } from '@fluentui/react-icons';
import { PopoverSurface } from '@fluentui/react-popover';
Expand All @@ -17,15 +16,9 @@ import type { AvatarGroupProps, AvatarGroupState } from './AvatarGroup.types';
export const useAvatarGroup_unstable = (props: AvatarGroupProps, ref: React.Ref<HTMLElement>): AvatarGroupState => {
const { children, layout = 'spread', maxAvatars = 5, size = defaultAvatarGroupSize } = props;
const { overflowIndicator = size < 24 ? 'icon' : 'count' } = props;
const childrenArray = React.Children.toArray(children);

if (
process.env.NODE_ENV !== 'production' &&
childrenArray.find(child => React.isValidElement(child) && child.type !== AvatarGroupItem)
) {
// eslint-disable-next-line no-console
console.warn("AvatarGroup's children must be of type AvatarGroupItems.");
}
const childrenArray = React.Children.toArray(
React.isValidElement(children) && children.type === React.Fragment ? children.props.children : children,
);
Comment on lines +19 to +21

@layershifter layershifter Jun 23, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't want to make it worse, but the tree could be nested...

<AvatarGroup>
  <>
    <AvatarGroupItem />
    <AvatarGroupItem />
    <>
      <AvatarGroupItem />
      <AvatarGroupItem />
      <AvatarGroupItem />
    </>
  </>
</AvatarGroup>

TBH Not sure if it worth fixing currently, I would rather fix it properly 🐱


let rootChildren = childrenArray;
let overflowChildren;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export const useAvatarGroupItem_unstable = (
const groupIsOverflow = useContextSelector(AvatarGroupContext, ctx => ctx.isOverflow);
const layout = useContextSelector(AvatarGroupContext, ctx => ctx.layout);
const groupSize = useContextSelector(AvatarGroupContext, ctx => ctx.size);
const hasAvatarGroupContext = useHasParentContext(AvatarGroupContext);
// Since the primary slot is not an intrinsic element, getPartitionedNativeProps cannot be used here.
const { style, className, ...avatarSlotProps } = props;
const size = groupSize ?? defaultAvatarGroupSize;
const hasAvatarGroupContext = useHasParentContext(AvatarGroupContext);

if (process.env.NODE_ENV !== 'production' && !hasAvatarGroupContext) {
Comment thread
sopranopillow marked this conversation as resolved.
// eslint-disable-next-line no-console
Expand Down