# Getting Started with the FloatingToolBar

This tutorial explains how to set up a basic Telerik UI for ASP.NET Core FloatingToolBar and highlights the major steps in the configuration of the component.

You will initialize a FloatingToolBar with text formatting tools inside a positioned container. Next, you will handle its events and reference the client-side instance of the component. Finally, you can run the sample code in [Telerik REPL](https://netcorerepl.telerik.com/) and continue exploring the components.

## Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET Core components:

* You can use the [Telerik REPL](https://netcorerepl.telerik.com/) playground and skip installing the components on your system and configuring a project.

* You can prepare a Visual Studio project by following the following guide:

  * Creating a new pre-configured project for the Telerik UI for ASP.NET Core components from [a project template](https://www.telerik.com/aspnet-core-ui/documentation/vs-integration/new-project-wizard).

## 1. Prepare the CSHTML File

The first step is to add the required directives at the top of the `.cshtml` document:

* To use the Telerik UI for ASP.NET Core HtmlHelpers:

  ```cshtml
  @using Kendo.Mvc.UI
  ```

* To use the Telerik UI for ASP.NET Core TagHelpers:

  ```cshtml
  @addTagHelper *, Kendo.Mvc
  ```

Add a container that holds the content and the toolbar. The FloatingToolBar aligns itself to its closest positioned ancestor, so set the `position` CSS property of the container to `relative`.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <div id="document-editor" style="position: relative; height: 260px; padding: 16px; border: 1px solid #ccc;">
        <h4>Customs Declaration</h4>
        <p>Container MSKU 7720145 holds 18 pallets of medical supplies, temperature-controlled at 2-8&deg;C.</p>
    </div>
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <div id="document-editor" style="position: relative; height: 260px; padding: 16px; border: 1px solid #ccc;">
        <h4>Customs Declaration</h4>
        <p>Container MSKU 7720145 holds 18 pallets of medical supplies, temperature-controlled at 2-8&deg;C.</p>
    </div>
```

## 2. Initialize the FloatingToolBar

Use the FloatingToolBar HtmlHelper or TagHelper to add the component inside the container:

* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the FloatingToolBar element.
* The `Visible()` option shows the toolbar when the page loads. By default, the toolbar is hidden until you call its `show()` client-side method.
* The `ContainerAlign()` option places the toolbar at the bottom center of the container.
* The `Items()` option defines the commands. It accepts the same item configuration as the [ToolBar](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/toolbar/getting-started).

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    <div id="document-editor" style="position: relative; height: 260px; padding: 16px; border: 1px solid #ccc;">
        <h4>Customs Declaration</h4>
        <p>Container MSKU 7720145 holds 18 pallets of medical supplies, temperature-controlled at 2-8&deg;C.</p>

        @(Html.Kendo().FloatingToolBar()
            .Name("floatingtoolbar")
            .Visible(true)
            .ContainerAlign(align => align
                .Horizontal(FloatingToolBarHorizontalAlign.Center)
                .Vertical(FloatingToolBarVerticalAlign.Bottom))
            .Margin(margin => margin.Vertical(-16))
            .Items(items =>
            {
                items.Add().Type(CommandType.ButtonGroup).Buttons(buttons =>
                {
                    buttons.Add().Text("Bold").Icon("bold").Togglable(true).ShowText(ShowIn.Overflow);
                    buttons.Add().Text("Italic").Icon("italic").Togglable(true).ShowText(ShowIn.Overflow);
                    buttons.Add().Text("Underline").Icon("underline").Togglable(true).ShowText(ShowIn.Overflow);
                });
                items.Add().Type(CommandType.Separator);
                items.Add().Type(CommandType.Button).Text("Insert Link").Icon("link").ShowText(ShowIn.Overflow);
            })
        )
    </div>
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <div id="document-editor" style="position: relative; height: 260px; padding: 16px; border: 1px solid #ccc;">
        <h4>Customs Declaration</h4>
        <p>Container MSKU 7720145 holds 18 pallets of medical supplies, temperature-controlled at 2-8&deg;C.</p>

        <kendo-floatingtoolbar name="floatingtoolbar" visible="true">
            <container-align horizontal="FloatingToolBarHorizontalAlign.Center" vertical="FloatingToolBarVerticalAlign.Bottom" />
            <margin vertical="-16" />
            <floatingtoolbar-items>
                <item type="CommandType.ButtonGroup">
                    <buttons>
                        <toolbar-button text="Bold" icon="bold" togglable="true" show-text="ShowIn.Overflow" />
                        <toolbar-button text="Italic" icon="italic" togglable="true" show-text="ShowIn.Overflow" />
                        <toolbar-button text="Underline" icon="underline" togglable="true" show-text="ShowIn.Overflow" />
                    </buttons>
                </item>
                <item type="CommandType.Separator" />
                <item type="CommandType.Button" text="Insert Link" icon="link" show-text="ShowIn.Overflow" />
            </floatingtoolbar-items>
        </kendo-floatingtoolbar>
    </div>
```

## 3. Handle the FloatingToolBar Events

The FloatingToolBar exposes events that you can handle to respond to user actions. In this tutorial, you will handle the `Show` and `Hide` events of the component.

```Razor HtmlHelper
    @(Html.Kendo().FloatingToolBar()
        .Name("floatingtoolbar")
        .Visible(true)
        .Events(events => events
            .Show("onShow")
            .Hide("onHide"))
        .Items(items =>
        {
            items.Add().Type(CommandType.Button).Text("Insert Link").Icon("link");
        })
    )

    <script>
        function onShow(e) {
            console.log("The FloatingToolBar is shown.");
        }

        function onHide(e) {
            console.log("The FloatingToolBar is hidden.");
        }
    </script>
```

```Razor TagHelper
    <kendo-floatingtoolbar name="floatingtoolbar" visible="true" on-show="onShow" on-hide="onHide">
        <floatingtoolbar-items>
            <item type="CommandType.Button" text="Insert Link" icon="link" />
        </floatingtoolbar-items>
    </kendo-floatingtoolbar>

    <script>
        function onShow(e) {
            console.log("The FloatingToolBar is shown.");
        }

        function onHide(e) {
            console.log("The FloatingToolBar is hidden.");
        }
    </script>
```

## 4. (Optional) Reference Existing FloatingToolBar Instances

To use the client-side API of the FloatingToolBar, get a reference to the component instance by using its `Name()`. Then, call the [client-side methods](https://docs.telerik.com/kendo-ui/api/javascript/ui/floatingtoolbar#methods) to control the toolbar.

```Razor HtmlHelper
    @(Html.Kendo().Button()
        .Name("showToolbar")
        .Content("Show Toolbar")
        .Events(events => events.Click("onShowClick"))
    )
    @(Html.Kendo().Button()
        .Name("hideToolbar")
        .Content("Hide Toolbar")
        .Events(events => events.Click("onHideClick"))
    )

    <script>
        function onShowClick() {
            $("#floatingtoolbar").data("kendoFloatingToolBar").show();
        }

        function onHideClick() {
            $("#floatingtoolbar").data("kendoFloatingToolBar").hide();
        }
    </script>
```

```Razor TagHelper
    <kendo-button name="showToolbar" on-click="onShowClick">Show Toolbar</kendo-button>
    <kendo-button name="hideToolbar" on-click="onHideClick">Hide Toolbar</kendo-button>

    <script>
        function onShowClick() {
            $("#floatingtoolbar").data("kendoFloatingToolBar").show();
        }

        function onHideClick() {
            $("#floatingtoolbar").data("kendoFloatingToolBar").hide();
        }
    </script>
```

## Explore this Tutorial in REPL

You can continue experimenting with the code sample in this tutorial by running it in the Telerik REPL server playground.

## Next Steps

* [Configuring the Position of the FloatingToolBar](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/floatingtoolbar/positioning)
* [Customizing the Appearance of the FloatingToolBar](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/floatingtoolbar/appearance)
* [Configuring the Overflow of the FloatingToolBar](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/floatingtoolbar/overflow)
* [Handling the FloatingToolBar Events](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/floatingtoolbar/events)
* [Accessibility of the FloatingToolBar](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/floatingtoolbar/accessibility/overview)
* [Keyboard Navigation of the FloatingToolBar](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/floatingtoolbar/accessibility/keyboard-navigation)

## See Also

* [FloatingToolBar Client-Side API](https://docs.telerik.com/kendo-ui/api/javascript/ui/floatingtoolbar)
* [Knowledge Base Section](https://www.telerik.com/aspnet-core-ui/documentation/knowledge-base)
