Skip to content

Commit

Permalink
fix(core): avatar group bugs
Browse files Browse the repository at this point in the history
closes (#12369)[#12369]

## Description
- Add maxVisibleItems input to limit the number of visible avatars in AvatarGroupHostComponent, retaining default behavior when unset
  • Loading branch information
khotcholava committed Sep 26, 2024
1 parent 22be6e6 commit 4a87b4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions libs/core/avatar-group/avatar-group.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<ng-content></ng-content>
<pre>{{_avatars.length}}</pre>
@if (type === 'individual') {
<fd-avatar-group-host
#avatarGroupHostComponent
Expand Down Expand Up @@ -58,6 +59,7 @@
<fd-popover [placement]="popoverPlacement" [noArrow]="false" [focusAutoCapture]="true" fdkResizeObserver (resized)="_detectChanges()">
<fd-popover-control>
<fd-avatar-group-host
[maxVisibleItems]="maxVisibleItems"
#avatarGroupHostComponent
[type]="type"
[size]="size"
Expand Down
11 changes: 9 additions & 2 deletions libs/core/avatar-group/avatar-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
import {
DynamicPortalComponent,
FocusableItemDirective,
FocusableListDirective,
FocusableListDirective, Nullable,
ResizeObserverDirective,
RtlService
} from '@fundamental-ngx/cdk/utils';
import { PopoverModule } from '@fundamental-ngx/core/popover';
import { Placement } from '../shared';
import { Placement } from '@fundamental-ngx/core/shared';
import { AvatarGroupHostComponent } from './components/avatar-group-host.component';
import { AvatarGroupOverflowButtonComponent } from './components/avatar-group-overflow-button.component';
import { DefaultAvatarGroupOverflowBodyComponent } from './components/default-avatar-group-overflow-body/default-avatar-group-overflow-body.component';
Expand Down Expand Up @@ -105,6 +105,13 @@ export class AvatarGroupComponent implements AvatarGroupHostConfig {
@Input()
overflowPopoverTitle: string;

/**
* The maximum number of visible avatar items.
**/
@Input()
maxVisibleItems: Nullable<number> = null;


/** @hidden */
@ViewChildren(AvatarGroupItemRendererDirective)
_avatarRenderers: QueryList<AvatarGroupItemRendererDirective>;
Expand Down
14 changes: 13 additions & 1 deletion libs/core/avatar-group/components/avatar-group-host.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export class AvatarGroupHostComponent
@Input()
items: QueryList<AvatarGroupItemDirective>;

/**
* The maximum number of visible avatar items.
**/
@Input()
maxVisibleItems: Nullable<number> = null;

/**
* @hidden
* The portals to be rendered in the avatar group.
Expand Down Expand Up @@ -166,12 +172,18 @@ export class AvatarGroupHostComponent
continue;
}
accWidth += item.width;
if (accWidth <= containerWidth) {
if (accWidth <= containerWidth && (!this.maxVisibleItems || visibleItems.length < this.maxVisibleItems)) {
visibleItems.push(item);
} else if (!item.forceVisibility) {
hiddenItems.push(item);
}
}

// Ensure we don't exceed the maxVisibleItems limit
if (this.maxVisibleItems && visibleItems.length > this.maxVisibleItems) {
hiddenItems.unshift(...visibleItems.splice(this.maxVisibleItems));
}

/* take last item from the visibleItems which is not forced to be visible and push it to the hiddenItems
* This is done to free up the space for the overflow button
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<fd-avatar-group [circle]="true" [popoverPlacement]="'bottom'" [size]="'m'" type="group" overflowPopoverTitle="Team members">
<fd-avatar-group [maxVisibleItems]="3" [circle]="true" [popoverPlacement]="'bottom'" [size]="'m'" type="group" overflowPopoverTitle="Team members">
@for (person of people; track person) { @if (!person.imageUrl &&
!person.glyph) {
<fd-avatar
Expand Down

0 comments on commit 4a87b4d

Please sign in to comment.