Auto-focus create skill modal name field
This commit is contained in:
@@ -268,6 +268,7 @@
|
|||||||
|
|
||||||
<SkillFormModal
|
<SkillFormModal
|
||||||
Visible="ShowCreateSkillModal"
|
Visible="ShowCreateSkillModal"
|
||||||
|
AutoFocusName="true"
|
||||||
IsD6="IsD6"
|
IsD6="IsD6"
|
||||||
Title="Create Skill"
|
Title="Create Skill"
|
||||||
SubmitLabel="Create Skill"
|
SubmitLabel="Create Skill"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
<form class="form-grid" @onsubmit="SubmitAsync" @onsubmit:preventDefault>
|
<form class="form-grid" @onsubmit="SubmitAsync" @onsubmit:preventDefault>
|
||||||
<label for="@NameInputId">Skill name</label>
|
<label for="@NameInputId">Skill name</label>
|
||||||
<input id="@NameInputId" @bind="FormState.Model.Name" @bind:event="oninput"/>
|
<input id="@NameInputId" @ref="NameInputElement" @bind="FormState.Model.Name" @bind:event="oninput"/>
|
||||||
@if (FormState.Errors.TryGetValue("name", out var skillNameError))
|
@if (FormState.Errors.TryGetValue("name", out var skillNameError))
|
||||||
{
|
{
|
||||||
<p class="field-error">@skillNameError</p>
|
<p class="field-error">@skillNameError</p>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using RpgRoller.Contracts;
|
using RpgRoller.Contracts;
|
||||||
|
|
||||||
namespace RpgRoller.Components.Pages.HomeControls;
|
namespace RpgRoller.Components.Pages.HomeControls;
|
||||||
@@ -19,6 +20,16 @@ public partial class SkillFormModal
|
|||||||
FormState.Model.AllowFumble = InitialModel.AllowFumble;
|
FormState.Model.AllowFumble = InitialModel.AllowFumble;
|
||||||
FormState.ResetValidation();
|
FormState.ResetValidation();
|
||||||
AppliedFormVersion = FormVersion;
|
AppliedFormVersion = FormVersion;
|
||||||
|
PendingNameFocus = AutoFocusName;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
|
{
|
||||||
|
if (!Visible || !PendingNameFocus)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PendingNameFocus = false;
|
||||||
|
await NameInputElement.FocusAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SubmitAsync()
|
private async Task SubmitAsync()
|
||||||
@@ -86,6 +97,8 @@ public partial class SkillFormModal
|
|||||||
private FormState<SkillFormModel> FormState { get; } = new();
|
private FormState<SkillFormModel> FormState { get; } = new();
|
||||||
private int AppliedFormVersion { get; set; } = -1;
|
private int AppliedFormVersion { get; set; } = -1;
|
||||||
private bool IsSubmitting { get; set; }
|
private bool IsSubmitting { get; set; }
|
||||||
|
private bool PendingNameFocus { get; set; }
|
||||||
|
private ElementReference NameInputElement { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public bool Visible { get; set; }
|
public bool Visible { get; set; }
|
||||||
@@ -132,6 +145,9 @@ public partial class SkillFormModal
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public bool IsMutating { get; set; }
|
public bool IsMutating { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public bool AutoFocusName { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<Guid> SkillSaved { get; set; }
|
public EventCallback<Guid> SkillSaved { get; set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user