1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-03-11 13:30:39 +01:00

PM-1354 - Fix master password not auto focused on web login flow (#5139)

This commit is contained in:
Jared Snider 2023-04-04 16:39:49 -04:00 committed by GitHub
parent 68d5558b9f
commit 4d6d3c4bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -68,8 +68,8 @@
id="login_input_master-password" id="login_input_master-password"
type="password" type="password"
bitInput bitInput
#masterPasswordInput
formControlName="masterPassword" formControlName="masterPassword"
appAutofocus
/> />
<button type="button" bitSuffix bitIconButton bitPasswordInputToggle></button> <button type="button" bitSuffix bitIconButton bitPasswordInputToggle></button>
</bit-form-field> </bit-form-field>

View File

@ -1,4 +1,4 @@
import { Directive, NgZone, OnInit } from "@angular/core"; import { Directive, ElementRef, NgZone, OnInit, ViewChild } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms"; import { FormBuilder, Validators } from "@angular/forms";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
import { take } from "rxjs/operators"; import { take } from "rxjs/operators";
@ -26,6 +26,8 @@ import { CaptchaProtectedComponent } from "./captcha-protected.component";
@Directive() @Directive()
export class LoginComponent extends CaptchaProtectedComponent implements OnInit { export class LoginComponent extends CaptchaProtectedComponent implements OnInit {
@ViewChild("masterPasswordInput", { static: true }) masterPasswordInput: ElementRef;
showPassword = false; showPassword = false;
formPromise: Promise<AuthResult>; formPromise: Promise<AuthResult>;
onSuccessfulLogin: () => Promise<any>; onSuccessfulLogin: () => Promise<any>;
@ -238,10 +240,16 @@ export class LoginComponent extends CaptchaProtectedComponent implements OnInit
toggleValidateEmail(value: boolean) { toggleValidateEmail(value: boolean) {
this.validatedEmail = value; this.validatedEmail = value;
if (!value) { if (!this.validatedEmail) {
// Reset master password only when going from validated to not validated (not you btn press) // Reset master password only when going from validated to not validated
// so that autofill can work properly // so that autofill can work properly
this.formGroup.controls.masterPassword.reset(); this.formGroup.controls.masterPassword.reset();
} else {
// 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());
} }
} }