From 85277aa2f80b533837e76fbb7c81769f855f23cc Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Tue, 25 Apr 2023 10:08:58 -0400 Subject: [PATCH] AC-1267 - (1) Mark master pass (MP) field as untouched on any load of MP section of login page post email validation in order to prevent validation errors of "input required" from being shown prematurely before the user has entered anything or lost focus on the input when the user hits enter on the login screen after entering an email (2) Improve the logic around the MP autofocus to match existing code patterns to ensure there are no possible scenarios in which the MP would not be autofocused. (#5246) --- .../angular/src/auth/components/login.component.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/angular/src/auth/components/login.component.ts b/libs/angular/src/auth/components/login.component.ts index 10025e12f75..ad7b6e630b1 100644 --- a/libs/angular/src/auth/components/login.component.ts +++ b/libs/angular/src/auth/components/login.component.ts @@ -246,11 +246,19 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit // so that autofill can work properly this.formGroup.controls.masterPassword.reset(); } else { + // Mark MP as untouched so that, when users enter email and hit enter, + // the MP field doesn't load with validation errors + this.formGroup.controls.masterPassword.markAsUntouched(); + // When email is validated, focus on master password after // waiting for input to be rendered - this.ngZone.onStable - .pipe(take(1)) - .subscribe(() => this.masterPasswordInput?.nativeElement?.focus()); + if (this.ngZone.isStable) { + this.masterPasswordInput?.nativeElement?.focus(); + } else { + this.ngZone.onStable.pipe(take(1)).subscribe(() => { + this.masterPasswordInput?.nativeElement?.focus(); + }); + } } }