# Blazor Context Menu Overview

The <a href="https://www.telerik.com/blazor-ui/context-menu" target="_blank">Blazor Context Menu</a> displays a contextual popup with flat or hierarchical data in a traditional menu-like structure. The component enables you to invoke commands while preserving the screen real estate.

In addition to the built-in [navigation capabilities](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/navigation), you can browse through the items and their children, define [templates](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/templates/overview) for the individual nodes, render text and icons or images, and respond to [events](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/events).

## Creating the Blazor Context Menu

To create the Context Menu:

1. Add the `TelerikContextMenu` tag and set its `Selector` parameter to a CSS selector that will match the elements to which you want to attach the Context Menu.
2. Provide a collection of models to the `Data` property of the component. The Context Menu will automatically recognize property names like `Id`, `ParentId`, `Text`, and more. Otherwise, [configure custom property names by using bindings](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/data-binding/overview#data-bindings).
3. Handle the [`OnClick` event](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/events#onclick) to respond to user actions.

> caption A basic Context Menu with hierarchical data binding and an `OnClick` event handler

<demo metaUrl="client/contextmenu/overview/" height="300"></demo>

## Data Binding

To show any items, the Blazor Context Menu requires a data source that you can provide through the `Data` property. The Context Menu allows you to display the items both as flat data and hierarchically. [Read more about the Blazor Context Menu data binding...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/data-binding/overview)

## Per-Target Customization

You can easily attach one and the same Context Menu to many targets or you can use its `ShowAsync(x, y)` method to show the component explicitly based on your business logic needs, data, and events. [Read more about the integration approaches of the Blazor Context Menu...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/integration).

## Navigation Views

A Context Menu is often used to list pages, views, or sections in an application so that users can navigate through them. To achieve the desired scenario, use either of the following options:

* If a URL is provided for the given item, populate the URLs in the anchors which the Context Menu will generate by using the built-in `UrlField` in the [bound data](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/data-binding/overview), as demonstrated in the first example of this article.
* Enable fine-tuning and generate the desired links, such as `NavLink` components, by using a [template](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/templates/overview).

[Read more about the Blazor Context Menu navigation...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/navigation)

## Icons

To illustrate the purpose of each Context Menu item, the Blazor Context Menu allows you to add images, icon classes, or font icons. [Read more about the Blazor Menu icons...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/icons)

## Templates

You can use the functionality of the built-in templates and customize what is rendered in the items. [Read more about the available Blazor Context Menu templates...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/templates/overview)

## Descriptions, Item Actions, and Group Headers

The Context Menu items can display additional content and structure:

* A description, which is a secondary line of text below the item label. Set the `DescriptionField` parameter to enable it. [Read more about Context Menu data bindings...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/data-binding/overview#data-bindings)
* Trailing content, such as a keyboard shortcut, before the expand arrow. [Read more about the Context Menu item actions template...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/templates/item-actions)
* Group headers, which organize the items under labeled sections at the root level and in child popups. [Read more about Context Menu item grouping...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/item-grouping)

## Events

The Context Menu generates events that you can handle and further customize its behavior. [Read more about the supported Blazor Context Menu events...](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/events)

## Context Menu Parameters

The following table lists Context Menu parameters, which are not related to other features on this page. For the full list of properties, methods, and events, see the [Context Menu API reference documentation](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikcontextmenu-1).

| Attribute  | Type and Default Value                              | Description                                                                                                                                                                                                                                                                                                 |
| ---------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Class`    | `string`                                            | Renders an additional CSS class to the main wrapping element of the component. Use it to apply custom styles or [override the theme](https://www.telerik.com/blazor-ui/documentation/styling-and-themes/override-theme-styles).                                                                             |
| `Selector` | `string`                                            | A CSS selector of the target elements where the Context Menu will be shown.                                                                                                                                                                                                                                 |
| `Size`     | `string` <br /> (`ThemeConstants.Menu.Size.Medium`) | The size of the Context Menu items. Use the members of the `ThemeConstants.Menu.Size` class: `Small`, `Medium`, or `Large`. When set to `null`, the component renders no size CSS class. [Read more about the Menu appearance](https://www.telerik.com/blazor-ui/documentation/components/menu/appearance). |

### Popup settings

The popup of the component can be additionally customized via nested tags:

```RAZOR.skip-repl
<TelerikContextMenu TItem="object">
    <ContextMenuSettings>
        <ContextMenuPopupSettings HorizontalCollision="@PopupCollision.Fit" />
    </ContextMenuSettings>
</TelerikContextMenu>
```

The ContextMenu provides the following popup settings:

| Parameter             | Type                                 | Description                                                                                                                                                                                                                                   |
| --------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `HorizontalCollision` | `PopupCollision` enum <br /> (`Fit`) | Sets the behavior of the Popup when it doesn't fit in the viewport based on the horizontal plane. [Read more about Popup collision behavior.](https://www.telerik.com/blazor-ui/documentation/components/popup/position-collision#collision)  |
| `VerticalCollision`   | `PopupCollision` enum <br /> (`Fit`) | Defines the behavior of the Popup when it doesn't fit in the viewport based on the vertical plane. [Read more about Popup collision behavior.](https://www.telerik.com/blazor-ui/documentation/components/popup/position-collision#collision) |

## Context Menu Reference and Methods

To use the [Blazor Context Menu methods](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikcontextmenu-1), add a reference to the component instance.

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Method      | Description                              |
| ----------- | ---------------------------------------- |
| `ShowAsync` | Programmatically shows the Context Menu. |
| `HideAsync` | Programmatically hides the Context Menu. |
| `Refresh`   | Re-renders the component.                |

<demo metaUrl="client/contextmenu/overview/methods/" height="450"></demo>

## Next Steps

* [Binding the Telerik UI for Blazor Context Menu to Data](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/data-binding/overview)
* [Handling the `OnClick` Context Menu Event and Respond to User Interaction](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/events#onclick)

## See Also

* [Binding the Blazor Context Menu to Data](https://www.telerik.com/blazor-ui/documentation/components/contextmenu/data-binding/overview)
* [Live Demo: Overview of the Blazor Context Menu](https://demos.telerik.com/blazor-ui/contextmenu/overview)
* [Context Menu API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikcontextmenu-1)
