Skip to content

Commit 4420f54

Browse files
xristianstefanovDesislava Mihaylova
andauthored
[4.2] docs(contextmenu): add refresh method (#1398)
* docs(contextmenu): add refresh method * Update overview.md --------- Co-authored-by: Desislava Mihaylova <[email protected]>
1 parent 3449cad commit 4420f54

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

components/contextmenu/overview.md

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Overview
33
page_title: Context Menu Overview
4-
description: Overview of the Context Menu for Blazor.
4+
description: Try now the Telerik UI for Blazor Context Menu and learn more about its options for creating the component, binding it to data, changing its navigation views, customizing the component per target, and more.
55
slug: contextmenu-overview
66
tags: telerik,blazor,context menu,overview
77
published: True
@@ -10,23 +10,25 @@ position: 0
1010

1111
# Blazor Context Menu Overview
1212

13-
The <a href="https://www.telerik.com/blazor-ui/context-menu" target="_blank">Blazor Context Menu component </a> displays a contextual popup with data (flat or hierarchical) in a traditional menu-like structure. It lets you invoke commands while preserving screen real estate.
13+
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.
1414

15-
In addition to built-in [navigation capabilities]({%slug contextmenu-navigation%}), you can browse through the items and their children, define [templates]({%slug contextmenu-templates-overview%}) for the individual nodes, render text and icons/images, and respond to [events]({%slug contextmenu-events%}).
15+
In addition to the built-in [navigation capabilities]({%slug contextmenu-navigation%}), you can browse through the items and their children, define [templates]({%slug contextmenu-templates-overview%}) for the individual nodes, render text and icons or images, and respond to [events]({%slug contextmenu-events%}).
1616

17-
## Creating Context Menu
17+
## Creating the Blazor Context Menu
1818

19-
1. Add the `TelerikContextMenu` tag and set its `Selector` parameter to a CSS selector that will match the element(s) you want to attach the context menu to.
20-
1. Provide a collection of models to its `Data` property. The Context Menu will automatically recognize property names like `Id`, `ParentId`, `Text` and a few others. Otherwise, [use bindings to configure custom property names]({%slug contextmenu-data-binding-overview%}#data-bindings).
19+
To create the Context Menu:
20+
21+
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.
22+
1. 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]({%slug contextmenu-data-binding-overview%}#data-bindings).
2123
1. Handle the [`OnClick` event]({%slug contextmenu-events%}#onclick) to respond to user actions.
2224

23-
>caption Basic context menu with hierarchical data binding and OnClick event handler
25+
>caption A basic Context Menu with hierarchical data binding and an `OnClick` event handler
2426
2527
````CSHTML
26-
@* Use a context menu to perform actions *@
28+
@* Use a Context Menu to perform actions *@
2729
2830
<div class="context-menu-target" style="width:200px; height: 100px; background: yellow; margin-bottom: 50px;">
29-
Right click (or tap-and-hold on a touch device) for a context menu.
31+
Right-click (or tap and hold on a touch device) for a Context Menu.
3032
</div>
3133
3234
<TelerikContextMenu Selector=".context-menu-target" Data="@MenuItems"
@@ -98,53 +100,54 @@ In addition to built-in [navigation capabilities]({%slug contextmenu-navigation%
98100

99101
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...]({%slug contextmenu-data-binding-overview%})
100102

101-
## Customize per Target
103+
## Per-Target Customization
102104

103-
The same context menu can easily be attached to many targets, or you can use its `ShowAsync(x, y)` method to show it explicitly based on your business logic needs, data and events. Read more in the [Integration]({%slug contextmenu-integration%}) article.
105+
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...]({%slug contextmenu-integration%}).
104106

105-
## Navigate Views
107+
## Navigation Views
106108

107-
A menu is often used to list pages, views or sections in an application so the user can navigate through them. To do that with a menu, you have two options:
109+
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:
108110

109-
* Use the built-in `UrlField` in the [bound data]({%slug contextmenu-data-binding-overview%}) to populate the URLs in the anchors the menu will generate for you if an URL is provided for the given item. An example is available in the beginning of this article.
110-
* Use a [Template]({%slug contextmenu-templates-overview%}) to generate the desired links (e.g., `NavLink` components) with your own code to enable fine-tuning.
111+
* 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]({%slug contextmenu-data-binding-overview%}), as demonstrated in the first example of this article.
112+
* Enable fine-tuning and generate the desired links, such as `NavLink` components, by using a [template]({%slug contextmenu-templates-overview%}).
111113

112114
[Read more about the Blazor Context Menu navigation...]({%slug contextmenu-navigation%})
113115

114116
## Icons
115117

116-
To illustrate the purpose of each menu item, the Blazor Context Menu allows you to add images, icon classes, or font icons. [Read more about the Blazor Menu icons...]({%slug contextmenu-icons%})
118+
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...]({%slug contextmenu-icons%})
117119

118120
## Templates
119121

120-
You can use the functionality of the built-in templates and customize what is rendered in the items. [Read more about the Blazor Context Menu templates...]({%slug contextmenu-templates-overview%})
122+
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...]({%slug contextmenu-templates-overview%})
121123

122124
## Events
123125

124-
The Context Menu generates events that you can handle and further customize its behavior. [Read more about the Blazor Context Menu events...]({%slug contextmenu-events%})
126+
The Context Menu generates events that you can handle and further customize its behavior. [Read more about the supported Blazor Context Menu events...]({%slug contextmenu-events%})
125127

126128
## Context Menu Parameters
127129

128-
The following table lists Context Menu parameters, which are not related to other features on this page. Check the [Context Menu API Reference](https://docs.telerik.com/blazor-ui/api/Telerik.Blazor.Components.TelerikContextMenu-1) for a full list of properties, methods and events.
130+
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://docs.telerik.com/blazor-ui/api/Telerik.Blazor.Components.TelerikContextMenu-1).
129131

130132
| Attribute | Type and Default&nbsp;Value | Description |
131133
| --- | --- | --- |
132-
| `Class` | `string` | Renders additional CSS class to the main wrapping element of the component. Use it to apply custom styles or [override the theme]({%slug themes-override%}). |
133-
| `Selector` | `string` | CSS selector of the target elements where the Context Menu will be shown.|
134+
| `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]({%slug themes-override%}). |
135+
| `Selector` | `string` | A CSS selector of the target elements where the Context Menu will be shown.|
134136

135137
## Context Menu Reference and Methods
136138

137-
Add a reference to the component instance to use the [Context Menu methods](/blazor-ui/api/Telerik.Blazor.Components.TelerikContextMenu-1).
139+
To use the [Blazor Context Menu methods](/blazor-ui/api/Telerik.Blazor.Components.TelerikContextMenu-1), add a reference to the component instance.
138140

139141
@[template](/_contentTemplates/common/parameters-table-styles.md#table-layout)
140142

141143
| Method | Description |
142144
| --- | --- |
143-
| `ShowAsync` | programmatically shows the ContextMenu
144-
| `HideAsync` | programmatically hides the ContextMenu
145+
| `ShowAsync` | Programmatically shows the Context Menu. |
146+
| `HideAsync` | Programmatically hides the Context Menu. |
147+
| `Refresh` | Re-renders the component. |
145148

146149
````CSHTML
147-
@* Open and close the ContextMenu programmatically *@
150+
@* Open, close, and refresh the Context Menu programmatically *@
148151
149152
<div @oncontextmenu:preventDefault="true"
150153
@oncontextmenu="@( (MouseEventArgs e) => ShowContextMenu(e, false) )"
@@ -164,23 +167,32 @@ Add a reference to the component instance to use the [Context Menu methods](/bla
164167
}
165168
</ul>
166169
}
167-
170+
<TelerikTextBox @bind-Value="@TextBoxValue" />
171+
<br />
172+
<TelerikButton OnClick="@HandleTextBoxReset">Reset textbox</TelerikButton>
168173
<TelerikButton OnClick="@(async () => await TheContextMenu.HideAsync())">Close</TelerikButton>
169174
</Template>
170175
</TelerikContextMenu>
171176
172177
@code {
173178
public List<ContextMenuItem> MenuItems { get; set; }
179+
public string TextBoxValue { get; set; }
174180
175-
// the context menu is a generic component and its type depends on the model it binds to
181+
// The Context Menu is a generic component and its type depends on the model to which it binds.
176182
TelerikContextMenu<ContextMenuItem> TheContextMenu { get; set; }
177183
184+
void HandleTextBoxReset()
185+
{
186+
TextBoxValue = "";
187+
TheContextMenu.Refresh();
188+
}
189+
178190
async Task ShowContextMenu(MouseEventArgs e, bool IsSpecial)
179191
{
180192
await TheContextMenu.ShowAsync(e.ClientX, e.ClientY);
181193
}
182194
183-
// generate sample data for the listview and the menu
195+
// Generate sample data for the ListView and the Context Menu.
184196
protected override void OnInitialized()
185197
{
186198
MenuItems = new List<ContextMenuItem>()
@@ -218,12 +230,11 @@ Add a reference to the component instance to use the [Context Menu methods](/bla
218230

219231
## Next Steps
220232

221-
* [Binding the Context Menu to Data]({%slug contextmenu-data-binding-overview%})
222-
223-
* Handle the [`OnClick` event]({%slug contextmenu-events%}#onclick) of the Context Menu to respond to the user action
233+
* [Binding the Telerik UI for Blazor Context Menu to Data]({%slug contextmenu-data-binding-overview%})
234+
* [Handling the `OnClick` Context Menu Event and Respond to User Interaction]({%slug contextmenu-events%}#onclick)
224235

225236
## See Also
226237

227-
* [Data Binding a Context Menu]({%slug contextmenu-data-binding-overview%})
228-
* [Live Demo: Context Menu](https://demos.telerik.com/blazor-ui/contextmenu/overview)
229-
* [API Reference](https://docs.telerik.com/blazor-ui/api/Telerik.Blazor.Components.TelerikContextMenu-1)
238+
* [Binding the Blazor Context Menu to Data]({%slug contextmenu-data-binding-overview%})
239+
* [Live Demo: Overview of the Blazor Context Menu](https://demos.telerik.com/blazor-ui/contextmenu/overview)
240+
* [Context Menu API Reference](https://docs.telerik.com/blazor-ui/api/Telerik.Blazor.Components.TelerikContextMenu-1)

0 commit comments

Comments
 (0)