Blazored.Typeahead
2.0.1
Prefix Reserved
See the version list below for details.
dotnet add package Blazored.Typeahead --version 2.0.1
NuGet\Install-Package Blazored.Typeahead -Version 2.0.1
<PackageReference Include="Blazored.Typeahead" Version="2.0.1" />
paket add Blazored.Typeahead --version 2.0.1
#r "nuget: Blazored.Typeahead, 2.0.1"
// Install Blazored.Typeahead as a Cake Addin #addin nuget:?package=Blazored.Typeahead&version=2.0.1 // Install Blazored.Typeahead as a Cake Tool #tool nuget:?package=Blazored.Typeahead&version=2.0.1
Important Notice For Server-side Blazor Apps
There is currently an issue with Server-side Blazor apps (not Client-side Blazor). They are unable to import static assets from component libraries such as this one.
You can still use this package, however, you will need to manually add the CSS file to your Server-side Blazor projects wwwroot
folder. Then you will need to reference it in your main _Layout.cshtml
.
Alternatively, there is a great package by Mister Magoo which offers a solution to this problem without having to manually copy files.
Installing
You can install from Nuget using the following command:
Install-Package Blazored.Typeahead
Or via the Visual Studio package manager.
Usage
I would suggest you add the following using statement to your main _Imports.razor
to make referencing the component a bit easier.
@using Blazored.Typeahead
Once you've done this you can add the control to a component like so.
<BlazoredTypeahead></BlazoredTypeahead>
Local Data Example
<BlazoredTypeahead Data="@SearchFilms"
bind-Item="@SelectedFilm">
<SelectedTemplate>
@context.Title
</SelectedTemplate>
<ResultTemplate>
@context.Title (@context.Year)
</ResultTemplate>
</BlazoredTypeahead>
@functions {
[Parameter] protected List<Film> Films { get; set; }
private async Task<List<Film>> SearchFilms(string searchText)
{
return await Task.FromResult(Films.Where(x => x.Title.ToLower().Contains(searchText.ToLower())).ToList());
}
}
In the example above, the component is set up with the minimum requirements. You must provide a method which has the following signature Task<List<T> MethodName(string searchText)
, to the Data
parameter. The control will call this method with the current search text every time the debounce timer expires (default: 300ms). You must also set a value for the Item
parameter. This will be populated with the item selected from the search results.
The component requires two templates to be provided...
SelectedTemplate
ResultTemplates
The SelectedTemplate
is used to display the selected item and the ResultTemplate
is used to display each result in the search list.
Remote Data Example
@inject HttpClient httpClient
<BlazoredTypeahead Data="@SearchFilms"
bind-Item="@SelectedFilm"
Debounce="500">
<SelectedTemplate>
@context.Title
</SelectedTemplate>
<ResultTemplate>
@context.Title (@context.Year)
</ResultTemplate>
<NotFoundTemplate>
Sorry, there weren't any search results.
</NotFoundTemplate>
</BlazoredTypeahead>
@functions {
[Parameter] protected List<Film> Films { get; set; }
private async Task<List<Film>> SearchFilms(string searchText)
{
var response = await httpClient.GetJsonAsync<List<Film>>($"https://allfilms.com/api/films/?title={searchText}");
return response;
}
}
Because you provide the search method to the component, making a remote call is really straight-forward. In this example, the Debounce
parameter has been upped to 500ms and the NotFoundTemplate
has been specified.
Full Options List
Below is a list of all the options available on the Typeahead.
Templates
- ResultTemplate (Required) - Allows the user to define a template for a result in the results list
- SelectedTemplate (Required) - Allows the user to define a template for a selected item
- NotFoundTemplate - Allows the user to define a template when no items are found
Parameters
- Item (Required) - Used for binding a local field to selected item on the control
- Data (Required) - Method to call when performing a search
- Placeholder (Optional) - Allows user to specify a placeholder message
- MinimumLength (Optional - Default 1) - Minimum number of characters before starting a search
- Debounce (Optional - Default 300) - Time to wait after the last keypress before starting a search
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Components.Browser (>= 3.0.0-preview5-19227-01)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Blazored.Typeahead:
Package | Downloads |
---|---|
OneLine.Blazor
OneLine.Blazor is a set of components and utilities to be used in blazor context. |
|
KingTech.Web.FormGenerator
Package Description |
|
KingTech.Web.Markdown
Package Description |
|
KingTech.Web.Markdown.NuGet
Package Description |
|
NBlaze.UIComponents
UI Blazor components |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Blazored.Typeahead:
Repository | Stars |
---|---|
MUnique/OpenMU
This project aims to create an easy to use, extendable and customizable server for a MMORPG called "MU Online".
|
Version | Downloads | Last updated |
---|---|---|
4.7.0 | 498,852 | 7/15/2022 |
4.6.0 | 468,518 | 3/27/2021 |
4.5.1 | 65,290 | 1/7/2021 |
4.5.0 | 9,685 | 1/4/2021 |
4.4.1 | 39,045 | 11/1/2020 |
4.4.0 | 24,271 | 9/24/2020 |
4.3.0 | 108,571 | 3/6/2020 |
4.2.2 | 19,464 | 12/29/2019 |
4.2.1 | 4,554 | 12/6/2019 |
4.2.0 | 1,722 | 11/23/2019 |
4.1.0 | 3,001 | 10/25/2019 |
4.0.5 | 643 | 10/25/2019 |
4.0.4 | 607 | 10/24/2019 |
4.0.3 | 674 | 10/22/2019 |
4.0.1 | 603 | 10/22/2019 |
4.0.0 | 669 | 10/22/2019 |
3.1.8 | 1,820 | 9/25/2019 |
3.1.7 | 1,923 | 9/17/2019 |
3.1.6 | 328 | 9/17/2019 |
3.1.5 | 445 | 9/5/2019 |
3.1.4 | 468 | 8/14/2019 |
3.1.3 | 345 | 8/14/2019 |
3.1.2 | 353 | 8/14/2019 |
3.1.1 | 878 | 7/26/2019 |
3.1.0 | 624 | 7/2/2019 |
3.0.4 | 560 | 6/19/2019 |
3.0.3 | 365 | 6/13/2019 |
3.0.2 | 701 | 6/13/2019 |
3.0.1 | 656 | 6/12/2019 |
3.0.0 | 677 | 6/12/2019 |
2.1.0 | 701 | 6/2/2019 |
2.0.2 | 642 | 5/31/2019 |
2.0.1 | 707 | 5/31/2019 |
2.0.0 | 730 | 5/30/2019 |
1.0.1 | 697 | 5/27/2019 |
1.0.0 | 1,003 | 5/27/2019 |