From 9a367acbdcb2d8a707ea93521ee1362a6ed97eba Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Wed, 24 Sep 2025 22:05:33 +0200 Subject: [PATCH] Autofocus password field on web app unlock screen (#1269) --- .../Auth/Components/PasswordInputField.razor | 29 ++++++++++++++ .../AliasVault.Client/Auth/Pages/Unlock.razor | 40 +++++++++++++++++-- .../wwwroot/css/tailwind.css | 8 ---- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/apps/server/AliasVault.Client/Auth/Components/PasswordInputField.razor b/apps/server/AliasVault.Client/Auth/Components/PasswordInputField.razor index 8e4aa8763..deb0221c5 100644 --- a/apps/server/AliasVault.Client/Auth/Components/PasswordInputField.razor +++ b/apps/server/AliasVault.Client/Auth/Components/PasswordInputField.razor @@ -1,13 +1,16 @@ @using System.Linq.Expressions +@inject IJSRuntime JSRuntime
-
@@ -67,7 +68,7 @@ else
- +
@@ -96,9 +97,11 @@ else private bool IsLoading { get; set; } = true; private bool IsWebAuthnLoading { get; set; } private bool ShowWebAuthnButton { get; set; } + private bool IsPasswordFocused { get; set; } private readonly UnlockModel _unlockModel = new(); private FullScreenLoadingIndicator _loadingIndicator = new(); private ServerValidationErrors _serverValidationErrors = new(); + private PasswordInputField? passwordField; private IStringLocalizer Localizer => LocalizerFactory.Create("Pages.Auth.Unlock", "AliasVault.Client"); private IStringLocalizer ApiErrorLocalizer => LocalizerFactory.Create("ApiErrors", "AliasVault.Client"); @@ -123,6 +126,12 @@ else IsLoading = false; StateHasChanged(); } + + if (!IsLoading && !IsWebAuthnLoading && !ShowWebAuthnButton && !IsPasswordFocused) + { + IsPasswordFocused = true; + await FocusPasswordField(); + } } /// @@ -314,9 +323,34 @@ else /// /// Show the password login form. /// - private void ShowPasswordLogin() + private async Task ShowPasswordLogin() { ShowWebAuthnButton = false; StateHasChanged(); + + // Focus the password field after the form is rendered + if (!IsPasswordFocused) + { + IsPasswordFocused = true; + await FocusPasswordField(); + } + } + + /// + /// Focus the password input field using component reference. + /// + private async Task FocusPasswordField() + { + try + { + if (passwordField != null) + { + await passwordField.FocusAsync(); + } + } + catch + { + // Do nothing + } } } diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css index 44167a388..be7780ef7 100644 --- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css +++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css @@ -3472,10 +3472,6 @@ video { } @media (min-width: 1024px) { - .lg\:fixed { - position: fixed; - } - .lg\:relative { position: relative; } @@ -3536,10 +3532,6 @@ video { display: none; } - .lg\:min-h-screen { - min-height: 100vh; - } - .lg\:w-1\/2 { width: 50%; }