Skip to content
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

Add a public method to focus the component #166

Merged
merged 3 commits into from Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion samples/BlazorWebAssembly/Pages/Index.razor
Expand Up @@ -9,7 +9,9 @@
<BlazoredTypeahead SearchMethod="GetPeopleLocal"
@bind-Value="FormModel.SelectedPerson"
EnableDropDown="true"
placeholder="Search by first name...">
placeholder="Search by first name..."
@ref="LocalBlazoredTypeahead"
>
<SelectedTemplate Context="person">
@person.Firstname
</SelectedTemplate>
Expand All @@ -20,6 +22,7 @@
<ValidationMessage For="@(() => FormModel.SelectedPerson)" />

<button class="btn btn-primary" type="submit" style="margin-top: 20px;">Submit</button>
<button class="btn btn-info" type="button" style="margin-top: 20px" @onclick="@(_ => LocalBlazoredTypeahead.Focus())">Focus</button>
</EditForm>

<hr />
Expand Down Expand Up @@ -186,6 +189,7 @@
private int? SelectedPersonId;
private IList<Person> SelectedPeople;
private FormExample FormModel = new FormExample();
private BlazoredTypeahead<Person, Person> LocalBlazoredTypeahead;

protected override void OnInitialized()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Blazored.Typeahead/BlazoredTypeahead.razor.cs
Expand Up @@ -450,5 +450,10 @@ protected virtual void Dispose(bool disposing)
_debounceTimer.Dispose();
}
}

public async Task Focus()
{
await Interop.Focus(JSRuntime, _searchInput);
}
}
}