Blazored.Typeahead 2.0.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
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
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazored.Typeahead" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Blazored.Typeahead --version 2.0.1
#r "nuget: Blazored.Typeahead, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

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 321,357 7/15/2022
4.6.0 430,520 3/27/2021
4.5.1 62,586 1/7/2021
4.5.0 7,535 1/4/2021
4.4.1 37,699 11/1/2020
4.4.0 20,394 9/24/2020
4.3.0 105,424 3/6/2020
4.2.2 18,965 12/29/2019
4.2.1 4,515 12/6/2019
4.2.0 1,686 11/23/2019
4.1.0 2,960 10/25/2019
4.0.5 613 10/25/2019
4.0.4 581 10/24/2019
4.0.3 643 10/22/2019
4.0.1 577 10/22/2019
4.0.0 630 10/22/2019
3.1.8 1,785 9/25/2019
3.1.7 1,904 9/17/2019
3.1.6 308 9/17/2019
3.1.5 429 9/5/2019
3.1.4 446 8/14/2019
3.1.3 332 8/14/2019
3.1.2 335 8/14/2019
3.1.1 855 7/26/2019
3.1.0 602 7/2/2019
3.0.4 547 6/19/2019
3.0.3 351 6/13/2019
3.0.2 669 6/13/2019
3.0.1 630 6/12/2019
3.0.0 649 6/12/2019
2.1.0 659 6/2/2019
2.0.2 609 5/31/2019
2.0.1 675 5/31/2019
2.0.0 699 5/30/2019
1.0.1 666 5/27/2019
1.0.0 872 5/27/2019