Skip to content

Commit 78c870a

Browse files
committed
fix(avatar): add alt prop for img alternate text
1 parent 8efb887 commit 78c870a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

projects/coreui-angular/src/lib/avatar/avatar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<ng-template #defaultImageTemplate>
99
@if (!!src) {
10-
<img [src]="src" class="avatar-img" />
10+
<img [ngSrc]="src" fill class="avatar-img" alt="{{alt}}" />
1111
} @else {
1212
<ng-content />
1313
}

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, HostBinding, Input } from '@angular/core';
2-
import { NgClass, NgTemplateOutlet } from '@angular/common';
2+
import { NgClass, NgOptimizedImage, NgTemplateOutlet } from '@angular/common';
33

44
import { Colors, Shapes, Sizes, TextColors } from '../coreui.types';
55
import { TextColorDirective } from '../utilities';
@@ -8,35 +8,45 @@ import { TextColorDirective } from '../utilities';
88
selector: 'c-avatar',
99
templateUrl: './avatar.component.html',
1010
standalone: true,
11-
imports: [
12-
NgTemplateOutlet,
13-
NgClass
14-
],
15-
hostDirectives: [{
16-
directive: TextColorDirective, inputs: ['cTextColor: textColor']
17-
}]
11+
imports: [NgTemplateOutlet, NgClass, NgOptimizedImage],
12+
hostDirectives: [
13+
{
14+
directive: TextColorDirective,
15+
inputs: ['cTextColor: textColor']
16+
}
17+
]
1818
})
1919
export class AvatarComponent {
2020
/**
2121
* Sets the background color context of the component to one of CoreUI’s themed colors.
2222
* @type Colors
2323
*/
2424
@Input() color?: Colors;
25+
2526
/**
2627
* Select the shape of the component.
2728
* @type Shapes
2829
*/
2930
@Input() shape?: Shapes;
31+
3032
/**
3133
* Size the component small, large, or extra large.
3234
* @default 'md'
3335
*/
3436
@Input() size?: Omit<Sizes, 'xxl'> = 'md';
37+
38+
/**
39+
* The alt attribute for the img element alternate text.
40+
* @type string
41+
*/
42+
@Input() alt: string = '';
43+
3544
/**
3645
* The src attribute for the img element.
3746
* @type string
3847
*/
3948
@Input() src?: string;
49+
4050
/**
4151
* Sets the color context of the status indicator to one of CoreUI’s themed colors.
4252
* @type Colors
@@ -50,8 +60,6 @@ export class AvatarComponent {
5060
*/
5161
@Input() textColor?: TextColors;
5262

53-
constructor() { }
54-
5563
get statusClass(): any {
5664
return {
5765
'avatar-status': true,

0 commit comments

Comments
 (0)