From 76c83a578485905262ab8528eba3c5b20202b9c5 Mon Sep 17 00:00:00 2001 From: Frank Tovar Date: Thu, 26 Feb 2026 14:15:45 +0100 Subject: [PATCH] Auto-focus create skill modal name field --- .../Pages/HomeControls/CharacterPanel.razor | 1 + .../Pages/HomeControls/SkillFormModal.razor | 2 +- .../Pages/HomeControls/SkillFormModal.razor.cs | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/RpgRoller/Components/Pages/HomeControls/CharacterPanel.razor b/RpgRoller/Components/Pages/HomeControls/CharacterPanel.razor index 07043dc..70d79db 100644 --- a/RpgRoller/Components/Pages/HomeControls/CharacterPanel.razor +++ b/RpgRoller/Components/Pages/HomeControls/CharacterPanel.razor @@ -268,6 +268,7 @@ - + @if (FormState.Errors.TryGetValue("name", out var skillNameError)) {

@skillNameError

diff --git a/RpgRoller/Components/Pages/HomeControls/SkillFormModal.razor.cs b/RpgRoller/Components/Pages/HomeControls/SkillFormModal.razor.cs index 4aaad9c..58eb4db 100644 --- a/RpgRoller/Components/Pages/HomeControls/SkillFormModal.razor.cs +++ b/RpgRoller/Components/Pages/HomeControls/SkillFormModal.razor.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; using RpgRoller.Contracts; namespace RpgRoller.Components.Pages.HomeControls; @@ -19,6 +20,16 @@ public partial class SkillFormModal FormState.Model.AllowFumble = InitialModel.AllowFumble; FormState.ResetValidation(); AppliedFormVersion = FormVersion; + PendingNameFocus = AutoFocusName; + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (!Visible || !PendingNameFocus) + return; + + PendingNameFocus = false; + await NameInputElement.FocusAsync(); } private async Task SubmitAsync() @@ -86,6 +97,8 @@ public partial class SkillFormModal private FormState FormState { get; } = new(); private int AppliedFormVersion { get; set; } = -1; private bool IsSubmitting { get; set; } + private bool PendingNameFocus { get; set; } + private ElementReference NameInputElement { get; set; } [Parameter] public bool Visible { get; set; } @@ -132,6 +145,9 @@ public partial class SkillFormModal [Parameter] public bool IsMutating { get; set; } + [Parameter] + public bool AutoFocusName { get; set; } + [Parameter] public EventCallback SkillSaved { get; set; }