dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

[Blazor] EditForm within a modal window causes input fields to lose focus when used in combination with bind-value-oninput #10228

Closed fs86 closed 5 years ago

fs86 commented 5 years ago

If you have a modal window with a EditForm, fields with bind-value-oninput lose focus while typing. I have created a small repo where you can see this behavior. The corresponding code is in the Index.razor page.

https://github.com/fs86/BlazorTest

fs86 commented 5 years ago

Update:

I got a pull request for a quick fix for this issue: https://github.com/fs86/BlazorTest/pull/1 If you use a complex type as model for the EditForm then everything works as expected:

<EditForm Model="@formData">
    <MyInput Autofocus="true" bind-Value="@formData.FirstName" Placeholder="First name" />
</EditForm>

@functions
{
    FormData formData = new FormData();

    protected class FormData
    {
        public string FirstName { get; set; } = string.Empty;
    }
}

But maybe that's still something you want to take a closer look at.

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @fs86. We're closing this issue as it seems the issue you're facing is caused by your application logic.