Skip to content

Commit

Permalink
feat(a11y): add title to icons
Browse files Browse the repository at this point in the history
  • Loading branch information
astagi committed Feb 6, 2025
1 parent 9fa14ee commit 82c4bae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<svg [attr.aria-hidden]="isAriaHidden" [attr.aria-label]="labelWaria" [class]="iconClass">
<svg [attr.role]="role" [attr.aria-hidden]="isAriaHidden" [attr.aria-label]="title || labelWaria" [class]="iconClass">
@if (title || labelWaria) {
<title>{{ title || labelWaria }}</title>
}
<use [attr.href]="iconHref" [attr.xlink:href]="iconHref"></use>
</svg>
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export class ItIconComponent {
*/
@Input() svgClass: string | undefined;

/**
* Title of the icon
*/
@Input() title: string | undefined;

/**
* Custom Waria label
*/
@Input() labelWaria: string | undefined;

/**
* Return the icon href
*/
Expand Down Expand Up @@ -71,13 +81,12 @@ export class ItIconComponent {
*/
protected assetBasePath: string;

/**
* Custom Waria label
*/
@Input() labelWaria: string | undefined;

get isAriaHidden(): boolean {
return this.labelWaria == undefined;
return this.labelWaria == undefined && this.title == undefined;
}

get role(): string {
return this.labelWaria == undefined && this.title == undefined ? undefined : 'img';

Check failure on line 89 in projects/design-angular-kit/src/lib/components/utils/icon/icon.component.ts

View workflow job for this annotation

GitHub Actions / run-build-and-tests

Type 'string | undefined' is not assignable to type 'string'.

Check failure on line 89 in projects/design-angular-kit/src/lib/components/utils/icon/icon.component.ts

View workflow job for this annotation

GitHub Actions / run-build-and-tests

Type 'string | undefined' is not assignable to type 'string'.
}

constructor() {
Expand Down

0 comments on commit 82c4bae

Please sign in to comment.