Trying to set focus to a textbox from a RadzenDropBox on selection-change will not work. The textbox will get focus for a moment, then focus returns to the dropdown. It works correctly with a normal "select" dropdown. If I enable the Thread.Sleep, the focus works correctly.
Any ideas?
Chuck
Here is the sample page:
@page "/"
@layout MainLayout
@rendermode InteractiveAuto
<RadzenStack>
<RadzenLabel>Name</RadzenLabel>
<select @bind="@SelectedName1" @ref="NameSelectRef" Style="width: 400px;">
<option value=""></option>
@foreach (var name in Names)
{
<option value="@name">@name</option>
}
</select>
<br />
<RadzenDropDown TValue="string" Data="@Names" @bind-value="@SelectedName2" @ref="NameRef" Style="width: 400px;" />
<br/>
<RadzenLabel>Location</RadzenLabel>
<RadzenTextBox style="width:100%" @ref="TextBoxRef" />
@* <input type="text" style="width:100%" @ref="TextBoxInputRef" /> *@
</RadzenStack>
@code {
private ElementReference NameSelectRef;
private RadzenDropDown<string> NameRef;
private RadzenTextBox TextBoxRef;
private ElementReference TextBoxInputRef;
public IEnumerable<string> Names;
public string SelectedName1;
public string SelectedName2;
protected override void OnInitialized()
{
base.OnInitialized();
Names = new List<string>() { "Name 1", "Name 2" };
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
//Thread.Sleep(100);
await TextBoxRef.Element.FocusAsync();
//await TextBoxInputRef.FocusAsync();
}
}
}