website/src/NSeguin.Dev.Web/Components/Shared/AutoFocus.razor

14 lines
No EOL
407 B
Text

@inject IJSRuntime JSRuntime
@code {
[Parameter]
public Func<ElementReference> GetControl { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (GetControl is null)
throw new ArgumentNullException(nameof(GetControl));
if (firstRender)
await JSRuntime.InvokeVoidAsync("App.scrollIntoView", GetControl(), true);
}
}