Skip to content
GitHub11 stars

Toggle Group

A set of two-state buttons that can be toggled on or off.

<ToggleGroup Variant="ToggleVariant.Outline" Multiple="true">
    <ToggleGroupItem Value="bold" aria-label="Toggle bold"><Icon Data="LucideIcons.Bold" /></ToggleGroupItem>
    <ToggleGroupItem Value="italic" aria-label="Toggle italic"><Icon Data="LucideIcons.Italic" /></ToggleGroupItem>
    <ToggleGroupItem Value="strikethrough" aria-label="Toggle strikethrough"><Icon Data="LucideIcons.Underline" /></ToggleGroupItem>
</ToggleGroup>

Installation

dnx Blazix.Cli add toggle-group

Usage

<ToggleGroup type="single">
    <ToggleGroupItem Value="a">A</ToggleGroupItem>
    <ToggleGroupItem Value="b">B</ToggleGroupItem>
    <ToggleGroupItem Value="c">C</ToggleGroupItem>
</ToggleGroup>

Composition

Use the following composition to build a ToggleGroup:

ToggleGroup
├── ToggleGroupItem
└── ToggleGroupItem

Outline

Use variant="outline" for an outline style.

<ToggleGroup Variant="ToggleVariant.Outline" Value="@(["all"])">
    <ToggleGroupItem Value="all" aria-label="Toggle all">All</ToggleGroupItem>
    <ToggleGroupItem Value="missed" aria-label="Toggle missed">Missed</ToggleGroupItem>
</ToggleGroup>

Size

Use the Size parameter to change the size of the toggle group.

<div class="flex flex-col gap-4">
    <ToggleGroup Size="ToggleSize.Sm" Value="@(["top"])" Variant="ToggleVariant.Outline">
        <ToggleGroupItem Value="top" aria-label="Toggle top">Top</ToggleGroupItem>

Spacing

Use Spacing to add spacing between toggle group items.

<ToggleGroup Size="ToggleSize.Sm" Value="@(["top"])" Variant="ToggleVariant.Outline" Spacing="2">
    <ToggleGroupItem Value="top" aria-label="Toggle top">Top</ToggleGroupItem>
    <ToggleGroupItem Value="bottom" aria-label="Toggle bottom">Bottom</ToggleGroupItem>
    <ToggleGroupItem Value="left" aria-label="Toggle left">Left</ToggleGroupItem>
    <ToggleGroupItem Value="right" aria-label="Toggle right">Right</ToggleGroupItem>
</ToggleGroup>

Vertical

Use orientation="vertical" for vertical toggle groups.

<ToggleGroup Multiple="true" Orientation="Orientation.Vertical" Spacing="1" Value="@(["bold", "italic"])">
    <ToggleGroupItem Value="bold" aria-label="Toggle bold"><Icon Data="LucideIcons.Bold" /></ToggleGroupItem>
    <ToggleGroupItem Value="italic" aria-label="Toggle italic"><Icon Data="LucideIcons.Italic" /></ToggleGroupItem>
    <ToggleGroupItem Value="underline" aria-label="Toggle underline"><Icon Data="LucideIcons.Underline" /></ToggleGroupItem>
</ToggleGroup>

Disabled

<ToggleGroup Disabled="true">
    <ToggleGroupItem Value="bold" aria-label="Toggle bold"><Icon Data="LucideIcons.Bold" /></ToggleGroupItem>
    <ToggleGroupItem Value="italic" aria-label="Toggle italic"><Icon Data="LucideIcons.Italic" /></ToggleGroupItem>
    <ToggleGroupItem Value="strikethrough" aria-label="Toggle strikethrough"><Icon Data="LucideIcons.Underline" /></ToggleGroupItem>
</ToggleGroup>

Custom

A custom toggle group example.

Use font-normal to set the font weight.

<Field>
    <FieldLabel>Font Weight</FieldLabel>
    <ToggleGroup Value="@([_fontWeight])" ValueChanged="SetFontWeight" Variant="ToggleVariant.Outline" Spacing="2" Size="ToggleSize.Lg" Class="flex-wrap">

RTL

To enable RTL support in Blazix, see the RTL configuration guide.

Translated with AI for the demo, so it may have mistakes.

<ToggleGroup Variant="ToggleVariant.Outline" @bind-Value="_value">
    <ToggleGroupItem Value="list">@T.List</ToggleGroupItem>
    <ToggleGroupItem Value="grid">@T.Grid</ToggleGroupItem>

API Reference

ToggleGroup

ParameterTypeDefault
Render RenderFragment<ToggleGroupRenderProps>? -
Value IReadOnlyList<string>? -
ValueChanged EventCallback<IReadOnlyList<string>?> -
OnValueChange EventCallback<ValueChangeEventArgs<IReadOnlyList<string>>> -
Multiple bool false
Disabled bool false
Orientation Orientation Orientation.Horizontal
LoopFocus bool true
Variant ToggleVariant? -
Size ToggleSize? -
Spacing int 2
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

ToggleGroupItem

ParameterTypeDefault
Render RenderFragment<ToggleRenderProps>? -
NativeButton bool? -
Valuerequired string -
Disabled bool false
Variant ToggleVariant ToggleVariant.Default
Size ToggleSize ToggleSize.Default
Class string? -
ChildContent RenderFragment? -

Other attributes are passed to the element it renders.

Changelog

2026-05-17 Default Spacing

Changed the default Spacing from 0 to 2 so toggle groups render with space between items by default. Use Spacing="0" for connected items.