Add an overload to ElementReference.FocusAsync that accepts preventScroll as an option:
```C#
public static ValueTask FocusAsync(this ElementReference elementReference, bool preventScroll);
````
I should probably add a new issue for this but I think FocusAsync() should also include preventScroll flag
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus
On Blazor server side, when you apply autofocus on your inputs the attribute is not being respected:
autofocus being applied but loses it after the page fully loadautofocus is not applied at allCreate a page with the followin code:
<input type="text" name="name" />
<input type="text" name="name1" autofocus />
Expected: If you don't do anything while the page loads the autofocus must be aplied
I am seeing every issue related with this closed (hope I am not blind) so just to make it clear:
We are going to have a new API that lets us focus by calling ref.FocusAsync() but we will not be able to add autofocus to our normal html elements because it will not work?
@barahonajm sorry I meant to reopen the other issue. You are correct in your summary though.
Got it, I believe normal html functionality like autofocus should be preserved but I know it is hard so at least FocusAsync solves the problem.
I should probably add a new issue for this but I think FocusAsync() should also include preventScroll flag
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus
We can repurpose this issue to track adding that option.
FYI @MackinnonBuck
Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Do you like the proposed implementation of adding a bool preventScroll parameter to the method? Do you prefer an overload method or a optional parameter?
@ryanclarke we would want a new overload. Modifying the current method would be a breaking change which we want to avoid.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I'll start working on this enhancement. Thanks for your help.
Just to clarify, since the nature of this issue seems to have changed over time.
Solving this issue should not mess with autofocus, it should simply add a preventDefault boolean parameter to an new overload of FocusAsync.
Acceptance criteria is that focusing on an off-screen element using this new method would not scroll the page.
I'm not going to have the time to work on this. Sorry. Anyone else can take it.
I will start working on this.