Skip to content

Commit a3625f4

Browse files
kendo-botKB Botxristianstefanov
authored
Added new kb article tooltip-display-disabled-context-menu-items (#2801)
* Added new kb article tooltip-display-disabled-context-menu-items * chore(Tooltip): add suggestions as per comments --------- Co-authored-by: KB Bot <[email protected]> Co-authored-by: Hristian Stefanov <[email protected]>
1 parent 25576e4 commit a3625f4

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Display Tooltip on Disabled Context Menu Items
3+
description: Learn how to show tooltips over menu items that appear disabled in a Blazor application, using CSS for visual effects and conditional rendering.
4+
type: how-to
5+
page_title: How to Show Tooltips on Visually Disabled Context Menu Items with Blazor
6+
slug: tooltip-kb-display-disabled-context-menu-items
7+
tags: tooltip, context menu, blazor, disabled items
8+
res_type: kb
9+
ticketid: 1678456
10+
---
11+
## Environment
12+
<table>
13+
<tbody>
14+
<tr>
15+
<td>Product</td>
16+
<td>Tooltip for Blazor</td>
17+
</tr>
18+
</tbody>
19+
</table>
20+
21+
## Description
22+
23+
This knowledge base article answers the following questions:
24+
- How can I display tooltips on disabled context menu items in Blazor?
25+
- Is it possible to make menu items appear disabled but still interact with tooltips in Blazor?
26+
- How to apply conditional tooltips on visually disabled elements in a Blazor application?
27+
28+
## Solution
29+
30+
By default, disabled elements are not interactive and don’t trigger events like hover or click. Thus they don't integrate with tooltips. However, you can achieve the desired behavior by making them appear visually disabled while keeping them interactive for tooltips with the CSS code below.
31+
32+
`````RAZOR
33+
<style>
34+
.disabled-item {
35+
opacity: 0.5; /* Make it look disabled */
36+
cursor: not-allowed;
37+
}
38+
39+
.disabled-item > * {
40+
pointer-events: none; /* Prevent clicks on inner content but allow hover on parent */
41+
}
42+
</style>
43+
44+
<div class="context-menu-target" style="width:200px; height: 100px; background: yellow;">
45+
Right-click (or tap and hold on a touch device) for a Context Menu.
46+
</div>
47+
48+
<TelerikSwitch Value="@DisabledElements" ValueChanged="@((bool val) => SwitchHandler(val))" />
49+
Disable Menu Items
50+
51+
<TelerikContextMenu Selector=".context-menu-target" Data="@MenuItems">
52+
<ItemTemplate>
53+
<div class="menu-item @(context.ItemDisabled ? "disabled-item" : "")" title="@($"{context.Text} is disabled!")" data-disabled="@context.ItemDisabled">
54+
@context.Text
55+
</div>
56+
</ItemTemplate>
57+
</TelerikContextMenu>
58+
59+
<TelerikTooltip TargetSelector=".menu-item.disabled-item" />
60+
61+
@code {
62+
private List<ContextMenuItem> MenuItems { get; set; }
63+
64+
private bool DisabledElements = false;
65+
66+
public void SwitchHandler(bool value)
67+
{
68+
DisabledElements = value;
69+
foreach (ContextMenuItem menuItem in MenuItems.Where(p => p.ItemType == "A"))
70+
{
71+
menuItem.ItemDisabled = DisabledElements;
72+
}
73+
}
74+
75+
protected override void OnInitialized()
76+
{
77+
var itemTypes = new[] { "A", "B" };
78+
MenuItems = Enumerable.Range(1, 4)
79+
.Select(i => new ContextMenuItem
80+
{
81+
Text = $"Item {i}",
82+
ItemType = itemTypes[(i - 1) / 2]
83+
})
84+
.ToList();
85+
86+
base.OnInitialized();
87+
}
88+
89+
public class ContextMenuItem
90+
{
91+
public string Text { get; set; }
92+
public ISvgIcon Icon { get; set; }
93+
public bool ItemDisabled { get; set; }
94+
public string ItemType { get; set; }
95+
}
96+
}
97+
`````
98+
99+
## See Also
100+
101+
- [Telerik UI for Blazor Tooltip Documentation](slug:tooltip-overview)
102+
- [Telerik UI for Blazor ContextMenu Documentation](slug:contextmenu-overview)

0 commit comments

Comments
 (0)