# Blazor Ribbon Control

URL: https://flexcoreui.com/demo/ribbon  
Section: Components  
Controls: RibbonControl, RibbonTab, RibbonGroup, RibbonButton  
Keywords: ribbon, office ribbon, ribbon bar, command bar, ribbon menu

An Office-style ribbon for Blazor apps: a busy screen's commands in tabs and titled groups of large and small buttons.

## Documentation

### Ribbon

| Name | Type | Default | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | The RibbonTabs. |
| CssClass | string | "" | Added to the outer fx-ribbon element. |
| Collapsible | bool | false | Shows a button at the end of the strip that hides and shows the body; a double-click on a tab does the same. |
| Collapsed | bool | false | Whether the body is hidden. Two-way with @bind-Collapsed; read only when Collapsible is true. Opening a tab shows the body again. |
| CollapsedChanged | EventCallback<bool> |  | Fires when the user hides or shows the body. |

### Tab

| Name | Type | Default | Description |
|---|---|---|---|
| Title | string | "" | Text of the tab's header. A new value redraws the strip, so it can follow page state, as the traveler tab does. |
| ChildContent | RenderFragment? | null | The tab's RibbonGroups, rendered only while the tab is open. |
| Visible | bool | true | false takes the tab off the strip. If it was open, the first tab that can be opened takes over. |
| Disabled | bool | false | The tab stays on the strip and cannot be opened. |
| Parent (cascading) | RibbonControl? | null | Supplied by the enclosing RibbonControl. A tab outside one renders nothing. |

### Group

| Name | Type | Default | Description |
|---|---|---|---|
| Title | string | "" | Caption under the group, and its accessible name. No caption row when empty. |
| ChildContent | RenderFragment? | null | The group's buttons, or any other markup. |
| Visible | bool | true | false leaves the group out of the tab. |
| Disabled | bool | false | Disables every RibbonButton in the group. Other markup in the group is not affected. |

### Button

| Name | Type | Default | Description |
|---|---|---|---|
| Text | string | "" | Label. |
| Icon | string | "" | Glyph before the label, printed as text: use an emoji or a few characters. An icon-font class name shows as words, and markup is not rendered. |
| Large | bool | false | Glyph at 20px above the label, 64px wide at least. Off: a 14px glyph left of the label. |
| Tooltip | string | "" | The button's title. The label when empty. |
| Disabled | bool | false | Sets the disabled attribute and fades the button to half opacity. |
| Pressed | bool? | null | Makes the button a toggle: true draws it pressed, and either value sets aria-pressed. null is a plain button. The page keeps the state and changes it in OnClick. With DropDownContent only the pressed look applies; aria-pressed is not set. |
| DropDownContent | RenderFragment? | null | When set, a click opens this content in a panel under the button and a click outside closes it. |
| CssClass | string | "" | Extra classes on the <button>. |
| OnClick | EventCallback | none | Runs on click. With DropDownContent it runs before the panel opens or closes. |
| CloseDropDown() (method) | void |  | Closes the panel, for example after an entry is picked. Capture the button with @ref. |

### Css

| Name | Description |
|---|---|
| fx-ribbon · .fx-ribbon-collapsed | Outer box: light gray with a bottom border, 12px text. fx-ribbon-collapsed while the body is hidden. |
| fx-ribbon-tabs · fx-ribbon-tab-btn · .active | The header strip and one header; the open header joins the body below it. The strip wraps when it does not fit. |
| fx-ribbon-collapse | The hide and show button at the end of the strip. |
| fx-ribbon-body · fx-ribbon-tab-content | At least 92px tall; the open tab's groups in a row that wraps when it does not fit. |
| fx-ribbon-group · fx-ribbon-group-body · fx-ribbon-group-title | One group, at least 80px wide with a divider on its right; its buttons wrap, the 10px caption sits underneath. |
| fx-ribbon-group-disabled | Added to a group while Disabled is true. The library has no rule for it; it is a hook for your own styles. |
| fx-ribbon-button · fx-ribbon-button-large · .disabled · fx-ribbon-button-pressed | A button; transparent until hovered. Large stacks the glyph over the label; pressed fills it. |
| fx-ribbon-button-icon · fx-ribbon-button-text | The glyph and the label inside a button. |
| fx-ribbon-dd-host · fx-ribbon-dd-panel · fx-ribbon-dd-backdrop | A dropdown button's wrapper, its panel, and the transparent layer that closes it. |
| fx-ribbon-dd-caret | The ▾ after a dropdown button's label: 0.8em, 3px to the right of the text. |

### Vars

| Name | Type | Description |
|---|---|---|
| --fx-zoom | 1 | Scales every font size in the ribbon, as across the library. |
| --fx-ribbon-pressed-bg / --fx-ribbon-pressed-border-color | #dbe7fb / #9db8e8 | Fill and border of a pressed button. |
| --fx-accent | #2563eb | Color of the keyboard focus outline on tabs and buttons. |

## Examples

### Tabs

```razor
@using Fx.ControlKit

<div class="desk-ribbon">
    <RibbonControl Collapsible="true" @bind-Collapsed="_hidden">
        <RibbonTab Title="Home">
            <RibbonGroup Title="Booking">
                <RibbonButton Text="Hold" Icon="⏸️" Large="true" Tooltip="Hold the seats for 24 hours" Pressed="@_held" Disabled="@_canceled" OnClick="@(() => _held = !_held)" />
                <RibbonButton Text="Cancel" Icon="✖️" Disabled="@_canceled" OnClick="@(() => _canceled = true)" />
                <RibbonButton Text="Reopen" Icon="↩️" Disabled="@(!_canceled)" OnClick="@(() => _canceled = false)" />
            </RibbonGroup>
            <RibbonGroup>
                <div class="ribbon-options">
                    <CheckBoxControl @bind-Checked="_showPrices" Label="Show prices" />
                    <CheckBoxControl @bind-Checked="_showTotal" Label="Show total" />
                </div>
            </RibbonGroup>
        </RibbonTab>
        <RibbonTab Title="Trip">
            <RibbonGroup Title="Travel" Disabled="@_canceled">
                <RibbonButton Text="Add flight" Icon="✈️" Large="true" Disabled="@Has("Return flights")" OnClick="@(() => Add("Return flights", 420))" />
                <RibbonButton Text="Transfer" Icon="🚐" Disabled="@Has("Airport transfer")" OnClick="@(() => Add("Airport transfer", 80))" />
            </RibbonGroup>
            <RibbonGroup Title="Stay" Disabled="@_canceled">
                <RibbonButton Text="Add hotel" Icon="🏨" Large="true" Disabled="@Has("Old-town hotel, 4 nights")" OnClick="@(() => Add("Old-town hotel, 4 nights", 1120))" />
                <RibbonButton Text="Excursion" Icon="🗺️" Disabled="@Has("Guided food tour")" OnClick="@(() => Add("Guided food tour", 180))" />
                <RibbonButton Text="Insurance" Icon="🛡️" Disabled="@Has("Travel insurance")" OnClick="@(() => Add("Travel insurance", 120))" />
            </RibbonGroup>
        </RibbonTab>
        <RibbonTab Title="Documents">
            <RibbonGroup Title="Send">
                <RibbonButton @ref="_send" Text="Email" Icon="✉️" Large="true">
                    <DropDownContent>
                        @foreach (var doc in new[] { "Itinerary", "Invoice", "Tickets" })
                        {
                            <ButtonControl BareStyle="true" CssClass="ribbon-menu-item" OnClick="@(() => Send(doc))">@doc</ButtonControl>
                        }
                    </DropDownContent>
                </RibbonButton>
                <RibbonButton Text="Print" Icon="🖨️" OnClick="@(() => _sent = "Itinerary printed")" />
            </RibbonGroup>
        </RibbonTab>
        <RibbonTab Title="Reports" Disabled="true" />
    </RibbonControl>
    <div class="desk-booking" role="status">
        <div class="desk-head">
            <strong>LIS-0001 · Lisbon city break for Albus Door</strong>
            <BadgeControl Text="@(_canceled ? "Canceled" : _held ? "On hold" : "Open")" Variant="@(_canceled ? BadgeVariant.Danger : _held ? BadgeVariant.Warning : BadgeVariant.Success)" />
        </div>
        <ul class="desk-lines">
            @if (_lines.Count == 0) { <li><span>No lines yet; add them on the Trip tab.</span></li> }
            @foreach (var line in _lines)
            {
                <li><span>@line.Item</span>@if (_showPrices) { <span>@line.Price.ToString("C0")</span> }</li>
            }
        </ul>
        <div class="desk-foot">
            <span>@(_sent ?? "Nothing sent yet")</span>
            @if (_showTotal) { <strong>Total @_lines.Sum(l => l.Price).ToString("C0")</strong> }
        </div>
    </div>
</div>
```

```csharp
// Booking desk
private bool _hidden, _held, _canceled, _showPrices = true, _showTotal = true;
private RibbonButton? _send;
private string? _sent;
private sealed record Line(string Item, decimal Price);
private readonly List<Line> _lines = new();
private void Add(string item, decimal price)
{
    if (!Has(item)) _lines.Add(new(item, price));
}
private bool Has(string item) => _lines.Any(l => l.Item == item);
private void Send(string document)
{
    _sent = $"{document} emailed to Albus Door";
    _send?.CloseDropDown();
}
```

### Pressed

```razor
@using Fx.ControlKit

<div class="paper-ribbon">
    <RibbonControl CssClass="paper">
        <RibbonTab Title="Group">
            <RibbonGroup Title="Kyoto Classic, four travelers">
                <RibbonButton Text="Confirm all" Icon="✔️" Large="true" Disabled="@_travelers.All(t => t.Confirmed)" OnClick="@(() => _travelers.ForEach(t => t.Confirmed = true))" />
                <RibbonButton Text="Start over" Icon="↩️" OnClick="Reset" />
            </RibbonGroup>
        </RibbonTab>
        <RibbonTab Title="@(_who?.Name ?? "Traveler")" Visible="@(_who is not null)">
            <RibbonGroup Title="Seat and meal" Disabled="@(_who?.Confirmed == true)">
                <RibbonButton Text="Window seat" Icon="💺" Pressed="@(_who?.Window == true)" OnClick="@(() => _who!.Window = !_who.Window)" />
                <RibbonButton Text="Vegetarian" Icon="🥗" Pressed="@(_who?.Vegetarian == true)" OnClick="@(() => _who!.Vegetarian = !_who.Vegetarian)" />
            </RibbonGroup>
            <RibbonGroup Title="Room" Disabled="@(_who?.Confirmed == true)">
                <RibbonButton Text="Quiet room" Icon="🌙" Pressed="@(_who?.Quiet == true)" OnClick="@(() => _who!.Quiet = !_who.Quiet)" />
            </RibbonGroup>
            <RibbonGroup Title="Booking">
                <RibbonButton Text="@(_who?.Confirmed == true ? "Reopen" : "Confirm")" Icon="✔️" Large="true" OnClick="@(() => _who!.Confirmed = !_who.Confirmed)" />
            </RibbonGroup>
        </RibbonTab>
    </RibbonControl>
</div>
<ul class="who-list">
    @foreach (var t in _travelers)
    {
        <li class="@(t == _who ? "picked" : null)">
            <ButtonControl BareStyle="true" CssClass="who-name" OnClick="@(() => _who = t == _who ? null : t)">@t.Name</ButtonControl>
            @if (t.Window) { <BadgeControl Text="Window seat" Variant="BadgeVariant.Info" Size="BadgeSize.Small" /> }
            @if (t.Vegetarian) { <BadgeControl Text="Vegetarian" Variant="BadgeVariant.Info" Size="BadgeSize.Small" /> }
            @if (t.Quiet) { <BadgeControl Text="Quiet room" Variant="BadgeVariant.Info" Size="BadgeSize.Small" /> }
            <BadgeControl Text="@(t.Confirmed ? "Confirmed" : "Open")" Variant="@(t.Confirmed ? BadgeVariant.Success : BadgeVariant.Secondary)" Size="BadgeSize.Small" />
        </li>
    }
</ul>
<span class="result">@(_who is null ? "Pick a traveler to add their tab." : _who.Confirmed ? $"{_who.Name}'s tab is on the strip; Reopen there unlocks their seat, meal and room." : $"{_who.Name}'s tab is on the strip; open it to set their seat, meal and room.")</span>
```

```csharp
// A tab for the selected traveler
private sealed class Traveler
{
    public string Name { get; init; } = "";
    public bool Window { get; set; }
    public bool Vegetarian { get; set; }
    public bool Quiet { get; set; }
    public bool Confirmed { get; set; }
}
private List<Traveler> _travelers = Seed();
private Traveler? _who;
private static List<Traveler> Seed() => new()
{
    new() { Name = "Hermione Ranger", Window = true },
    new() { Name = "Albus Door" },
    new() { Name = "Ron Measly", Vegetarian = true },
    new() { Name = "Luna Goodlove", Confirmed = true },
};
private void Reset()
{
    _travelers = Seed();
    _who = null;
}
```

