Skip to content

Commit 91b2528

Browse files
chore(menu): sync with code updates
1 parent 31f90fc commit 91b2528

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

components/menu/events.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This article explains the events available in the Telerik Menu for Blazor:
1616

1717
## OnSelect
1818

19-
The `OnSelect` event fires when the user clicks or taps on a menu item. It receives the model of the item as an argument that you can cast to the concrete type you are using.
19+
The `OnSelect` event fires when the user clicks or taps on a menu item. It receives the model of the item as an argument that you can cast to the concrete model type you are using.
2020

2121
You can use the `OnSelect` event to react to user choices in a menu without using navigation to load new content automatically.
2222

@@ -25,17 +25,17 @@ You can use the `OnSelect` event to react to user choices in a menu without usin
2525
````CSHTML
2626
@using Telerik.Blazor.Components.Menu
2727
28-
<TelerikMenu Data="@MenuItems" OnSelect="@OnSelect">
28+
<TelerikMenu Data="@MenuItems" OnSelect="@((MenuItem item) => OnSelectHandler(item))">
2929
</TelerikMenu>
3030
3131
Last item selected: @SelectedItem?.Text
3232
3333
@code {
3434
public MenuItem SelectedItem { get; set; }
3535
36-
protected void OnSelect(object item)
36+
protected void OnSelectHandler(MenuItem item)
3737
{
38-
SelectedItem = item as MenuItem;
38+
SelectedItem = item;
3939
}
4040
4141
public List<MenuItem> MenuItems { get; set; }
@@ -50,7 +50,7 @@ Last item selected: @SelectedItem?.Text
5050
protected override void OnInitialized()
5151
{
5252
MenuItems = new List<MenuItem>()
53-
{
53+
{
5454
new MenuItem()
5555
{
5656
Text = "Share",

components/menu/overview.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,19 @@ To use a Telerik Menu for Blazor:
9898
````CSHTML
9999
@using Telerik.Blazor.Components.Menu
100100
101-
<TelerikMenu @ref:suppressField @ref="theMenu">
102-
</TelerikTreeView>
101+
<TelerikMenu @ref:suppressField @ref="theMenu" Data="@menuData" TextField="Page" UrlField="Page">
102+
</TelerikMenu>
103103
104104
@code {
105-
Telerik.Blazor.Components.Menu.TelerikMenu theMenu;
105+
// the menu is a generic component and its type depends on the model it binds to
106+
Telerik.Blazor.Components.Menu.TelerikMenu<MenuItem> theMenu;
107+
108+
List<MenuItem> menuData = Enumerable.Range(1, 3).Select(x => new MenuItem { Page = $"page{x}" }).ToList();
109+
110+
public class MenuItem
111+
{
112+
public string Page { get; set; }
113+
}
106114
}
107115
````
108116

components/menu/templates.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,31 @@ The Menu component allows you to define a custom template for its items. This ar
1414

1515
The `ItemTemplate` of an item is defined under the `ItemTemplate` tag of the menu.
1616

17-
The template receives the model to which the item is bound as its `context`. You can use it to render the desired content.
17+
The template receives the model to which the item is bound as its `context`. You can use it to render the desired content. The menu is a generic component, so you can use a named context variable that will be of the model type without additional casting.
1818

1919
You can use the template to render arbitrary content according to your application's data and logic. You can use components in it and thus provide rich content instead of plain text. You can also use it to add DOM event handlers like click, doubleclick, mouseover if you need to respond to them.
2020

21-
>caption Use templates to implement navigation between views without the usage of the UrlField feature
21+
>caption Use templates to implement navigation between views without the UrlField feature
2222
2323
````CSHTML
2424
@using Telerik.Blazor.Components.Menu
2525
26-
<TelerikMenu Data="@MenuItems"
27-
ItemsField="@nameof(MenuItem.SubSectionList)">
28-
<ItemTemplate>
29-
@{
30-
var item = context as MenuItem;
31-
var shouldNavigate = !string.IsNullOrEmpty(item.Page);
32-
if (shouldNavigate)
33-
{
34-
<NavLink href="@item.Page">@item.Section</NavLink>
35-
}
36-
else
37-
{
38-
<span style="font-weight: bold;">See more about our @item.Section.ToLowerInvariant()</span>
39-
}
26+
<TelerikMenu Data="@MenuItems"
27+
ItemsField="@nameof(MenuItem.SubSectionList)">
28+
<ItemTemplate Context="item">
29+
@{
30+
var shouldNavigate = !string.IsNullOrEmpty(item.Page);
31+
if (shouldNavigate)
32+
{
33+
<NavLink href="@item.Page">@item.Section</NavLink>
4034
}
41-
</ItemTemplate>
42-
</TelerikMenu>
35+
else
36+
{
37+
<span style="font-weight: bold;">See more about our @item.Section.ToLowerInvariant()</span>
38+
}
39+
}
40+
</ItemTemplate>
41+
</TelerikMenu>
4342
4443
@code {
4544
public List<MenuItem> MenuItems { get; set; }
@@ -109,9 +108,8 @@ You can use the template to render arbitrary content according to your applicati
109108
110109
<TelerikMenu Data="@MenuItems"
111110
ItemsField="@nameof(MenuItem.SubSectionList)">
112-
<ItemTemplate>
111+
<ItemTemplate Context="item">
113112
@{
114-
var item = context as MenuItem;
115113
bool isCurrentPage = CompareCurrentPageUrl(item.Page);
116114
string itemStyling = isCurrentPage ? "color: cyan; cursor: not-allowed;" : "color: blue";
117115
if (isCurrentPage)
@@ -190,7 +188,6 @@ You can use the template to render arbitrary content according to your applicati
190188
base.OnInitialized();
191189
}
192190
}
193-
194191
````
195192

196193
>caption The result from the snippet above, asuming the current page URL is `menu/index` and we hovered the "Components" item

0 commit comments

Comments
 (0)