Skip to content

Commit 82c4bae

Browse files
committed
feat(a11y): add title to icons
1 parent 9fa14ee commit 82c4bae

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
<svg [attr.aria-hidden]="isAriaHidden" [attr.aria-label]="labelWaria" [class]="iconClass">
1+
<svg [attr.role]="role" [attr.aria-hidden]="isAriaHidden" [attr.aria-label]="title || labelWaria" [class]="iconClass">
2+
@if (title || labelWaria) {
3+
<title>{{ title || labelWaria }}</title>
4+
}
25
<use [attr.href]="iconHref" [attr.xlink:href]="iconHref"></use>
36
</svg>

projects/design-angular-kit/src/lib/components/utils/icon/icon.component.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ export class ItIconComponent {
3838
*/
3939
@Input() svgClass: string | undefined;
4040

41+
/**
42+
* Title of the icon
43+
*/
44+
@Input() title: string | undefined;
45+
46+
/**
47+
* Custom Waria label
48+
*/
49+
@Input() labelWaria: string | undefined;
50+
4151
/**
4252
* Return the icon href
4353
*/
@@ -71,13 +81,12 @@ export class ItIconComponent {
7181
*/
7282
protected assetBasePath: string;
7383

74-
/**
75-
* Custom Waria label
76-
*/
77-
@Input() labelWaria: string | undefined;
78-
7984
get isAriaHidden(): boolean {
80-
return this.labelWaria == undefined;
85+
return this.labelWaria == undefined && this.title == undefined;
86+
}
87+
88+
get role(): string {
89+
return this.labelWaria == undefined && this.title == undefined ? undefined : 'img';
8190
}
8291

8392
constructor() {

0 commit comments

Comments
 (0)