Button

in namespace DotVVM.Controls.Tailwind.Controls

Renders a styled button.

Usage & Scenarios

Renders a styled button with semantic variants, sizes, icons, enabled state, commands, and optional submit behavior. Use inner content instead of Text when you need richer markup.

Sample 1: Button Types, Sizes, and Icons

Demonstrates all button types, size variants, icon support, click commands, and disabled state.


<div class="flex flex-col gap-6">
    <div class="flex gap-2 flex-wrap">
        <t:Button Type="Default" Text="Default" />
        <t:Button Type="Primary" Text="Primary" />
        <t:Button Type="Secondary" Text="Secondary" />
        <t:Button Type="Success" Text="Success" />
        <t:Button Type="Warning" Text="Warning" />
        <t:Button Type="Danger" Text="Danger" />
        <t:Button Type="Info" Text="Info" />
        <t:Button Type="Ghost" Text="Ghost" />
        <t:Button Type="Link" Text="Link" />
    </div>
    
    <div class="flex gap-2 flex-wrap items-center">
        <span class="text-sm font-semibold">Sizes:</span>
        <t:Button Type="Primary" Text="Small" Size="Small" />
        <t:Button Type="Primary" Text="Default" Size="Default" />
        <t:Button Type="Primary" Text="Large" Size="Large" />
        <t:Button Type="Primary" Text="Extra Large" Size="ExtraLarge" />
    </div>
</div>

Click action

This sample demonstrates handling the Click command and updating a counter on the page.


<div class="flex flex-col gap-4">
    <div class="flex items-center gap-4">
        <t:Button Type="Primary" Text="Click me" Click="{command: IncrementClick()}" Size="Large" />
        <span class="text-lg font-semibold">Clicked: {{value: ClickCount}} times</span>
    </div>
</div>

using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public int ClickCount { get; set; }

    public void IncrementClick()
    {
        ClickCount++;
    }
}

Buttons with Icons

Demonstrates buttons with HeroIcons, showing both Start (default) and End icon positions.


<div class="flex gap-2 flex-wrap">
    <t:Button Type="Primary" Text="Add" Icon="Plus" />
    <t:Button Type="Danger" Text="Delete" Icon="Trash" />
    <t:Button Type="Default" Text="Filter" Icon="Funnel" />
    <t:Button Type="Success" Text="Save" Icon="Check" />
    <t:Button Type="Warning" Text="Download" Icon="ArrowDownTray" IconPosition="End" />
</div>

Bindable Enabled State

Shows how to bind the Button's Enabled state to a checkbox property, allowing dynamic enable/disable.


<div class="flex flex-col gap-4">
    <div class="flex items-center gap-4">
        <t:CheckBoxFormField Checked="{value: IsButtonEnabled}" Text="Enable button" />
        <t:Button Type="Primary" Text="Toggle Me" Enabled="{value: IsButtonEnabled}" />
    </div>
</div>

using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public bool IsButtonEnabled { get; set; } = true;
}

Bindable Button Text

Demonstrates binding the Button's Text property to a TextBox input, allowing users to dynamically change the button label.


<div class="flex flex-col gap-4">
    <div class="flex items-center gap-4">
        <t:TextBoxFormField LabelText="Button text" Text="{value: ButtonText}" />
        <t:Button Type="Primary" Text="{value: ButtonText}" />
    </div>
</div>

using DotVVM.Framework.ViewModel;

public class ViewModel : DotvvmViewModelBase
{
    public string ButtonText { get; set; } = "Click me!";
}

Submit and disabled buttons

Shows IsSubmitButton and Enabled on the same control. IsSubmitButton="true" changes the rendered HTML button type to submit, while Enabled="false" disables the button.


<div class="flex gap-2 flex-wrap items-center">
    <t:Button Type="Primary" Text="Submit" IsSubmitButton="true" />
    <t:Button Type="Default" Text="Regular button" />
    <t:Button Type="Primary" Text="Disabled submit" IsSubmitButton="true" Enabled="false" />
    <t:Button Type="Danger" Text="Disabled action" Enabled="false" />
</div>

Properties

Name Type Description Notes Default Value
property icon Enabled Boolean Gets or sets whether the button is interactive.
attribute
inner element
static value
bindable
default
True
property icon Icon HeroIcon Gets or sets the optional icon displayed inside the button. It cannot be combined with template-based content.
attribute
inner element
static value
bindable
default
null
property icon IconPosition IconPosition Gets or sets whether the icon is rendered before or after the button text.
attribute
inner element
static value
bindable
default
Start
property icon IsSubmitButton Boolean Gets or sets whether the button is rendered with type="submit".
attribute
inner element
static value
bindable
default
False
property icon Size ControlSize Gets or sets the size variant of the button.
attribute
inner element
static value
bindable
default
Default
property icon Template ITemplate Gets or sets the custom content rendered inside the button.
attribute
inner element
static value
bindable
default
null
property icon Text String Gets or sets the text displayed inside the button.
attribute
inner element
static value
bindable
default
null
property icon Type ButtonType Gets or sets the visual style variant of the button.
attribute
inner element
static value
bindable
default
Default
property icon Visible Boolean Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
event icon Click ICommandBinding Gets or sets the command executed when the button is clicked.

HTML produced by the control