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

<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">
                <MudToggleItem Value="@("One")"/>
                <MudToggleItem Value="@("Two")"/>
                <MudToggleItem Value="@("Three")"/>
            </MudToggleGroup>
                    
            <MudToggleGroup T="string" Outline="@_outline" Delimiters="@_delimiters" Dense="@_dense" Rounded="@_rounded" CheckMark="@_checkMark" FixedContent="@_fixedContent">
                <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">
                <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-Checked="@_dense" Label="Dense"/>
        <MudCheckBox @bind-Checked="@_rounded" Label="Rounded"/>
        <MudCheckBox @bind-Checked="@_checkMark" Label="CheckMark"/>
        <MudCheckBox @bind-Checked="@_fixedContent" Label="FixedContent"/>
        <MudCheckBox @bind-Checked="@_outline" Label="Outline"/>
        <MudCheckBox @bind-Checked="@_delimiters" Label="Delimiters" />
    </MudStack>
</MudStack>
@code{
    bool _dense = false;
    bool _rounded = false;
    bool _checkMark = false;
    bool _outline = true;
    bool _delimiters = true;
    bool _fixedContent = 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";
}
Custom Content

MudToggleItem supports customization of its content with a RenderFragment<bool> where the parameter conveys whether or not the item is currently selected. In the example the context variable was used to color the selected chip green.

Indie Developer

Basic
Perfect for lone wolves

Small Team

Pro
Up to five devs and two interns

Corporation

Enterprise
Unlimited edition
<MudToggleGroup  Class="mud-width-full" T="string" SelectedClass="black white-text">
    <MudToggleItem Value="@("Basic Edition")">
        <div class="mud-width-full mud-height-full">
            <div class="d-flex align-center justify-space-between flex-wrap">
                <MudText Class="ellipsis">Indie Developer</MudText>
                <MudChip Color="@(context ? Color.Success : Color.Primary)" Icon="@(context ? Icons.Material.Filled.Check : "")">Basic</MudChip>
            </div>
            <MudText Typo="Typo.subtitle2">Perfect for lone wolves</MudText>
        </div>
    </MudToggleItem>
    <MudToggleItem Value="@("Pro Edition")">
        <div class="mud-width-full mud-height-full">
            <div class="d-flex align-center justify-space-between flex-wrap">
                <MudText Class="ellipsis">Small Team</MudText>
                <MudChip Color="@(context ? Color.Success : Color.Primary)" Icon="@(context ? Icons.Material.Filled.Check : "")">Pro</MudChip>
            </div>
            <MudText Typo="Typo.subtitle2">Up to five devs and two interns</MudText>
        </div>
    </MudToggleItem>
    <MudToggleItem Value="@("Enterprise Edition")">
        <div class="mud-width-full mud-height-full">
            <div class="d-flex align-center justify-space-between flex-wrap">
                <MudText Class="ellipsis">Corporation</MudText>
                <MudChip Color="@(context ? Color.Success : Color.Primary)" Icon="@(context ? Icons.Material.Filled.Check : "")">Enterprise</MudChip>
            </div>
            <MudText Typo="Typo.subtitle2">Unlimited edition</MudText>
        </div>
    </MudToggleItem>
</MudToggleGroup>

<style>
    .ellipsis {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
    }
</style>

Copyright © 2020-2024 MudBlazor.

Powered by .NET 8.0.3

An unhandled error has occurred. Reload 🗙