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 | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| DataSource | IValueBinding<IEnumerable<Object>> | Gets or sets the collection used to generate buttons when data-binding is used. |
attribute
bindable
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| ItemEnabled | Boolean | Gets or sets whether each generated button is enabled. |
attribute
static value
bindable
|
True | |
| ItemIcon | HeroIcon | Gets or sets the icon displayed in each generated button when DataSource is used. |
attribute
static value
bindable
|
null | |
| ItemIconPosition | IconPosition | Gets or sets whether the icon is rendered before or after the generated button text. |
attribute
static value
bindable
|
Start | |
| ItemIsSubmitButton | Boolean | Gets or sets whether each generated button is rendered as a submit button. |
attribute
static value
|
False | |
| Items | List<Button> | Gets or sets the buttons rendered inside the group. |
inner element
static value
default
|
null | |
| ItemSize | ControlSize | Gets or sets the size applied to each generated button. |
attribute
static value
bindable
|
Default | |
| ItemTemplate | ITemplate | Gets or sets the template of generated buttons when DataSource is used. |
inner element
static value
|
null | |
| ItemText | String | Gets or sets the text of generated buttons when DataSource is used. |
attribute
static value
bindable
|
null | |
| ItemType | ButtonType | Gets or sets the visual style applied to each generated button. |
attribute
static value
bindable
|
Default | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |
Events
| Name | Type | Description | |
|---|---|---|---|
| ItemClick | ICommandBinding | Gets or sets the command executed when a generated button is clicked. |