Skip to content

Commit 675b8dc

Browse files
KB Botxristianstefanov
authored andcommitted
Added new kb article tooltip-display-disabled-context-menu-items
1 parent cd9328b commit 675b8dc

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: Display Tooltips 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, meaning they don’t trigger events like hover, click, or tooltip. However, you can achieve the desired behavior by making them appear visually "disabled" while keeping them interactive for tooltips with the CSS shown 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+
DISABLE ELEMENTS
49+
<TelerikSwitch Value="@DisabledElements" ValueChanged="@((bool val) => SwitchHandler(val))" />
50+
51+
<TelerikContextMenu Selector=".context-menu-target" Data="@MenuItems">
52+
<ItemTemplate>
53+
<div class="menu-item @(context.ItemDisabled ? "disabled-item" : "")" data-disabled="@context.ItemDisabled">
54+
@context.Text
55+
</div>
56+
</ItemTemplate>
57+
</TelerikContextMenu>
58+
59+
<TelerikTooltip TargetSelector=".menu-item.disabled-item">
60+
<Template>
61+
Tooltip for disabled item
62+
</Template>
63+
</TelerikTooltip>
64+
65+
@code {
66+
private List<ContextMenuItem> MenuItems { get; set; }
67+
68+
private bool DisabledElements = false;
69+
70+
public void SwitchHandler(bool value)
71+
{
72+
DisabledElements = value;
73+
foreach (ContextMenuItem menuItem in MenuItems.Where(p => p.ItemType == "A"))
74+
{
75+
menuItem.ItemDisabled = DisabledElements;
76+
}
77+
}
78+
79+
protected override void OnInitialized()
80+
{
81+
MenuItems = new List<ContextMenuItem>()
82+
{
83+
new ContextMenuItem
84+
{
85+
Text = "Item 1",
86+
ItemType = "A"
87+
},
88+
new ContextMenuItem
89+
{
90+
Text = "Item 2",
91+
ItemType = "A"
92+
},
93+
new ContextMenuItem
94+
{
95+
Text = "Item 3",
96+
ItemType = "B"
97+
},
98+
new ContextMenuItem
99+
{
100+
Text = "Item 4",
101+
ItemType = "B"
102+
}
103+
};
104+
105+
base.OnInitialized();
106+
}
107+
108+
public class ContextMenuItem
109+
{
110+
public string Text { get; set; }
111+
public ISvgIcon Icon { get; set; }
112+
public bool ItemDisabled { get; set; }
113+
public string ItemType { get; set; }
114+
}
115+
}
116+
`````
117+
118+
## See Also
119+
120+
- [Telerik UI for Blazor Tooltip Documentation](slug:tooltip-overview)
121+
- [Telerik UI for Blazor ContextMenu Documentation](slug:contextmenu-overview)

0 commit comments

Comments
 (0)