Forms
TwToggleGroup
TwToggleGroup is a set of toggle buttons with single or multiple selection, for alignment, view modes or filters. Bind Value or Values, or set Multiple.
Last updated
Single selection
By default one item can be pressed at a time. Bind it with
@bind-Value; each TwToggleGroupItem sets the Value it stands for.Multiple selection
Set
Multiple to let any number of items be pressed, and bind them with @bind-Values.Deselectable
A single-select group keeps its selection, like a radio group. Set
Deselectable so pressing the pressed item releases it, leaving none pressed.Variants
ToggleVariant.Text (the default) sets the items on a filled bar. ToggleVariant.Outlined draws a border around the group instead.RAZOR
<div class="flex flex-wrap items-center gap-4">
<TwToggleGroup Value="@("grid")" AriaLabel="View (filled bar)">
<TwToggleGroupItem Value="@("grid")" Icon="Icon.Grid" Label="Grid" />
<TwToggleGroupItem Value="@("list")" Icon="Icon.List_Ul" Label="List" />
</TwToggleGroup>
<TwToggleGroup Value="@("grid")" Variant="ToggleVariant.Outlined" AriaLabel="View (outlined)">
<TwToggleGroupItem Value="@("grid")" Icon="Icon.Grid" Label="Grid" />
<TwToggleGroupItem Value="@("list")" Icon="Icon.List_Ul" Label="List" />
</TwToggleGroup>
</div>Sizes
Set
Size on the group to size every item.RAZOR
<div class="flex flex-wrap items-center gap-4">
<TwToggleGroup Size="Size.Sm" Multiple Values="@(new[] { "bold" })" AriaLabel="Small formatting">
<TwToggleGroupItem Value="@("bold")" Icon="Icon.Type_Bold" AriaLabel="Bold" />
<TwToggleGroupItem Value="@("italic")" Icon="Icon.Type_Italic" AriaLabel="Italic" />
</TwToggleGroup>
<TwToggleGroup Size="Size.Md" Multiple Values="@(new[] { "bold" })" AriaLabel="Medium formatting">
<TwToggleGroupItem Value="@("bold")" Icon="Icon.Type_Bold" AriaLabel="Bold" />
<TwToggleGroupItem Value="@("italic")" Icon="Icon.Type_Italic" AriaLabel="Italic" />
</TwToggleGroup>
<TwToggleGroup Size="Size.Lg" Multiple Values="@(new[] { "bold" })" AriaLabel="Large formatting">
<TwToggleGroupItem Value="@("bold")" Icon="Icon.Type_Bold" AriaLabel="Bold" />
<TwToggleGroupItem Value="@("italic")" Icon="Icon.Type_Italic" AriaLabel="Italic" />
</TwToggleGroup>
</div>Colors
Set
Color on the group to tint every pressed item, or on a TwToggleGroupItem to tint just that one.RAZOR
<TwToggleGroup Multiple Values="@(new[] { "wifi", "bluetooth" })" Color="Color.Primary" Variant="ToggleVariant.Outlined" AriaLabel="Connections">
<TwToggleGroupItem Value="@("wifi")" Icon="Icon.Wifi" Label="Wi-Fi" />
<TwToggleGroupItem Value="@("bluetooth")" Icon="Icon.Bluetooth" Label="Bluetooth" />
<TwToggleGroupItem Value="@("airplane")" Icon="Icon.Airplane" Label="Flight mode" Color="Color.Warning" />
</TwToggleGroup>Vertical
Set
Vertical to stack the items. The arrow keys work in either direction.RAZOR
<TwToggleGroup Value="@("week")" Vertical AriaLabel="Calendar view">
<TwToggleGroupItem Value="@("day")" Label="Day" />
<TwToggleGroupItem Value="@("week")" Label="Week" />
<TwToggleGroupItem Value="@("month")" Label="Month" />
</TwToggleGroup>Disabled
Set
Disabled on the group to disable every item, or on a TwToggleGroupItem to disable just that one. The arrow keys skip disabled items.RAZOR
<div class="flex flex-wrap items-center gap-4">
<TwToggleGroup Value="@("left")" Disabled AriaLabel="Alignment (disabled)">
<TwToggleGroupItem Value="@("left")" Icon="Icon.Text_Left" AriaLabel="Align left" />
<TwToggleGroupItem Value="@("center")" Icon="Icon.Text_Center" AriaLabel="Align center" />
</TwToggleGroup>
<TwToggleGroup Value="@("left")" AriaLabel="Alignment (one disabled)">
<TwToggleGroupItem Value="@("left")" Icon="Icon.Text_Left" AriaLabel="Align left" />
<TwToggleGroupItem Value="@("center")" Icon="Icon.Text_Center" AriaLabel="Align center" Disabled />
<TwToggleGroupItem Value="@("right")" Icon="Icon.Text_Right" AriaLabel="Align right" />
</TwToggleGroup>
</div>View mode selector
Bind an enum to switch between views of the same content.
Report.pdf
Budget.xlsx
Photo.jpg
Notes.txt
Slides.pptx
Logo.svg
Accessibility
A single-select group is a
radiogroup of radio items with aria-checked, following the WAI-ARIA radio group pattern: moving to an item with the arrow keys also selects it. A Multiple group is a group of toggle buttons with aria-pressed, following the toolbar pattern: the arrow keys move focus and Space or Enter presses the focused item. Either way the group is a single Tab stop, and Arrow Left and Arrow Right swap in a right to left layout. Name the group with AriaLabel or AriaLabelledBy, and give icon-only items an AriaLabel.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwToggleTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
Inherited from TwToggle - this component reuses that theme rather than defining its own.
| Property | Type | Controls |
|---|---|---|
ToggleRounded |
Rounded? | |
DefaultVariant |
ToggleVariant? | |
Base |
string | |
Sm |
string | |
Md |
string | |
Lg |
string | |
IconSm |
string | |
IconMd |
string | |
IconLg |
string | |
Unpressed |
string | |
Hover |
string | |
Pressed |
string | |
GroupPressed |
string | |
PressedForcedColors |
string | |
Outlined |
string | |
Disabled |
string | |
GroupBase |
string | |
GroupHorizontal |
string | |
GroupVertical |
string | |
GroupText |
string | |
GroupOutlined |
string |
Global Theme Configuration
These reuse shared design tokens configured once on
TwBlazorTheme, rather than being unique to this component.
| Property | Type | Controls |
|---|---|---|
Colors |
TwBlazorPalette |
Full reference: TwToggleTheme on the API docs.