ToggleGroup
Since 0.1.0-alpha.22Toggles 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
@* 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>
{
private bool _bold = true;
private bool _italic;
private bool _underline;
}Add this example to a page with the izzy CLI:
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
| Feature | Static | Interactive |
|---|---|---|
| Everything | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Accessibility
- It renders a
divwithrole="group", named byLabel, 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
| Prop | Type | Default |
|---|---|---|
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). | bool | true |
OrientationLays the buttons out in a row (the default) or a column. | Orientation | Orientation.Horizontal |
FullWidthStretches the group to its container's width, sharing it among the buttons. | bool | false |
ChildContentThe buttons. | RenderFragment? |
Plus 17 item props and 4 common props.
Full APISee 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.