# Blazor Split Button

URL: https://flexcoreui.com/demo/split-button  
Section: Components  
Controls: SplitButtonControl, SplitButtonItem  
Keywords: split button, dropdown button, menu button

A Blazor split button: one click for the default action, a caret for the alternatives, built from items or your own markup.

## Documentation

### Parameters

| Name | Type | Default | Description |
|---|---|---|---|
| Text | string? | null | Label of the main half; wins over ChildContent, and names both halves when Title is not set. |
| IconCss | string? | null | Classes for an icon before the main half's label, such as bi bi-envelope. |
| ChildContent | RenderFragment? | null | Your own markup for the main half, such as a count; used when Text is not set. |
| Items | IList<SplitButtonItem>? | null | The menu entries, in order. A new list re-renders the menu, so it can follow page state. |
| MenuContent | RenderFragment? | null | Your own markup after the items, such as options to check; clicks inside it keep the menu open. |
| Disabled | bool | false | Disables both halves and hides the menu; the button fades to 60% and ignores the pointer. A menu left open is only hidden: it shows again when the control is enabled. |
| Title (base) | string? | null | Tooltip and accessible name of the main half; the caret gets the same text plus " options". Falls back to Text; with neither, the caret is named "More options". |
| Enabled (base) | bool | true | Not read. Use Disabled; Enabled="false" leaves both halves active. |
| Visible (base) | bool | true | Not read. Visible="false" does not hide the control. |
| Id (base) | string? | null | Never rendered. An id attribute binds to this parameter, so it does not reach the host either. |
| CssClass / Style (base) | string? | null | Appended to, and inline style on, the host element. |
| Tag / Data / Parent (base) |  | null | Accepted but not rendered. |
| (unmatched attributes) | Dictionary<string,object> |  | Forwarded to the host <div>, not to the buttons. |

### Events

| Name | Type | Description |
|---|---|---|
| OnClick | none | A click, Enter or Space on the main half. No payload. |
| OnItemClick | SplitButtonItem | An enabled entry was picked; the menu has already closed. Read its Value rather than matching on Text. |

### Item

| Name | Type | Default | Description |
|---|---|---|---|
| Text | string | "" | The entry's label. |
| IconCss | string? | null | Classes for an icon before the label. |
| Value | object? | null | Any payload; read it in OnItemClick instead of matching on Text. |
| Disabled | bool | false | Drawn at half opacity and not clickable. |
| ctor |  |  | new(text, iconCss, value, disabled) with all but text optional, or new() with property setters; it is a class. |

### Css

| Name | Description |
|---|---|
| fx-split-button-host | Inline-flex wrapper; the menu is positioned against it. Gets fx-split-button-disabled when disabled. |
| fx-split-button-main · fx-split-button-toggle | The two halves. Filled with --fx-split-btn-bg, shared border, rounded outer corners. |
| fx-split-button-dropdown | The menu: white panel under the control, right-aligned, 150px minimum. |
| fx-split-button-item | One entry; .disabled halves its opacity. |
| fx-split-button-backdrop | Full-screen transparent layer that closes the menu on click. |

### Vars

| Name | Type | Description |
|---|---|---|
| --fx-split-btn-bg / --fx-split-btn-color | #2563eb / #ffffff | Fill and text of both halves. |
| --fx-split-btn-border-color | #1d4ed8 | Border of both halves. |
| --fx-split-btn-hover-bg | #1d4ed8 | Fill of the half under the pointer. |
| --fx-split-btn-divider-color | rgba(255, 255, 255, 0.25) | Line between the two halves. |
| --fx-split-btn-radius | 6px | Outer corners of the control and corners of the menu. |
| --fx-split-btn-menu-bg / --fx-split-btn-menu-border-color | #ffffff / #e2e8f0 | Menu panel fill and border. |
| --fx-split-btn-menu-color / --fx-split-btn-menu-hover-bg | #1e293b / #f1f5f9 | Menu entry text, and its fill under the pointer. |

## Examples

### Basic

```razor
@using Fx.ControlKit

<div class="sb two">
    <div class="demo-row">
        <SplitButtonControl Text="Send reply" IconCss="bi bi-envelope" Items="_replyItems" Disabled="_solved"
                            OnClick="@(() => Did("Reply emailed to Albus Door"))" OnItemClick="ReplyItem" />
        <ButtonControl CssClass="btn-sm" OnClick="() => _solved = !_solved">@(_solved ? "Reopen ticket" : "Mark solved")</ButtonControl>
        <BadgeControl Text="@(_solved ? "Solved" : "Open")" Variant="@(_solved ? BadgeVariant.Success : BadgeVariant.Info)" />
    </div>
    <div class="log-col">
        <div class="log-head"><span class="bi bi-clock-history" aria-hidden="true"></span>Activity
            <ButtonControl BareStyle="true" CssClass="log-clear" Disabled="@(_log.Count == 0)" OnClick="() => _log.Clear()">Clear</ButtonControl>
        </div>
        <ul class="log" role="status">
            @foreach (var line in _log)
            {
                <li>@line</li>
            }
            @if (_log.Count == 0)
            {
                <li class="log-empty">No activity to show</li>
            }
        </ul>
    </div>
</div>
```

```csharp
// Basic
private readonly List<SplitButtonItem> _replyItems = new()
{
    new("Send with the router guide", "bi bi-file-earmark-pdf", value: "guide"),
    new("Send a copy to me", "bi bi-person", value: "copy"),
    new("Add as internal note", "bi bi-journal-text", value: "note"),
    new("Reply by chat", "bi bi-chat-dots", disabled: true),
};
private bool _solved;
private readonly List<string> _log = new() { "Reply to Albus Door on TKT-1042 is ready" };
private void Did(string line) => _log.Insert(0, line);
private void ReplyItem(SplitButtonItem item) => Did(item.Value switch
{
    "guide" => "Reply emailed with the router guide",
    "copy" => "Copy of the reply sent to the agent",
    _ => "Internal note added to TKT-1042",
});
```

### Menu content

```razor
@using Fx.ControlKit

<div class="sb">
    <div class="demo-row">
        <SplitButtonControl Text="Approve refund" IconCss="bi bi-check2-circle" Items="_refundItems"
                            OnClick="@(() => Refund("Approved"))" OnItemClick="@(i => Refund(i.Text))">
            <MenuContent>
                <div class="menu-options">
                    <CheckBoxControl @bind-Checked="_lateFee" Label="Late fee, $15" />
                    <CheckBoxControl @bind-Checked="_goodwill" Label="Goodwill credit, $10" />
                </div>
            </MenuContent>
        </SplitButtonControl>
        <span class="total"><span class="bi bi-receipt" aria-hidden="true"></span>Refund for TKT-1043: @Total.ToString("C0")</span>
    </div>
    <p class="result" role="status">@_refundStatus</p>
</div>
```

```csharp
// Menu content
private readonly List<SplitButtonItem> _refundItems = new() { new("Hold for review", "bi bi-hourglass-split") };
private bool _lateFee = true, _goodwill;
private decimal Total => 59 + (_lateFee ? 15 : 0) + (_goodwill ? 10 : 0);
private string _refundStatus = "Last decision: none yet";
private void Refund(string how) => _refundStatus = $"Last decision: {how} at {Total:C0}";
```

### Child content

```razor
@using Fx.ControlKit

<div class="sb">
    <div class="demo-row">
        <SplitButtonControl Title="Remind all" Items="RemindItems" Disabled="@(_waiting.Count == 0)"
                            Style="--fx-split-btn-bg: #b45309; --fx-split-btn-border-color: #92400e; --fx-split-btn-hover-bg: #92400e;"
                            OnClick="RemindAll" OnItemClick="@(i => Remind((string)i.Value!))">
            <span class="bi bi-bell"></span> Remind <span class="count">@_waiting.Count</span>
        </SplitButtonControl>
        <ButtonControl CssClass="btn-sm" OnClick="ResetWaiting">Start over</ButtonControl>
    </div>
    <p class="result" role="status">@(_waiting.Count == 0 ? "Everyone has been reminded" : $"Still to remind: {string.Join(", ", _waiting)}")</p>
</div>
```

```csharp
// Child content
private List<string> _waiting = new() { "Ron Measly", "Luna Goodlove", "Neville Longbutton" };
private List<SplitButtonItem> RemindItems => _waiting.Select(n => new SplitButtonItem($"Remind {n}", "bi bi-person", value: n)).ToList();
private void Remind(string name) => _waiting.Remove(name);
private void RemindAll() => _waiting.Clear();
private void ResetWaiting() => _waiting = new() { "Ron Measly", "Luna Goodlove", "Neville Longbutton" };
```

