Blazor Input Checkbox

Checkboxes allow the user to select one or more items from a set.

Features:

JavaScript Independence: This component operates seamlessly without requiring JavaScript, offering a lightweight and straightforward solution.

Appearance customization: Customizable styles and themes.

Rendering options: Render your component as various HTML tags for maximum flexibility and integration.

Learn about core component featuresLearn about input component features

Simple checkbox:

MyBool1 value: False
<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="MyBool1" />
    MyBool1
</BlazorLabel>
<div>MyBool1 value: @MyBool1</div>

@code {
    public bool MyBool1 { get; set; } = false;
}

Checkbox variants:

<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." Variants="new[] {BaseVariants.Primary}" />
    Primary
</BlazorLabel>
<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." Variants="new[] {BaseVariants.Secondary}" />
    Secondary
</BlazorLabel>
<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." Variants="new[] {BaseVariants.Info}" />
    Info
</BlazorLabel>
<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." Variants="new[] {BaseVariants.Warning}" />
    Warning
</BlazorLabel>
<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." Variants="new[] {BaseVariants.Danger}" />
    Danger
</BlazorLabel>
<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." Variants="new[] {BaseVariants.Success}" />
    Success
</BlazorLabel>

Checkbox group:

Selected items: Item1,Item2
<BlazorCheckboxGroup @bind-Value="MyCheckboxes">
    <CheckboxTemplate Context="item">
        <BlazorLabel>
            <BlazorInputCheckbox @bind-Value="item.Selected" Variants="(string[])item.Resource" />
            @item.Label
        </BlazorLabel>
    </CheckboxTemplate>
</BlazorCheckboxGroup>
<div>Selected items: @string.Join(",", MyCheckboxes.GetSelectedItems())</div>

@code {
    public CheckboxCollection<string> MyCheckboxes { get; set; } = new()
    {
        new ()
        {
            Selected = true,
            Label = "Item 1",
            Item = "Item1",
            Resource = new[] {BaseVariants.Primary}
        },
        new ()
        {
            Selected = true,
            Label = "Item 2",
            Item = "Item2",
            Resource = new[] {BaseVariants.Secondary}
        }
    };
}

Disabled input:

<BlazorLabel>
    <BlazorInputCheckbox @bind-Value="..." @bind-disabled="Disabled" />
    I ๐Ÿ’œ Blazor
</BlazorLabel>
<BlazorButton type="button" @onclick="_ => Disabled = !Disabled" Variants="Disabled?new[] {BaseVariants.Success}:new[] {BaseVariants.Danger}">@(Disabled ? "Enable" : "Disable")</BlazorButton>

@code {
    public bool Disabled { get; set; } = true;
}

Appearance Customization

Learn about Theme Feature
Component & Variants CSS class
BlazorInputCheckbox.invalid border-danger
BlazorInputCheckbox.valid border-success
BlazorInputCheckbox.primary accent-primary
BlazorInputCheckbox.secondary accent-secondary
BlazorInputCheckbox.success accent-success
BlazorInputCheckbox.danger accent-danger
BlazorInputCheckbox.warning accent-warning
BlazorInputCheckbox.info accent-info

Parameters

BlazorInputCheckbox

Name Type Description
RenderAs string Specifies the HTML tag to be used for rendering the component. This can be any valid HTML tag, such as div, span, button, or other suitable tags.
Variants string[] Specifies the variant of the component.
Value bool The value of the input.
UpdateOnHtmlEvent string This parameter allows you to specify which HTML event should trigger a re-render or update of the component. When the specified event occurs on the input element, the component will initiate the parsing process, updating its internal value to reflect the UI input. Default event is onchange.
ValueParsed EventCallback<ParseEventArgs> Specify an action or method to be executed when the component parses a value, whether the parsing operation succeeds or fails.
FieldState FieldState Represents the state of a field or input element within the component. Can be used to track and manage the state of the field and display relevant messages to the user.
ParseValueHandler Func<string?, TValue?> Implement specialized parsing logic for the component, such as handling user input, converting strings to specific data types, which corresponds to the type of the Value parameter in the component and performing validation during the parsing process.

Methods

CheckboxCollection<T>

Name Description
GetSelectedItems() Returns a collection of items of type T, where each item represents a choice that has been selected by the user in the checkbox group.
An error has occurred. This application may no longer respond until reloaded. Reload ๐Ÿ—™