Hi,
I'm currently trying to make a radzen autocomplete focus after render but it doesn't seem to be working.
this is my code at the moment.
<RadzenAutoComplete name="searchbar" id="searchbar" Data="@AllItemNo" @bind-Value="@input" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.StartsWith" @onkeyup="KeyboardTrigger" @ref=@barcodeInput />
RadzenAutoComplete barcodeInput;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await barcodeInput.Element.FocusAsync();
}
}
enchev
September 18, 2023, 6:13am
2
You can try also alternative approach:
Thank you, perfect! I was able to capture in OnAfterRenderAsync (I see I need to go do a more careful study of the Blazor component lifecycle).
In that method, I was able to revert back to the @ref approach, but have a couple small follow-up questions on focus and selection:
<EditTemplate Context="order">
<RadzenTextBox @ref="shipNameTextBox" id="idForJSTest"
@bind-Value="order.ShipName"
Style="width:100%; display: block" Name="ShipName" />
then check the ref variable for null…
If I change my autocomplete to a textbox it works.
it doesn't work for autocomplete.
enchev
September 18, 2023, 8:35am
4
The TextBox will render simple input while the AutoComplete is a bit more complex:
UPDATE: We've decided to add FocusAsync() method:
committed 08:52AM - 18 Sep 23 UTC
okay so is there a way to focus an autocomplete or is it to complex to focus?
enchev
September 18, 2023, 8:54am
6
I've updated my reply, the new method will be part of our next update later this week.
tmeehan
February 25, 2026, 5:55pm
8
I just want to throw in my 2 cents. I was having this issue with an autocomplete in a dialog. Setting the delay to 1 second or more is all that worked until I saw a post about making sure to set AutoFocusFirstElement= false in the DialogOptions before calling the dialog. Works perfect now. It’s always the little things.