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(module:avatar): fix avatar text resize when used in list #2074

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 10 additions & 1 deletion components/avatar/nz-avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ElementRef,
Input,
OnChanges,
OnInit,
SimpleChanges,
ViewChild
} from '@angular/core';
Expand All @@ -21,7 +22,7 @@ export type NzAvatarSize = 'small' | 'large' | 'default';
preserveWhitespaces: false,
changeDetection : ChangeDetectionStrategy.OnPush
})
export class NzAvatarComponent implements OnChanges {
export class NzAvatarComponent implements OnChanges, OnInit {
private el: HTMLElement;
private prefixCls = 'ant-avatar';
private sizeMap = { large: 'lg', small: 'sm' };
Expand Down Expand Up @@ -90,6 +91,8 @@ export class NzAvatarComponent implements OnChanges {

private notifyCalc(): this {
// If use ngAfterViewChecked, always demands more computations, so......
// Should set a minimum time waiting for DOM to be rendered, otherwise string size would not change when avatar is
// used in list.
setTimeout(() => {
this.calcStringSize();
});
Expand All @@ -107,4 +110,10 @@ export class NzAvatarComponent implements OnChanges {

this.setClass().notifyCalc();
}

ngOnInit(): void {
setTimeout(() => {
this.notifyCalc();
}, 16);
}
}