diff --git a/projects/ppwcode/ng-forms/src/lib/directives/disable-password-fill.directive.ts b/projects/ppwcode/ng-forms/src/lib/directives/disable-password-fill.directive.ts new file mode 100644 index 00000000..ab339e11 --- /dev/null +++ b/projects/ppwcode/ng-forms/src/lib/directives/disable-password-fill.directive.ts @@ -0,0 +1,32 @@ +import { Directive, ElementRef, inject, OnInit, Renderer2 } from '@angular/core' + +/** + * Directive to disable automatic password fill suggestions of the most popular password-managers. + * These suggestions are present when the browser extension of the respective password-manager is installed. + * The following password-managers are supported: + * - LastPass: 'data-lpignore' + * - 1Password: 'data-1p-ignore' + * - ProtonPass: 'data-protonpass-ignore' + * - Dashlane: 'data-form-type' + * - BitWarden: 'data-bwignore' + */ +@Directive({ + selector: '[ppwDisablePasswordFill]' +}) +export class disablePasswordFillDirective implements OnInit { + private readonly el = inject(ElementRef) + private readonly renderer = inject(Renderer2) + + ngOnInit() { + this.disablePasswordFill() + } + + disablePasswordFill() { + this.renderer.setAttribute(this.el.nativeElement, 'data-lpignore', 'true') + this.renderer.setAttribute(this.el.nativeElement, 'data-1p-ignore', 'true') + this.renderer.setAttribute(this.el.nativeElement, 'data-protonpass-ignore', 'true') + this.renderer.setAttribute(this.el.nativeElement, 'data-form-type', 'other') + this.renderer.setAttribute(this.el.nativeElement, 'data-bwignore', 'true') + this.el.nativeElement.removeAttribute('ppwDisablePasswordFill') + } +} diff --git a/projects/ppwcode/ng-forms/src/public-api.ts b/projects/ppwcode/ng-forms/src/public-api.ts index 86261728..12160c63 100644 --- a/projects/ppwcode/ng-forms/src/public-api.ts +++ b/projects/ppwcode/ng-forms/src/public-api.ts @@ -2,6 +2,7 @@ * Public API Surface of ng-forms */ +export * from './lib/directives/disable-password-fill.directive' export * from './lib/validators/validation.service' export * from './lib/generators' export * from './lib/controls-of'