-
Notifications
You must be signed in to change notification settings - Fork 80
Added new kb article tooltip-display-disabled-context-menu-items #2801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xristianstefanov
merged 2 commits into
master
from
new-kb-tooltip-display-disabled-context-menu-items-ef942347e6794900ad58ff909dc59553
Mar 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
knowledge-base/tooltip-display-disabled-context-menu-items.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| --- | ||
| title: Display Tooltips on Disabled Context Menu Items | ||
| description: Learn how to show tooltips over menu items that appear disabled in a Blazor application, using CSS for visual effects and conditional rendering. | ||
| type: how-to | ||
| page_title: How to Show Tooltips on Visually Disabled Context Menu Items with Blazor | ||
| slug: tooltip-kb-display-disabled-context-menu-items | ||
| tags: tooltip, context menu, blazor, disabled items | ||
| res_type: kb | ||
| ticketid: 1678456 | ||
| --- | ||
| ## Environment | ||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>Tooltip for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| This knowledge base article answers the following questions: | ||
| - How can I display tooltips on disabled context menu items in Blazor? | ||
| - Is it possible to make menu items appear disabled but still interact with tooltips in Blazor? | ||
| - How to apply conditional tooltips on visually disabled elements in a Blazor application? | ||
|
|
||
| ## Solution | ||
|
|
||
| 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. | ||
xristianstefanov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| `````RAZOR | ||
| <style> | ||
| .disabled-item { | ||
| opacity: 0.5; /* Make it look disabled */ | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| .disabled-item > * { | ||
| pointer-events: none; /* Prevent clicks on inner content but allow hover on parent */ | ||
| } | ||
| </style> | ||
|
|
||
| <div class="context-menu-target" style="width:200px; height: 100px; background: yellow;"> | ||
| Right-click (or tap and hold on a touch device) for a Context Menu. | ||
| </div> | ||
|
|
||
| DISABLE ELEMENTS | ||
| <TelerikSwitch Value="@DisabledElements" ValueChanged="@((bool val) => SwitchHandler(val))" /> | ||
xristianstefanov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| <TelerikContextMenu Selector=".context-menu-target" Data="@MenuItems"> | ||
| <ItemTemplate> | ||
| <div class="menu-item @(context.ItemDisabled ? "disabled-item" : "")" data-disabled="@context.ItemDisabled"> | ||
| @context.Text | ||
| </div> | ||
| </ItemTemplate> | ||
| </TelerikContextMenu> | ||
|
|
||
| <TelerikTooltip TargetSelector=".menu-item.disabled-item"> | ||
| <Template> | ||
| Tooltip for disabled item | ||
| </Template> | ||
xristianstefanov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </TelerikTooltip> | ||
|
|
||
| @code { | ||
| private List<ContextMenuItem> MenuItems { get; set; } | ||
|
|
||
| private bool DisabledElements = false; | ||
|
|
||
| public void SwitchHandler(bool value) | ||
| { | ||
| DisabledElements = value; | ||
| foreach (ContextMenuItem menuItem in MenuItems.Where(p => p.ItemType == "A")) | ||
| { | ||
| menuItem.ItemDisabled = DisabledElements; | ||
| } | ||
| } | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| MenuItems = new List<ContextMenuItem>() | ||
| { | ||
| new ContextMenuItem | ||
| { | ||
| Text = "Item 1", | ||
| ItemType = "A" | ||
| }, | ||
| new ContextMenuItem | ||
| { | ||
| Text = "Item 2", | ||
| ItemType = "A" | ||
| }, | ||
| new ContextMenuItem | ||
| { | ||
| Text = "Item 3", | ||
| ItemType = "B" | ||
| }, | ||
| new ContextMenuItem | ||
| { | ||
| Text = "Item 4", | ||
| ItemType = "B" | ||
| } | ||
xristianstefanov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| base.OnInitialized(); | ||
| } | ||
|
|
||
| public class ContextMenuItem | ||
| { | ||
| public string Text { get; set; } | ||
| public ISvgIcon Icon { get; set; } | ||
| public bool ItemDisabled { get; set; } | ||
| public string ItemType { get; set; } | ||
| } | ||
| } | ||
| ````` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Telerik UI for Blazor Tooltip Documentation](slug:tooltip-overview) | ||
| - [Telerik UI for Blazor ContextMenu Documentation](slug:contextmenu-overview) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.