bitwarden-estensione-browser/libs/angular/src/directives/a11y-title.directive.ts

24 lines
636 B
TypeScript
Raw Normal View History

2021-12-16 13:36:21 +01:00
import { Directive, ElementRef, Input, Renderer2 } from "@angular/core";
2019-04-02 04:36:07 +02:00
@Directive({
2021-12-16 13:36:21 +01:00
selector: "[appA11yTitle]",
2019-04-02 04:36:07 +02:00
})
export class A11yTitleDirective {
2021-12-16 13:36:21 +01:00
@Input() set appA11yTitle(title: string) {
this.title = title;
}
2019-04-02 04:36:07 +02:00
2021-12-16 13:36:21 +01:00
private title: string;
2019-04-02 04:36:07 +02:00
2021-12-16 13:36:21 +01:00
constructor(private el: ElementRef, private renderer: Renderer2) {}
2019-04-02 04:36:07 +02:00
2021-12-16 13:36:21 +01:00
ngOnInit() {
if (!this.el.nativeElement.hasAttribute("title")) {
this.renderer.setAttribute(this.el.nativeElement, "title", this.title);
}
if (!this.el.nativeElement.hasAttribute("aria-label")) {
this.renderer.setAttribute(this.el.nativeElement, "aria-label", this.title);
2019-04-02 04:36:07 +02:00
}
2021-12-16 13:36:21 +01:00
}
2019-04-02 04:36:07 +02:00
}