Skip to content

Commit 69f37d7

Browse files
authored
Merge pull request #7014 from IgniteUI/jcoitino/app-builder-fixes
fix(avatar): Make Avatar.size bindable #7013
2 parents c2eb62b + b52eadb commit 69f37d7

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

projects/igniteui-angular/src/lib/avatar/avatar.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ describe('Avatar', () => {
8181
instance.size = IgxAvatarSize.MEDIUM;
8282
fixture.detectChanges();
8383
expect(instance.size).toEqual(IgxAvatarSize.MEDIUM);
84-
expect(hostEl.classList).not.toContain(classes.medium);
84+
expect(hostEl.classList).toContain(classes.medium);
8585

8686
instance.size = IgxAvatarSize.LARGE;
8787
fixture.detectChanges();
8888
expect(instance.size).toEqual(IgxAvatarSize.LARGE);
89-
expect(hostEl.classList).not.toContain(classes.large);
89+
expect(hostEl.classList).toContain(classes.large);
9090

9191
instance.size = 'nonsense' as any;
9292
fixture.detectChanges();

projects/igniteui-angular/src/lib/avatar/avatar.component.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CommonModule } from '@angular/common';
22
import {
3-
AfterViewInit,
43
Component,
54
ElementRef,
65
HostBinding,
@@ -53,7 +52,7 @@ export enum IgxAvatarType {
5352
selector: 'igx-avatar',
5453
templateUrl: 'avatar.component.html'
5554
})
56-
export class IgxAvatarComponent implements OnInit, AfterViewInit {
55+
export class IgxAvatarComponent implements OnInit {
5756

5857
/**
5958
* This is a reference to the avatar image element in the DOM.
@@ -256,6 +255,22 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
256255
}
257256
}
258257

258+
/** @hidden @internal */
259+
@HostBinding('class.igx-avatar--small')
260+
get _isSmallSize(): boolean {
261+
return this.size === 'small';
262+
}
263+
/** @hidden @internal */
264+
@HostBinding('class.igx-avatar--medium')
265+
get _isMediumSize(): boolean {
266+
return this.size === 'medium';
267+
}
268+
/** @hidden @internal */
269+
@HostBinding('class.igx-avatar--large')
270+
get _isLargeSize(): boolean {
271+
return this.size === 'large';
272+
}
273+
259274
/**
260275
* Returns the type of the avatar.
261276
*
@@ -280,6 +295,22 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
280295
return IgxAvatarType.CUSTOM;
281296
}
282297

298+
/** @hidden @internal */
299+
@HostBinding('class.igx-avatar--image')
300+
get _isImageType(): boolean {
301+
return this.type === IgxAvatarType.IMAGE;
302+
}
303+
/** @hidden @internal */
304+
@HostBinding('class.igx-avatar--icon')
305+
get _isIconType(): boolean {
306+
return this.type === IgxAvatarType.ICON;
307+
}
308+
/** @hidden @internal */
309+
@HostBinding('class.igx-avatar--initials')
310+
get _isInitialsType(): boolean {
311+
return this.type === IgxAvatarType.INITIALS;
312+
}
313+
283314
/**
284315
* Returns the template of the avatar.
285316
*
@@ -306,15 +337,6 @@ export class IgxAvatarComponent implements OnInit, AfterViewInit {
306337
this.roleDescription = this.getRole();
307338
}
308339

309-
/** @hidden @internal */
310-
public ngAfterViewInit() {
311-
if (this.type !== IgxAvatarType.CUSTOM) {
312-
this.elementRef.nativeElement.classList.add(`igx-avatar--${this.type}`);
313-
}
314-
315-
this.elementRef.nativeElement.classList.add(`igx-avatar--${this._size}`);
316-
}
317-
318340
/** @hidden @internal */
319341
private getRole(): string {
320342
switch (this.type) {

0 commit comments

Comments
 (0)