Toggle buttons

ToggleButtonControl · ButtonGroupControl

A button that stays pressed, and a group that picks one value or many.

Overview

ToggleButtonControl is a ButtonControl with a pressed state: Selected binds two ways and the button reports aria-pressed. ButtonGroupControl lines up several such buttons from a list of SelectionItems and keeps the selection for you: one value or many, horizontal or vertical, with Arrow, Home and End moving focus between them.

Examples

#Toggle button

@bind-Selected holds the state. Icon-only toggles need Title and aria-label. Enabled="false" disables; there is no Disabled parameter on this control.

Example
Razor
C#
Format: none

#Button group

Selection="Single" replaces the selection; Multiple toggles each value. Orientation="Vertical" stacks the buttons. AllowEmpty lets the last value go; a disabled item stays in place and is skipped by the arrow keys.

Example
Razor
C#
left
mon, tue, wed, thu, fri

Documentation

ToggleButtonControl parameters

ParameterTypeDefaultDescription
SelectedboolfalsePressed state. Two-way with @bind-Selected.
SelectedChangedEventCallback<bool>—Fires after each toggle with the new state.
ChildContentRenderFragment?—Label or any markup.
IconCssstring?nullLeading icon.
OnClickEventCallback<MouseEventArgs>—Fires after the toggle and after SelectedChanged.
Enabled (base)booltruefalse disables the button. There is no Disabled parameter.
Title (base)string?nullNative tooltip. Required on icon-only toggles.
CssClass / Style (base)string?nullAppended to the inner button's classes; inline style.
(unmatched attributes)Dictionary<string,object>—Forwarded to the inner <button>: aria-*, data-*, id.

ButtonGroupControl parameters

ParameterTypeDefaultDescription
ItemsIReadOnlyList<SelectionItem>emptyButtons, in order. Values must be unique or the control throws.
ValuesIReadOnlyList<string>emptySelected values. Two-way with @bind-Values.
ValuesChangedEventCallback<IReadOnlyList<string>>—Fires after each change with the full selection.
SelectionChoiceSelectionModeSingleSingle replaces the selection; Multiple toggles the value.
OrientationFlexOrientationHorizontalHorizontal or Vertical.
AllowEmptyboolfalseWhen false the last selected value cannot be cleared.
AriaLabelstring"Button group"Accessible name of the group.
Enabled (base)booltruefalse disables every button.
Visible (base)booltruefalse renders nothing.
CssClass / Style (base)string?nullOn the group element.

SelectionItem

PropertyTypeDefaultDescription
Valuestring—Key reported in Values. Unique within the group.
Textstring—Label. Empty for icon-only buttons.
DisabledboolfalseRendered disabled and skipped by the arrow keys.
IconCssstring?nullLeading icon.
ctor—new(value, text, disabled, iconCss); it is a positional record.

Methods

MethodInputsReturnsDescription
ButtonGroupControl.SelectAsync()valueTaskSame as a click on that button: applies the current mode and raises ValuesChanged. Ignored when disabled or unknown.

CSS classes

ClassEffect
fx-toggle-button · .selectedThe toggle's button; selected fills it with the accent color and an inset shadow.
fx-button-group · .verticalInline flex row of buttons with no gap; vertical stacks them.
fx-selectedA selected button inside a group: accent fill, white text.
fx-button-group buttonSquare corners, 28px minimum height, 2px focus ring on keyboard focus.

CSS variables

VariableFallbackPurpose
--fx-accent#1c6ebf (toggle) · #2465b9 (group)Pressed fill. The two stylesheets fall back to different blues.
--fx-btn-*—Resting look, inherited from ButtonControl. See Buttons.

Keyboard and accessibility

  • Both render ButtonControl, so every button is a native <button>: Space and Enter toggle it.
  • Every button carries aria-pressed. The group has role="group" and the AriaLabel text.
  • In a group, Arrow Right or Down moves focus to the next button, Arrow Left or Up to the previous, Home and End to the first and last. Focus wraps and skips disabled items. Arrows move focus only; Space or Enter selects.
  • Icon-only toggles need Title plus aria-label.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.