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

Task #161 - Fix aria-label #162

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
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
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);
}
}
}
}
}