Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

ToggleGroup

Since 0.1.0-alpha.22
Joins toggle buttons that any of can be on, such as text styles.

Toggles that belong together, such as bold, italic and underline: any of them can be on. It names the set and joins the buttons into one control; Accent, Variant and Size here are the defaults for the ToggleButtons inside. Each toggle keeps its own value. For one choice of several, such as text alignment (a single-selection toggle group), use SegmentedControl<T>.

Text styles

To make toggles that belong together, such as bold, italic and underline, read as one control, put them in a ToggleGroup and name it with Label. Each toggle keeps its own value, and any of them can be on.

Always Interactive

Preview

The quick brown fox

Code

Usage.razor
@* Text styles: each toggle turns on and off on its own; the group joins them and names the set. *@
<Stack Gap="3" Align="Align.Center">
    <ToggleGroup Label="Text style">
        <ToggleButton Icon="Lucide.Bold" Label="Bold" IconOnly @bind-Value="_bold" />
        <ToggleButton Icon="Lucide.Italic" Label="Italic" IconOnly @bind-Value="_italic" />
        <ToggleButton Icon="Lucide.Underline" Label="Underline" IconOnly @bind-Value="_underline" />
    </ToggleGroup>
    <TextBlock Weight="@(_bold ? FontWeight.Bold : FontWeight.Normal)" Italic="_italic" Decoration="@(_underline ? TextDecoration.Underline : null)">The quick brown fox</TextBlock>
</Stack>

@code {
    private bool _bold = true;
    private bool _italic;
    private bool _underline;
}

Add this example to a page with the izzy CLI:

bash
izzy add component ToggleGroup --at <file>:<line>

For one choice of several, such as text alignment, use a SegmentedControl: the single-selection toggle group of other libraries.

Mode support

What works in each mode, ToggleGroup
FeatureStaticInteractive
EverythingYesYes

Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

Accessibility

  • It renders a div with role="group", named by Label, such as "Text style".
  • Each toggle is its own checkbox and tab stop, so Tab moves between them and Space toggles one.
  • For one choice among several, such as text alignment, use SegmentedControl<T>, which is a radio group.

Parameters

ToggleGroup parameters
PropTypeDefault
LabelWhat the buttons have in common, for screen readers: "Text alignment".string?
AccentThe buttons' accent, unless a button sets its own.Accent?
VariantThe buttons' variant, unless a button sets its own.ButtonVariant?
SizeThe buttons' size, unless a button sets its own.ControlSize?
AttachedJoins the buttons into one control with shared borders (the default).booltrue
OrientationLays the buttons out in a row (the default) or a column.OrientationOrientation.Horizontal
FullWidthStretches the group to its container's width, sharing it among the buttons.boolfalse
ChildContentThe buttons.RenderFragment?

See also

  • ToggleButton: a button that stays on or off: a checkbox drawn as a button.
  • SegmentedControl: lets the user pick one of a few choices from joined buttons.
  • CheckboxGroup: lets the user pick several choices from a list of checkboxes.

Connection lost

Rejoining the server…