mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 14:04:03 +00:00
undo a11y-title change wip
This commit is contained in:
@@ -1,32 +1,37 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { Directive, ElementRef, input, OnInit } from "@angular/core";
|
||||
import { Directive, ElementRef, Input, OnInit, Renderer2 } from "@angular/core";
|
||||
|
||||
@Directive({
|
||||
selector: "[appA11yTitle]",
|
||||
host: {
|
||||
"[attr.title]": "this.getTitleAttr()",
|
||||
"[attr.aria-label]": "this.getAriaLabelAttr()",
|
||||
},
|
||||
})
|
||||
export class A11yTitleDirective implements OnInit {
|
||||
appA11yTitle = input<string>();
|
||||
@Input() set appA11yTitle(title: string) {
|
||||
this.title = title;
|
||||
this.setAttributes();
|
||||
}
|
||||
|
||||
private title: string;
|
||||
private originalTitle: string | null;
|
||||
private originalAriaLabel: string | null;
|
||||
|
||||
constructor(private el: ElementRef) {}
|
||||
constructor(
|
||||
private el: ElementRef,
|
||||
private renderer: Renderer2,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.originalTitle = this.el.nativeElement.getAttribute("title");
|
||||
this.originalAriaLabel = this.el.nativeElement.getAttribute("aria-label");
|
||||
this.setAttributes();
|
||||
}
|
||||
|
||||
getTitleAttr() {
|
||||
return this.originalTitle ?? this.appA11yTitle();
|
||||
}
|
||||
|
||||
getAriaLabelAttr() {
|
||||
return this.originalAriaLabel ?? this.appA11yTitle();
|
||||
private setAttributes() {
|
||||
if (this.originalTitle === null) {
|
||||
this.renderer.setAttribute(this.el.nativeElement, "title", this.title);
|
||||
}
|
||||
if (this.originalAriaLabel === null) {
|
||||
this.renderer.setAttribute(this.el.nativeElement, "aria-label", this.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user