Toggle Group

A bunch of toggle buttons forming a selection of values to choose from with various selection modes.

See also: Button Group

Usage

The MudToggleGroup holds a number of MudToggleItems and semantically groups them together into a selection. The items can be configured to show text or custom content such as an icon. To show a check mark set the CheckMark parameter. The check mark will push the text to the side by default. If you don't want this you can set the FixedContent parameter to counterbalance the checkmark with padding on the right.

One

Two

Three

Four

<MudStack>
    <MudStack Row Class="flex-wrap">
        <MudStack Spacing="16" AlignItems="@AlignItems.Start">
            <MudToggleGroup T="string" Style="width: 300px;" Outline="@_outline" Delimiters="@_delimiters" Dense="@_dense" Rounded="@_rounded" CheckMark="@_checkMark" FixedContent="@_fixedContent" Disabled="@_disabled">
                <MudToggleItem Value="@("One")"/>
                <MudToggleItem Value="@("Two")"/>
                <MudToggleItem Value="@("Three")"/>
                <MudToggleItem Value="@("Four")"/>
            </MudToggleGroup>

            <MudToggleGroup T="string" Outline="@_outline" Delimiters="@_delimiters" Dense="@_dense" Rounded="@_rounded" CheckMark="@_checkMark" FixedContent="@_fixedContent" Disabled="@_disabled">
                <MudToggleItem Value="@("left")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignLeft"/>
                </MudToggleItem>
                <MudToggleItem Value="@("center")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignCenter"/>
                </MudToggleItem>
                <MudToggleItem Value="@("right")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignRight"/>
                </MudToggleItem>
                <MudToggleItem Value="@("justify")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignJustify"/>
                </MudToggleItem>
            </MudToggleGroup>
        </MudStack>
        <MudSpacer/>
        <MudToggleGroup T="string" Vertical  Outline="@_outline" Delimiters="@_delimiters" Dense="@_dense" Rounded="@_rounded" CheckMark="@_checkMark" FixedContent="@_fixedContent" Disabled="@_disabled">
                <MudToggleItem Value="@("left")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignLeft"/>
                </MudToggleItem>
                <MudToggleItem Value="@("center")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignCenter"/>
                </MudToggleItem>
                <MudToggleItem Value="@("right")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignRight"/>
                </MudToggleItem>
                <MudToggleItem Value="@("justify")">
                    <MudIcon Icon="@Icons.Material.Filled.FormatAlignJustify"/>
                </MudToggleItem>
        </MudToggleGroup>
    </MudStack>

    <MudStack Row Class="flex-wrap">
        <MudCheckBox @bind-Value="_dense" Label="Dense"/>
        <MudCheckBox @bind-Value="_rounded" Label="Rounded"/>
        <MudCheckBox @bind-Value="_checkMark" Label="CheckMark"/>
        <MudCheckBox @bind-Value="_fixedContent" Label="FixedContent"/>
        <MudCheckBox @bind-Value="_outline" Label="Outline"/>
        <MudCheckBox @bind-Value="_delimiters" Label="Delimiters" />
        <MudCheckBox @bind-Value="_disabled" Label="Disabled" />
    </MudStack>
</MudStack>
@code{
    bool _dense = false;
    bool _rounded = false;
    bool _checkMark = false;
    bool _outline = true;
    bool _delimiters = true;
    bool _fixedContent = false;
    bool _disabled = false;
}
Selection Mode

MudToggleGroup has three different selection modes: SelectionMode.SingleSelection, SelectionMode.MultiSelection and SelectionMode.ToggleSelection. Single selection is the default and allows only one choice to be selected at the same time, just like in a radio group. With multi-selection many items can be selected at the same time or none. Toggle-selection is an exclusive single selection which allows toggling off the selected value so that nothing is selected.

Single Selection

Value: Yes

Yes

No

Don't know


Multi Selection

Values: Vegan Menu, Carbon Offset

Extra Bag

Vegan Menu

Carbon Offset


Toggle Selection

Value: null

Coffee (1)

Tee (2)

Water (3)

<MudStack>
    <MudStack>
        <MudText>Single Selection</MudText>
        <MudText>Value: @_value1</MudText>
        <MudToggleGroup T="string" SelectionMode="SelectionMode.SingleSelection" @bind-Value="_value1" Color="Color.Primary" CheckMark FixedContent>
            <MudToggleItem Value="@("Yes")" Text="Yes" />
            <MudToggleItem Value="@("No")" Text="No" />
            <MudToggleItem Value="@("Don't know")" Text="Don't know" />
        </MudToggleGroup>
    </MudStack>

    <MudDivider />

    <MudStack>
        <MudText>Multi Selection</MudText>
        <MudText>Values: @string.Join(", ", _value2 ?? new List<string>())</MudText>
        <MudToggleGroup T="string" SelectionMode="SelectionMode.MultiSelection" @bind-Values="_value2" Color="Color.Secondary" CheckMark>
            <MudToggleItem Value="@("Extra Bag")" UnselectedIcon="@Icons.Material.Filled.CheckBoxOutlineBlank" SelectedIcon="@Icons.Material.Filled.CheckBox"/>
            <MudToggleItem Value="@("Vegan Menu")" UnselectedIcon="@Icons.Material.Filled.CheckBoxOutlineBlank" SelectedIcon="@Icons.Material.Filled.CheckBox" />
            <MudToggleItem Value="@("Carbon Offset")" UnselectedIcon="@Icons.Material.Filled.CheckBoxOutlineBlank" SelectedIcon="@Icons.Material.Filled.CheckBox" />
        </MudToggleGroup>
    </MudStack>

    <MudDivider />

    <MudStack>
        <MudText>Toggle Selection</MudText>
        <MudText>Value: @(_value3 == null ? "null" : _value3.ToString())</MudText>
        <MudToggleGroup T="int?" SelectionMode="SelectionMode.ToggleSelection" @bind-Value="_value3" Color="Color.Tertiary" CheckMark>
            <MudToggleItem Value="@((int?)1)" Text="Coffee (1)" />
            <MudToggleItem Value="@((int?)2)" Text="Tee (2)" />
            <MudToggleItem Value="@((int?)3)" Text="Water (3)" />
        </MudToggleGroup>
    </MudStack>
</MudStack>
@code {
    private string _value1 = "Yes";
    private IEnumerable<string> _value2 = new []{ "Vegan Menu", "Carbon Offset"};
    private int? _value3;
}
Custom Selection Style

You can customize the look of selected items with SelectedClass.

Antimatter

Dark Matter

Dark Energy

<MudStack>
    <MudToggleGroup T="string" SelectedClass="@_style" @bind-Value="_value">
        <MudToggleItem Value="@("Antimatter")" />
        <MudToggleItem Value="@("Dark Matter")" />
        <MudToggleItem Value="@("Dark Energy")" />
    </MudToggleGroup>

    <MudSelect T="string" @bind-Value="_style" Variant="Variant.Outlined">
        <MudSelectItem Value="@("mud-theme-primary")" />
        <MudSelectItem Value="@("mud-theme-secondary")" />
        <MudSelectItem Value="@("custom-gradient")" />
        <MudSelectItem Value="@("custom-striped")" />
    </MudSelect>
</MudStack>

<style>
    .custom-gradient {
        background-image: linear-gradient(to right top, #051937, #004d7a, #008793, #00bf72, #a8eb12);
        color: white !important;
    }

    .custom-striped {
        background: repeating-linear-gradient( 45deg, #606dbc, #606dbc 10px, #465298 10px, #465298 20px );
        color: white !important;
    }
</style>
@code {
    private string _style = "custom-striped";
    private string _value = "Antimatter";
}

Copyright © 2020-2024 MudBlazor.

Powered by .NET 8.0.8

An error has occurred. This application may no longer respond until reloaded. Reload 🗙