Class TwToggle
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
A two-state button that is either pressed (on) or not pressed (off), such as a bold button in a text formatting toolbar.
public class TwToggle : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent
- Inheritance
-
TwToggle
- Implements
- Inherited Members
Remarks
Renders a native button with aria-pressed, so screen readers announce it as a toggle button and
Enter or Space switches it. Bind the state with @bind-Pressed. The pressed state is also exposed as
data-state="on" or data-state="off", so a Class can style
it with Tailwind's data-[state=on]: variant. A toggle that shows only an icon needs an
AriaLabel; keep the label the same in both states, since the pressed
state is announced separately. Use TwToggleGroup<T> for a set of related toggles.
Constructors
TwToggle()
public TwToggle()
Properties
ChildContent
Gets or sets custom content shown in the toggle in place of Label.
[Parameter]
public RenderFragment? ChildContent { get; set; }
Property Value
Color
Gets or sets the color of the toggle while it is pressed, and of its focus ring.
[Parameter]
public Color? Color { get; set; }
Property Value
Remarks
If not set, a pressed toggle is drawn in a neutral tint.
Disabled
Gets or sets whether the toggle is disabled. A disabled toggle cannot be focused or switched.
[Parameter]
public bool Disabled { get; set; }
Property Value
Icon
Gets or sets the icon shown before the label, or on its own for an icon-only toggle.
[Parameter]
public Icon? Icon { get; set; }
Property Value
- Icon?
Label
Gets or sets the text shown in the toggle. Ignored when ChildContent is set.
[Parameter]
public string Label { get; set; }
Property Value
Pressed
Gets or sets whether the toggle is pressed (on).
[Parameter]
public bool Pressed { get; set; }
Property Value
PressedChanged
Gets or sets the callback invoked with the new state when the toggle is pressed or released.
[Parameter]
public EventCallback<bool> PressedChanged { get; set; }
Property Value
Size
Gets or sets the size of the toggle. Defaults to Md.
[Parameter]
public Size? Size { get; set; }
Property Value
- Size?
Tooltip
Gets or sets the text of a tooltip shown when the toggle is hovered or keyboard-focused.
[Parameter]
public string? Tooltip { get; set; }
Property Value
Remarks
The tooltip only describes the toggle, so an icon-only toggle still needs an AriaLabel.
Variant
Gets or sets how the toggle is drawn while it is not pressed.
[Parameter]
public ToggleVariant? Variant { get; set; }
Property Value
Remarks
If not set, uses DefaultVariant, which defaults to Text.
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder