bitwarden-estensione-browser/libs/angular/src/directives/input-verbatim.directive.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-12-16 13:36:21 +01:00
import { Directive, ElementRef, Input, Renderer2 } from "@angular/core";
2018-04-25 23:53:37 +02:00
@Directive({
2021-12-16 13:36:21 +01:00
selector: "[appInputVerbatim]",
2018-04-25 23:53:37 +02:00
})
export class InputVerbatimDirective {
2021-12-16 13:36:21 +01:00
@Input() set appInputVerbatim(condition: boolean | string) {
this.disableComplete = condition === "" || condition === true;
}
2018-04-25 23:53:37 +02:00
2021-12-16 13:36:21 +01:00
private disableComplete: boolean;
2018-04-25 23:53:37 +02:00
2021-12-16 13:36:21 +01:00
constructor(private el: ElementRef, private renderer: Renderer2) {}
2018-04-25 23:53:37 +02:00
2021-12-16 13:36:21 +01:00
ngOnInit() {
if (this.disableComplete && !this.el.nativeElement.hasAttribute("autocomplete")) {
this.renderer.setAttribute(this.el.nativeElement, "autocomplete", "off");
}
if (!this.el.nativeElement.hasAttribute("autocapitalize")) {
this.renderer.setAttribute(this.el.nativeElement, "autocapitalize", "none");
}
if (!this.el.nativeElement.hasAttribute("autocorrect")) {
this.renderer.setAttribute(this.el.nativeElement, "autocorrect", "none");
}
if (!this.el.nativeElement.hasAttribute("spellcheck")) {
this.renderer.setAttribute(this.el.nativeElement, "spellcheck", "false");
}
if (!this.el.nativeElement.hasAttribute("inputmode")) {
this.renderer.setAttribute(this.el.nativeElement, "inputmode", "verbatim");
2018-04-25 23:53:37 +02:00
}
2021-12-16 13:36:21 +01:00
}
2018-04-25 23:53:37 +02:00
}