Table of Contents

Class TwButton

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a configurable button component that supports custom content, navigation, and event handling in a Blazor application.

public class TwButton : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent
Inheritance
TwButton
Implements
Inherited Members

Remarks

TwButton provides a flexible button element that can display a text label or custom content, handle click events, and optionally perform navigation using a specified URL. The component supports standard button types, color customization, and can be disabled to prevent user interaction. When the Href property is set, the button renders as a link and uses NavigationManager for navigation. If both Label and ChildContent are provided, ChildContent takes precedence and replaces the label. The component is designed for use within Blazor applications and integrates with the Blazor event and navigation systems.

Constructors

TwButton()

public TwButton()

Properties

ChildContent

Gets or sets the custom content to display in the button.

[Parameter]
public RenderFragment? ChildContent { get; set; }

Property Value

RenderFragment

Remarks

When provided, this content replaces the Label parameter.

Color

Gets or sets the color theme of the button.

[Parameter]
public Color? Color { get; set; }

Property Value

Color?

Dense

Gets or sets a value indicating whether the component should be displayed in a dense layout.

[Parameter]
public bool Dense { get; set; }

Property Value

bool

Remarks

When set to true, the component uses a more compact layout, reducing spacing between elements. This can be useful for displaying more information in a limited space.

Disabled

Disables the button if set to true.

[Parameter]
public bool Disabled { get; set; }

Property Value

bool

EndIcon

Gets or sets whether to display an icon at the end of the button.

[Parameter]
public Icon? EndIcon { get; set; }

Property Value

Icon?

Href

Sets the button to use NavigationManager.

[Parameter]
public string Href { get; set; }

Property Value

string

IconButton

Gets or sets a value indicating whether padding is removed from the content.

[Parameter]
public bool IconButton { get; set; }

Property Value

bool

Remarks

When set to true, the content is displayed without additional padding, which may affect the layout and appearance of the component.

Label

Gets or sets the text label to display for the button.

[Parameter]
public string Label { get; set; }

Property Value

string

NavigationManager

[Inject]
public NavigationManager NavigationManager { get; set; }

Property Value

NavigationManager

OnClick

Gets or sets the callback that is invoked when the button is clicked.

[Parameter]
public EventCallback OnClick { get; set; }

Property Value

EventCallback

Remarks

Assign an event handler to this property to respond to click events. The callback is triggered when the user interacts with the component in a way that constitutes a click, such as pressing a mouse button or tapping on a touch device.

Plain

When true, skips the button's base structural classes (sizing/shape), typography, variant/color classes, focus ring, and shadow - leaving only Class (and the disabled/readonly cursor class) applied.

[Parameter]
public bool Plain { get; set; }

Property Value

bool

Remarks

Useful for embedding a button inside another already-styled control (e.g. a chip's close icon) where the caller wants full control over appearance instead of TwButton's default chrome.

Readonly

Makes the button readonly if set to true.

[Parameter]
public bool Readonly { get; set; }

Property Value

bool

Remarks

When true, the button cannot be clicked but will still be visible.

StartIcon

Gets or sets whether to display an icon at the start of the button.

[Parameter]
public Icon? StartIcon { get; set; }

Property Value

Icon?

Target

Gets or sets the name of the target frame or window for the navigation request.

[Parameter]
public string Target { get; set; }

Property Value

string

Type

The type of button (e.g., "button", "submit", "reset").

[Parameter]
public string Type { get; set; }

Property Value

string

Remarks

The default is "button".

Variant

Gets or sets the button variant.

[Parameter]
public ButtonVariant? Variant { get; set; }

Property Value

ButtonVariant?

Remarks

If not set, uses the global default from DefaultRounded. Default is Filled (high emphasis).

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder