BlazorChoices 1.0.0

dotnet add package BlazorChoices --version 1.0.0
                    
NuGet\Install-Package BlazorChoices -Version 1.0.0
                    
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="BlazorChoices" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorChoices" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BlazorChoices" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorChoices --version 1.0.0
                    
#r "nuget: BlazorChoices, 1.0.0"
                    
#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.
#:package BlazorChoices@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorChoices&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BlazorChoices&version=1.0.0
                    
Install as a Cake Tool

BlazorChoices

A Blazor component library that wraps Choices.js to provide enhanced select and input elements with search, tags, and more.

Features

  • ✅ Single and multiple select support
  • ✅ Tags input with add/remove
  • ✅ Built-in search functionality
  • ✅ Configurable options
  • ✅ Event callbacks for value changes
  • ✅ Full Blazor interop support
  • ✅ .NET 10 support
  • ✅ Clean and intuitive API

Demo

Check out the live demo on GitHub Pages to see all features in action.

Installation

Add the BlazorChoices component library to your Blazor project:

dotnet add package BlazorChoices

Or add it directly to your .csproj file:

<PackageReference Include="BlazorChoices" Version="1.0.0" />

Getting Started

1. Add using statement

Add the following to your _Imports.razor:

@using BlazorChoices

2. Include CSS and JavaScript

Add the following to your index.html (Blazor WebAssembly) or _Host.cshtml (Blazor Server):


<link href="_content/BlazorChoices/lib/choices/choices.min.css" rel="stylesheet" />


<script src="_content/BlazorChoices/lib/choices/choices.min.js"></script>

Usage Examples

Simple Select

<ChoicesSelect OnChange="@OnSingleChange">
    <option value="">Select a fruit...</option>
    <option value="apple">Apple</option>
    <option value="banana">Banana</option>
    <option value="orange">Orange</option>
</ChoicesSelect>

@code {
    private string selectedValue = string.Empty;

    private void OnSingleChange(string value)
    {
        selectedValue = value;
    }
}

Multiple Select

<ChoicesSelect Multiple="true" OnChangeMultiple="@OnMultipleChange" Options="@options">
    <option value="us">United States</option>
    <option value="uk">United Kingdom</option>
    <option value="fr">France</option>
    <option value="de">Germany</option>
</ChoicesSelect>

@code {
    private string[] selectedValues = Array.Empty<string>();
    
    private ChoicesOptions options = new()
    {
        RemoveItemButton = true,
        SearchEnabled = true,
        PlaceholderValue = "Choose countries..."
    };

    private void OnMultipleChange(string[] values)
    {
        selectedValues = values;
    }
}

Tags Input

<ChoicesInput OnTagsChanged="@OnTagsChange" Options="@tagOptions" />

@code {
    private string[] tags = Array.Empty<string>();
    
    private ChoicesOptions tagOptions = new()
    {
        RemoveItemButton = true,
        AddItems = true,
        DuplicateItemsAllowed = false,
        MaxItemCount = 10
    };

    private void OnTagsChange(string[] values)
    {
        tags = values;
    }
}

Configuration Options

The ChoicesOptions class provides the following configuration options:

Property Type Default Description
SearchEnabled bool true Enable search functionality
RemoveItemButton bool false Show remove button for selected items
ShouldSort bool true Sort choices alphabetically
PlaceholderValue string null Placeholder text
MaxItemCount int -1 Maximum number of items that can be selected (-1 = unlimited)
DuplicateItemsAllowed bool true Allow duplicate items
Position string "auto" Position of dropdown (auto, top, bottom)
AddItems bool true Allow adding custom items
RemoveItems bool true Allow removal of items
NoResultsText string "No results found" Text shown when there are no results
NoChoicesText string "No choices to choose from" Text shown when there are no choices

API Reference

ChoicesSelect Component

Parameters:

  • Multiple (bool): Enable multiple selection mode
  • Options (ChoicesOptions): Configuration options
  • OnChange (EventCallback<string>): Event fired when a single value changes
  • OnChangeMultiple (EventCallback<string[]>): Event fired when multiple values change
  • Id (string): HTML id attribute
  • Class (string): CSS class
  • ChildContent (RenderFragment): Option elements

Methods:

  • InitAsync(): Initialize the Choices.js instance
  • DestroyAsync(): Destroy the Choices.js instance
  • SetValueAsync(object value): Set the selected value programmatically
  • GetValueAsync(): Get the current selected value

ChoicesInput Component

Parameters:

  • Options (ChoicesOptions): Configuration options
  • OnTagsChanged (EventCallback<string[]>): Event fired when tags change
  • Id (string): HTML id attribute
  • Class (string): CSS class

Methods:

  • InitAsync(): Initialize the Choices.js instance
  • DestroyAsync(): Destroy the Choices.js instance
  • SetValueAsync(object value): Set the tags programmatically
  • GetValueAsync(): Get the current tags

Building the Sample

To build and run the sample application:

git clone https://github.com/agriffard/BlazorChoices.git
cd BlazorChoices
dotnet build
cd samples/BlazorChoices.Sample
dotnet run

Then navigate to http://localhost:5000 in your browser.

Publishing to GitHub Pages

To publish the sample application to GitHub Pages:

cd samples/BlazorChoices.Sample
dotnet publish -c Release -o publish
# Configure base href for GitHub Pages
# Then deploy the publish/wwwroot folder to gh-pages branch

Technology Stack

  • .NET 10
  • Blazor WebAssembly
  • Choices.js v11.2.0
  • JavaScript Interop

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.

Acknowledgments

  • Choices.js - The excellent JavaScript library that powers this component
  • Built with ❤️ for the Blazor community
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 117 1/5/2026