Blazor ToolBar Overview

The Blazor ToolBar component is a container for buttons or other application-specific tools. This article explains the available features.

Telerik UI for Blazor Ninja image

The ToolBar component is part of Telerik UI for Blazor, a professional grade UI library with 95+ native components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

Creating Blazor ToolBar

  1. Add the <TelerikToolBar> tag to a Razor file.
  2. Use child tags to add tools such as <ToolBarButton> or <ToolBarToggleButton>. Set button text as child content. Optionally, set Icon.
  3. Define OnClick handlers for the buttons.
  4. Set the Selected parameter of the toggle buttons. It supports two-way binding.
  5. (optional) Place related buttons in a <ToolBarButtonGroup> to display them together.

Basic Telerik Toolbar

<TelerikToolBar>
    <ToolBarButtonGroup>
        <ToolBarButton Icon="bold" OnClick="@OnBold">Bold</ToolBarButton>
        <ToolBarButton Icon="italic" OnClick="@OnItalic">Italic</ToolBarButton>
    </ToolBarButtonGroup>

    <ToolBarToggleButton @bind-Selected="@Selected">Toggle Button</ToolBarToggleButton>

    <ToolBarButton Icon="undo" OnClick="@OnUndo">Undo</ToolBarButton>
</TelerikToolBar>

<p> Last clicked button: @LastClicked </p>
<p> The Toggle button's selected state is @Selected.ToString() </p>

@code {
    bool Selected { get; set; } = true;
    string LastClicked { get; set; }

    void OnBold()
    {
        LastClicked = "Bold";
    }

    void OnItalic()
    {
        LastClicked = "Italic";
    }

    void OnUndo()
    {
        LastClicked = "Undo";
    }
}

Built-in Tools

The ToolBar component can include built-in tools such as buttons, toggle buttons and button groups. Read more about the Blazor ToolBar built-in tools.

Separators

The Toolbar features separators and spacers that can visually divide the component items. Read more about the Blazor ToolBar separators and spacers..

Custom Items

The ToolBar component supports template items. Use them to create complex toolbars with dropdowns, inputs and other custom content. Read more about Blazor ToolBar item customization.

Events

The Blazor ToolBar fires click and selection events. Handle those events to respond to user actions. Read more about the Blazor ToolBar events.

ToolBar Parameters

The Blazor ToolBar provides parameters to configure the component:

Parameter Type Description
Adaptive bool Toggles the overflow popup of the toolbar. Displays an additional anchor on the right of the toolbar, where it places all items which overflow from the toolbar.
Class string The CSS class to be rendered on the main wrapping element of the ToolBar component, which is <div class="k-toolbar">. Use for styling customizations.

Example

The Blazor Toolbar has an option for adaptiveness. This option allows you to hide the items overflowing in a popup.

When using ToolBarTemplateItem with the responsive overflow popup, the template inherits automatically Overflow - ToolBarItemOverflow.Never behavior.

Responsive Overflow Popup

<TelerikButton OnClick="ChangeWidth">Change Width!</TelerikButton>

<br />
<br />

<div class="toolbar-wrapper">    
    <TelerikToolBar Adaptive="@ToolBarAdaptive">
        <ToolBarButton Icon="undo">Undo</ToolBarButton>
        <ToolBarButton Icon="redo">Redo</ToolBarButton>
        <ToolBarButton Icon="image" Overflow="ToolBarItemOverflow.Always">Image</ToolBarButton>
        <ToolBarSeparator></ToolBarSeparator>
        <ToolBarToggleButton Icon="apply-format"></ToolBarToggleButton>
        <ToolBarSeparator></ToolBarSeparator>
        <ToolBarButton Icon="copy" Overflow="ToolBarItemOverflow.Never">Copy</ToolBarButton>
        <ToolBarButton Icon="paste" Overflow="ToolBarItemOverflow.Never">Paste</ToolBarButton>
        <ToolBarSeparator></ToolBarSeparator>
    <ToolBarButtonGroup SelectionMode="@ButtonGroupSelectionMode.Single">
        <ToolBarToggleButton Icon="align-left" OverflowText="Left"></ToolBarToggleButton>
        <ToolBarToggleButton Icon="align-center" OverflowText="Center"></ToolBarToggleButton>
        <ToolBarToggleButton Icon="align-right" OverflowText="Right"></ToolBarToggleButton>
    </ToolBarButtonGroup>
    </TelerikToolBar>
</div>

@code {
    void ChangeWidth()
    {
        Width = 40;
    }

    public double Width { get; set; } = 100;
    public bool ToolBarAdaptive { get; set; } = true;
}

<style>
    .toolbar-wrapper{
        width: @(Width.ToString() + "%");
    }
</style>

Next Steps

See Also

In this article