Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): address Avatar Group issues #12530

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
22be6e6
fix(core): avatar group bugs
khotcholava Sep 25, 2024
4a87b4d
fix(core): avatar group bugs
khotcholava Sep 26, 2024
b39b871
fix(core): avatar group
khotcholava Sep 30, 2024
aedf05e
Merge branch 'main' into fix(core)-avatar-group-bugs
khotcholava Oct 10, 2024
b32ae7e
fix(core): Resolve focus retention & rendering issues, add feature en…
khotcholava Oct 10, 2024
fe4920e
fix(core): Resolve focus retention & rendering issues, add feature en…
khotcholava Oct 10, 2024
0ead287
Make avatar group circle
khotcholava Oct 11, 2024
1f11a17
Make avatar group circle
khotcholava Oct 11, 2024
da922ad
Implemented first selection of popover avatar items
khotcholava Oct 14, 2024
f587f50
fix(core): avatar group
khotcholava Oct 15, 2024
4373cde
fix(core): Resolve focus retention & rendering issues, add feature en…
khotcholava Oct 25, 2024
b6af950
Merge branch 'main' into fix(core)-avatar-group-bugs
khotcholava Oct 29, 2024
3768cb9
Merge branch 'main' into fix(core)-avatar-group-bugs
khotcholavaSuzy Nov 7, 2024
f79c75e
fix(core): avatar groups
khotcholavaSuzy Nov 7, 2024
3405d09
fix(core): avatar groups
khotcholavaSuzy Nov 7, 2024
3a61be4
fix(core): avatar groups
khotcholavaSuzy Nov 7, 2024
8b1e6de
fix(core): avatar groups
khotcholavaSuzy Nov 8, 2024
8251f84
Merge branch 'main' into fix(core)-avatar-group-bugs
mikerodonnell89 Nov 12, 2024
d20946e
fix(core): avatar groups
khotcholavaSuzy Nov 13, 2024
cb1c93d
fix(core): avatar group fixed first item focus
khotcholavaSuzy Nov 27, 2024
d353a20
fix(core): avatar group fixed first item focus
khotcholavaSuzy Nov 27, 2024
18fc966
fix e2e test
khotcholava Dec 2, 2024
827ef21
Fixed popover focus
khotcholava Dec 2, 2024
d4bd252
fix e2e test
khotcholava Dec 2, 2024
bc16f40
Merge remote-tracking branch 'origin/fix(core)-avatar-group-bugs' int…
khotcholava Dec 2, 2024
728a86b
fixed time picker tests
khotcholava Dec 3, 2024
87c2469
fixed time picker tests
khotcholava Dec 3, 2024
fada1bc
Merge branch 'main' into fix(core)-avatar-group-bugs
khotcholava Dec 20, 2024
3420564
Merge branch 'main' into fix(core)-avatar-group-bugs
mikerodonnell89 Jan 2, 2025
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
19 changes: 16 additions & 3 deletions libs/core/avatar-group/avatar-group.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(resized)="_detectChanges()"
>
@for (item of _avatars; track item) {
<fd-popover [noArrow]="false" [focusAutoCapture]="true">
<fd-popover [placement]="popoverPlacement" [noArrow]="false" [focusAutoCapture]="true">
<fd-popover-control tabindex="-1" (click)="outletItem.element.focus()">
<ng-template
#outletItem="fdAvatarGroupItemPortal"
Expand All @@ -33,6 +33,7 @@
</fd-popover>
}
<fd-popover
[placement]="popoverPlacement"
[noArrow]="false"
[focusAutoCapture]="true"
*fdAvatarGroupInternalOverflowButton="avatarGroupHostComponent._hiddenItems(); let hiddenItems"
Expand All @@ -52,9 +53,17 @@
</fd-popover>
</fd-avatar-group-host>
} @else {
<fd-popover [noArrow]="false" [focusAutoCapture]="true" fdkResizeObserver (resized)="_detectChanges()">
<fd-popover
[placement]="popoverPlacement"
[noArrow]="false"
[focusAutoCapture]="true"
fdkResizeObserver
(resized)="_detectChanges()"
(isOpenChange)="handlePopoverOpen($event)"
>
<fd-popover-control>
<fd-avatar-group-host
[maxVisibleItems]="maxVisibleItems"
#avatarGroupHostComponent
[type]="type"
[size]="size"
Expand Down Expand Up @@ -108,6 +117,10 @@
[ngTemplateOutletContext]="{ hiddenItems: hiddenItems }"
/>
} @else {
<fd-default-avatar-group-overflow-body [avatars]="hiddenItems" [overflowPopoverTitle]="overflowPopoverTitle" />
<fd-default-avatar-group-overflow-body
(back)="handleBack()"
[avatars]="hiddenItems"
[overflowPopoverTitle]="overflowPopoverTitle"
/>
}
</ng-template>
32 changes: 32 additions & 0 deletions libs/core/avatar-group/avatar-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ContentChildren,
Input,
QueryList,
ViewChild,
ViewChildren,
ViewEncapsulation,
computed,
Expand All @@ -18,10 +19,12 @@ import {
DynamicPortalComponent,
FocusableItemDirective,
FocusableListDirective,
Nullable,
ResizeObserverDirective,
RtlService
} from '@fundamental-ngx/cdk/utils';
import { PopoverModule } from '@fundamental-ngx/core/popover';
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 @@ -88,6 +91,10 @@ export class AvatarGroupComponent implements AvatarGroupHostConfig {
@Input()
size: AvatarGroupHostConfig['size'] = 'l';

/** Popover placement */
@Input()
popoverPlacement: Placement | null = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

use Nullable type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PopoverPlacement type is Placement | null. It's not Nullable. If I change it I'm afraid it will broke already existing functionality


/**
* The title which is displayed when user opens the overflow popover.
* This takes effect only when default overflow popover body is used,
Expand All @@ -96,10 +103,20 @@ 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>;

/** @hidden */
@ViewChild(DefaultAvatarGroupOverflowBodyComponent)
defaultAvatarGroupOverflowBody: DefaultAvatarGroupOverflowBodyComponent;

/** @hidden */
@ContentChildren(AvatarGroupItemDirective)
_avatars: QueryList<AvatarGroupItemDirective>;
Expand All @@ -121,8 +138,23 @@ export class AvatarGroupComponent implements AvatarGroupHostConfig {
/** @hidden */
private readonly _rtlService = inject(RtlService, { optional: true });

private opened = false;

/** @hidden */
_detectChanges(): void {
this._cdr.detectChanges();
}

/** @hidden */
handlePopoverOpen(isOpen: boolean): void {
this.opened = isOpen;
if (isOpen) {
this.defaultAvatarGroupOverflowBody._avatarGroupItemPortals.first.setTabbable(true);
}
}

/** @hidden */
handleBack(): void {
this.handlePopoverOpen(this.opened);
}
}
14 changes: 13 additions & 1 deletion libs/core/avatar-group/components/avatar-group-host.component.ts
Copy link
Contributor

Choose a reason for hiding this comment

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

add or update relevant unit tests for maxVisibleItems

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is not e2e test for avatar group host

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
Expand Up @@ -2,7 +2,6 @@ import {
ChangeDetectionStrategy,
Component,
forwardRef,
HostBinding,
inject,
Input,
OnChanges,
Expand All @@ -29,7 +28,8 @@ import { AVATAR_GROUP_HOST_CONFIG } from '../tokens';
selector: 'fd-avatar-group-overflow-button',
template: ` <ng-content></ng-content>`,
host: {
role: 'button'
role: 'button',
class: 'fd-avatar--circle'
},
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
Expand All @@ -51,13 +51,6 @@ export class AvatarGroupOverflowButtonComponent
@Input()
size: Size = 'l';

/**
* Whether the overflow button should be displayed as a circle.
*/
@Input()
@HostBinding('class.fd-avatar--circle')
circle = false;

/**
* A number from 1 to 10 representing the background color of the Avatar.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnDestroy,
Output,
QueryList,
Renderer2,
ViewChildren,
Expand Down Expand Up @@ -54,6 +56,10 @@ export class DefaultAvatarGroupOverflowBodyComponent implements AfterViewInit, O
@Input()
overflowPopoverTitle: string;

/** @hidden */
@Output()
back = new EventEmitter<void>();

/** @hidden */
@ViewChildren(AvatarGroupItemRendererDirective)
_avatarGroupItemPortals: QueryList<AvatarGroupItemRendererDirective>;
Expand Down Expand Up @@ -122,5 +128,6 @@ export class DefaultAvatarGroupOverflowBodyComponent implements AfterViewInit, O
_openOverflowMain(): void {
this._overflowPopoverStage = 'main';
this._changeDetectorRef.detectChanges();
this.back.emit();
}
}
Loading