Skip to content
GitHub11 stars

Toggle Group

Provides a shared state to a series of toggle buttons.

<ToggleGroupRoot aria-label="Text alignment" Value="@(["left"])" class="toggle-group-panel">
    <ToggleRoot aria-label="Align left" Value="left" class="toggle-group-button">
        @AlignLeftIcon

Anatomy

Toggle Group is composed together with Toggle. Import the primitives and assemble the parts:

@using Blazix.Primitives

<ToggleGroupRoot>
    <ToggleRoot />
</ToggleGroupRoot>

Examples

Multiple

Add the Multiple parameter to allow pressing more than one toggle at a time.

<ToggleGroupRoot Multiple="true" Value="@(["bold", "italic"])" aria-label="Text formatting options" class="toggle-group-panel">
    <ToggleRoot aria-label="Bold" Value="bold" class="toggle-group-button">
        @BoldIcon

API Reference

ToggleGroupRoot

Renders a <div> element.

ParameterTypeDefault
Value IReadOnlyList<string>? -
ValueChanged

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

EventCallback<IReadOnlyList<string>?> -
OnValueChange

Runs before the value changes, with the reason; call Cancel() to keep it.

EventCallback<ValueChangeEventArgs<IReadOnlyList<string>>> -
Disabled

Whether the component should ignore user interaction.

bool false
Multiple bool false
Orientation

Which way the parts are laid out, and which arrow keys move between them.

Orientation Orientation.Horizontal
LoopFocus bool true
Render RenderFragment<ToggleGroupRenderProps>? -
ChildContent

The part's content.

RenderFragment? -

Other attributes are passed to the element it renders.

AttributeType
data-orientation

Indicates the orientation of the toggle group.

'horizontal' | 'vertical'
data-disabled

Present when the toggle group is disabled.

-
data-multiple

Present when the toggle group allows multiple buttons to be in the pressed state at the same time.

-