Showcase

Blazor Switch

Create consistent cross-browser and cross-device checkboxes with our blazor switches. A switch has the markup of a custom checkbox. The examples below cover the disabled state, a reversed layout, the ValueChanged event, a read-only value and use in a form.
API Documentation

Basic usage #

Disable #

Use the Disabled parameter to disable the Switch.
Razor
<div class="mb-3">
    <Switch @bind-Value="agree" Disabled="@disabled" Label="Disabled switch checkbox input" />
</div>

<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Warning" @onclick="Toggle"> Toggle </Button>

@code {
    private bool agree = true;
    private bool disabled = true;

    private void Enable() => disabled = false;

    private void Disable() => disabled = true;

    private void Toggle() => disabled = !disabled;
}
Also, use Enable() and Disable() methods to enable and disable the Switch.
NOTE
Do not use both the Disabled parameter and Enable() & Disable() methods.
Razor
<div class="mb-3">
    <Switch @ref="switch1" @bind-Value="agree" Label="Disabled switch checkbox input" />
</div>

<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>

@code {
    private Switch switch1 = default!;
    private bool agree = true;

    private void Disable() => switch1.Disable();

    private void Enable() => switch1.Enable();
}

Reverse #

Put your switches on the opposite side by using the Reverse parameter.

Events: ValueChanged #

This event fired when the Switch selection changed.

Read-only value #

Set only the Value parameter to display a value that cannot be written back, such as a read-only property. Combine it with Disabled so users cannot toggle the display.

Form #

The Switch can also be used inside an EditForm with Value and ValueChanged instead of @bind-Value. Use @bind-Value when you want the EditContext to track the field.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.