-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception thrown if FocusAsync() and @onfocusin are used in custom input element at the same time - blazor Wasm #30070
Comments
Thanks for contacting us. |
The same thing is reported for Blazorise Megabit/Blazorise#1823 But by the look of it, it seems this is the Blazor issue. |
I second that bug, I've included another sample based on little more than the starter Blazor WebAssembly template. You'll find the sample at Blazor issue with focus trap. |
Happening also with our Blazorise components. Megabit/Blazorise#1823 ABP framework is also affected. https://github.com/volosoft/volo/issues/5807 It's a pretty serious bug and I don't think affected-few label is valid anymore. |
I hit the same bug while working on Ant Design Blazor. @SteveSandersonMS looking at this it seems to be affecting a lot of component libraries. Blazorise, AntDesign & MudBlazor have in total almost 480K nuget downloads (ABP has 4500K but probably only a fraction of that is for blazor related projects). It is not a huge number but I would not consider that "a few" either. This bug is also present in core6.0 preview 3. In my case the bug does not surface when I run my app in Firefox. It does show in Chrome & Edge. |
I'm working on a fix for this in 6.0-preview5, but a quick workaround for people currently affected is to add an protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await Task.Yield();
await _inputReference.FocusAsync();
}
} |
I can confirm Thank you @SteveSandersonMS |
In a Blazor WebAssembly project
Simultaneously setting of focus and using of the razor component event onfocusin throws an exception:
I want to create an input element that is focused after the first render. At the same time, I want to do further work once the element receives focus (from the user or programmatically) using @onfocusin.
For these reasons, my input element now looks like this:
The exception is thrown as soon as the focus is set (for the demo project its when the page containing the input is loaded).
To Reproduce
Demo project
The Exception
Further technical details
The text was updated successfully, but these errors were encountered: