Completed
Last Updated: 22 Oct 2021 15:35 by Jeffrey
Jeffrey
Created on: 15 Oct 2021 16:06
Category: UI for Blazor
Type: Feature Request
1
Context Menu Item Title (tooltip)
Can you add a Title field to the Context Menu component to accommodate tooltips in the dropdown menu?
2 comments
Jeffrey
Posted on: 22 Oct 2021 15:35
Thanks for the info. 
ADMIN
Nadezhda Tacheva
Posted on: 22 Oct 2021 11:16

Hello Jeffrey,

You can currently accommodate tooltips for the ContextMenu items with the following approach:

  • Use ItemTemplate to override the default item rendering.

  • Place the desired item content in a container.

  • Set a unique identifier as Id of that container which you can then use as a Target Selector of the Tooltip - it can be a field of the model, for example.

  • Add a Template for the Tooltip to add the desired content for the corresponding Context Menu item.

Note: as of version 3.0.0 of Telerik UI for Blazor, we will expose OnItemRender event through the arguments of which you will be able to set the desired CSS class to the separate items. These classes can then be used as Target selectors for the Tooltip. You can check the request here - Expose OnItemRender event, with ability to set Class and PopupClass per item. It is opened for the Menu component but will be also applied to the ContextMenu.

To better illustrate the described approach, I have prepared a runnable sample. I have included some additional CSS to expand the container holding the items content to fill up to whole row, so the Tooltip will be opened when the user hovers anywhere on the row and not just on the item text.

Please consider and let me know if any further questions appear.

<div class="menuTarget">
    right click this context menu target
</div>

<TelerikContextMenu Data="@MenuItems" Selector=".menuTarget">
    <ItemTemplate>
        @{
            var item = context as ContextMenuItem;

            <div id="@item.CSSId" class="context-menu-item">@item.Text</div>

            <TelerikTooltip TargetSelector="@($"#{item.CSSId}")" ShowOn="@TooltipShowEvent.Hover">
                <Template Context="Context">
                    @item.Details
                </Template>
            </TelerikTooltip>
        }
    </ItemTemplate>
</TelerikContextMenu>

@code {

    List<ContextMenuItem> MenuItems { get; set; }

    protected override void OnInitialized()
    {

        MenuItems = new List<ContextMenuItem>()
    {
            new ContextMenuItem
            {
                CSSId = "item1-selector",
                Text = "Item 1",
                Details = "Details for Item 1"
            },
            new ContextMenuItem
            {
                CSSId = "item2-selector",
                Text = "Item 2",
                Details = "Details for Item 2"
            }
        };

        base.OnInitialized();
    }

    public class ContextMenuItem
    {
        public string CSSId { get; set; }
        public string Text { get; set; }
        public string Details { get; set; }
    }
}

<style>
    .context-menu-item {
        width: 100px;
        padding: 5px 10px;
    }

    .k-in.k-link.k-menu-link {
        padding: 0px;
    }

    .menuTarget {
        width: 100px;
        background: yellow;
        margin: 50px;
    }
</style>

 

Last but not least, having in mind that the desired scenario can be achieved with the current configuration of the ContextMenu component, I have marked this request as "Completed". In addition, I will also create a knowledge base resource covering this use case.

Regards,
Nadezhda Tacheva
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.