Skip to content
Merged
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": "prerelease",
"comment": "chore: Added warning for AvatarGroup to check if children are of type AvatarGroupItem and for AvatarGroupItem to check if it's being used inside an AvatarGroup.",
"packageName": "@fluentui/react-avatar",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 @@ -18,6 +19,14 @@ export const useAvatarGroup_unstable = (props: AvatarGroupProps, ref: React.Ref<
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.");
}

let rootChildren = childrenArray;
let overflowChildren;
let overflowButtonChildren;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Avatar } from '../Avatar/Avatar';
import { AvatarGroupContext } from '../../contexts/AvatarGroupContext';
import { defaultAvatarGroupSize } from '../AvatarGroup/useAvatarGroup';
import { resolveShorthand } from '@fluentui/react-utilities';
import { useContextSelector } from '@fluentui/react-context-selector';
import { useContextSelector, useHasParentContext } from '@fluentui/react-context-selector';
import type { AvatarGroupItemProps, AvatarGroupItemState } from './AvatarGroupItem.types';

/**
Expand All @@ -26,6 +26,12 @@ export const useAvatarGroupItem_unstable = (
// 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) {
// eslint-disable-next-line no-console
console.warn('AvatarGroupItem must only be used inside an AvatarGroup component.');
}

return {
nonOverflowAvatarsCount: nonOverflowAvatarsCount ?? 1,
Expand Down