Skip to content

Commit 20a1fa8

Browse files
svdimitrntacheva
andauthored
[3.1] Add the HideAsync method (#803)
* chore(contextmenu): add the hideasync method * Update components/contextmenu/overview.md Co-authored-by: Nadezhda Tacheva <[email protected]> * Update components/contextmenu/overview.md Co-authored-by: Nadezhda Tacheva <[email protected]> Co-authored-by: Nadezhda Tacheva <[email protected]>
1 parent c602e73 commit 20a1fa8

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

components/contextmenu/overview.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,82 @@ A menu is often used to list pages, views or sections in an application so the u
155155

156156
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.
157157

158+
## Methods
159+
160+
The ContextMenu methods are accessible through it's reference:
161+
* `ShowAsync` - programmatically shows the ContextMenu
162+
* `HideAsync` - programmatically hides the ContextMenu
163+
164+
````CSHTML
165+
@* Open and close the ContextMenu programmatically *@
166+
167+
<div @oncontextmenu:preventDefault="true"
168+
@oncontextmenu="@( (MouseEventArgs e) => ShowContextMenu(e, false) )"
169+
class="menuTarget">
170+
normal target
171+
</div>
172+
173+
<TelerikContextMenu Data="@MenuItems" @ref="@TheContextMenu">
174+
<Template>
175+
@{
176+
var dataSource = context as List<ContextMenuItem>;
177+
<p>We have this data:</p>
178+
<ul>
179+
@foreach (var item in dataSource)
180+
{
181+
<li>@item.Text</li>
182+
}
183+
</ul>
184+
}
185+
186+
<TelerikButton OnClick="@(async () => await TheContextMenu.HideAsync())">Close</TelerikButton>
187+
</Template>
188+
</TelerikContextMenu>
189+
190+
@code {
191+
public List<ContextMenuItem> MenuItems { get; set; }
192+
TelerikContextMenu<ContextMenuItem> TheContextMenu { get; set; }
193+
194+
async Task ShowContextMenu(MouseEventArgs e, bool IsSpecial)
195+
{
196+
await TheContextMenu.ShowAsync(e.ClientX, e.ClientY);
197+
}
198+
199+
// generate sample data for the listview and the menu
200+
protected override void OnInitialized()
201+
{
202+
MenuItems = new List<ContextMenuItem>()
203+
{
204+
new ContextMenuItem
205+
{
206+
Text = "More Info",
207+
Metadata = "info"
208+
},
209+
new ContextMenuItem
210+
{
211+
Text = "Special Command",
212+
Metadata = "special"
213+
}
214+
};
215+
216+
base.OnInitialized();
217+
}
218+
219+
public class ContextMenuItem
220+
{
221+
public string Text { get; set; }
222+
public string Metadata { get; set; }
223+
}
224+
}
225+
226+
<style>
227+
.menuTarget {
228+
width: 100px;
229+
background: yellow;
230+
margin: 50px;
231+
}
232+
</style>
233+
````
158234

159235
## See Also
160236

0 commit comments

Comments
 (0)