Skip to content

Commit

Permalink
Merge pull request #162 from czeckd/bugfix/ng18-aria
Browse files Browse the repository at this point in the history
Task #161 - Fix aria-label
  • Loading branch information
czeckd committed Sep 10, 2024
2 parents 49b2f68 + ac82e8e commit 838111a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "svg-icon",
"description": "Angular 18 component and service for inlining SVGs allowing them to be easily styled with CSS.",
"version": "18.0.1",
"version": "18.0.2",
"repository": {
"type": "git",
"url": "https://github.com/czeckd/angular-svg-icon.git"
Expand All @@ -16,7 +16,6 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --configuration production",
"dist": "ng build --configuration production angular-svg-icon && cp README.md LICENSE ./dist/angular-svg-icon/",
"test": "ng test --source-map=false angular-svg-icon",
"coverage": "ng test --code-coverage angular-svg-icon",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-svg-icon/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-svg-icon",
"description": "Angular 18 component and service for inlining SVGs allowing them to be easily styled with CSS.",
"version": "18.0.1",
"version": "18.0.2",
"repository": {
"type": "git",
"url": "https://github.com/czeckd/angular-svg-icon.git"
Expand Down
29 changes: 15 additions & 14 deletions projects/angular-svg-icon/src/lib/svg-icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,19 @@ export class SvgIconComponent implements OnDestroy {
}

private doAria(label: string) {
const svg = this.element.nativeElement.firstChild;
// If there is not a svgAriaLabel and the SVG has an arial-label, then do not override
// the SVG's aria-label.
if (svg && !(label === undefined && svg.hasAttribute('aria-label'))) {
if (label === '') {
this.renderer.setAttribute(svg, 'aria-hidden', 'true');
this.renderer.removeAttribute(svg, 'aria-label');
} else {
this.renderer.removeAttribute(svg, 'aria-hidden');
this.renderer.setAttribute(svg, 'aria-label', label);
}
}
}

if (label !== undefined) {
const svg = this.element.nativeElement.firstChild;
// If there is not a svgAriaLabel and the SVG has an arial-label, then do not override
// the SVG's aria-label.
if (svg && !svg.hasAttribute('aria-label')) {
if (label === '') {
this.renderer.setAttribute(svg, 'aria-hidden', 'true');
this.renderer.removeAttribute(svg, 'aria-label');
} else {
this.renderer.removeAttribute(svg, 'aria-hidden');
this.renderer.setAttribute(svg, 'aria-label', label);
}
}
}
}
}

0 comments on commit 838111a

Please sign in to comment.