Skip to content
GitHub11 stars

A two-state button that can be on or off.

<ToggleRoot aria-label="Favorite" class="toggle-button">
    <Render Context="toggle">
        <button type="button" @attributes="toggle.Attributes">

Anatomy

Import the primitives and use the part:

@using Blazix.Primitives

<ToggleRoot />

Use it on its own, or in a Toggle Group, which shares one state between a series of toggles.

API Reference

ToggleRoot

Renders a <button> element.

ParameterTypeDefault
Pressed bool false
PressedChanged

Called with the new value when Pressed changes, for @bind-Pressed.

EventCallback<bool> -
OnPressedChange EventCallback<ValueChangeEventArgs<bool>> -
Disabled

Whether the component should ignore user interaction.

bool false
Value string? -
NativeButton bool? -
Render RenderFragment<ToggleRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-pressed

Present when the toggle button is pressed.

-
data-disabled

Present when the toggle button is disabled.

-