ButtonGroup

in namespace DotVVM.Controls.Tailwind.Controls

Renders a group of buttons displayed side-by-side with shared borders and no gaps. Supports hardcoded children (place <t:Button> elements inside) or DataSource mode.

Usage & Scenarios

Renders multiple Tailwind Button controls as a connected group. You can place buttons manually or generate them from DataSource with the Item* mappings.

Sample 2: Basic Hardcoded Button Group

Demonstrates a simple button group with three basic buttons placed directly inside the ButtonGroup control.

<div class="flex gap-2">
    <t:ButtonGroup>
        <t:Button Type="Default" Text="Left" />
        <t:Button Type="Default" Text="Center" />
        <t:Button Type="Default" Text="Right" />
    </t:ButtonGroup>
</div>

Sample 3: Mixed Button Types with Icons

Shows a button group with different button types (Primary, Warning, Danger) and HeroIcons assigned to each button.

<div class="flex gap-2">
    <t:ButtonGroup>
        <t:Button Type="Primary" Text="Save" Icon="Check" />
        <t:Button Type="Warning" Text="Edit" Icon="PencilSquare" />
        <t:Button Type="Danger" Text="Delete" Icon="Trash" />
    </t:ButtonGroup>
</div>

Sample 4: DataSource with Click Commands

Demonstrates button group generation from a DataSource collection, with ItemClick command that tracks which button was clicked.

<div class="flex flex-col gap-4 items-start">
    <t:ButtonGroup DataSource="{value: Actions}" ItemText="{value: _this}" ItemClick="{command: _parent.ItemClicked(_this)}" />
    <p class="text-sm">Last clicked: <strong>{{value: LastClicked}}</strong></p>
</div>

using DotVVM.Framework.ViewModel;
using System;

public class ViewModel : DotvvmViewModelBase
{
    public List<string> Actions { get; set; } = new() { "Copy", "Cut", "Paste" };
    
    public string LastClicked { get; set; } = "(none)";
    
    public void ItemClicked(string item)
    {
        LastClicked = $"{item} clicked at {DateTime.Now:HH:mm:ss}";
    }
}

Properties

Name Type Description Notes Default Value
property icon DataSource IValueBinding<IEnumerable<Object>> Gets or sets the collection used to generate buttons when data-binding is used.
attribute
inner element
static value
bindable
default
null
property icon ItemEnabled Boolean Gets or sets whether each generated button is enabled.
attribute
inner element
static value
bindable
default
True
property icon ItemIcon HeroIcon Gets or sets the icon displayed in each generated button when DataSource is used.
attribute
inner element
static value
bindable
default
null
property icon ItemIconPosition IconPosition Gets or sets whether the icon is rendered before or after the generated button text.
attribute
inner element
static value
bindable
default
Start
property icon ItemIsSubmitButton Boolean Gets or sets whether each generated button is rendered as a submit button.
attribute
inner element
static value
bindable
default
False
property icon Items List<Button> Gets or sets the buttons rendered inside the group.
attribute
inner element
static value
bindable
default
null
property icon ItemSize ControlSize Gets or sets the size applied to each generated button.
attribute
inner element
static value
bindable
default
Default
property icon ItemTemplate ITemplate Gets or sets the template of generated buttons when DataSource is used.
attribute
inner element
static value
bindable
default
null
property icon ItemText String Gets or sets the text of generated buttons when DataSource is used.
attribute
inner element
static value
bindable
default
null
property icon ItemType ButtonType Gets or sets the visual style applied to each generated 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 ItemClick ICommandBinding Gets or sets the command executed when a generated button is clicked.

HTML produced by the control