This is a migrated thread and some comments may be shown as answers.

[Solved] Down arrow appears even when there are no child items

6 Answers 100 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Derek Hunziker
Top achievements
Rank 1
Derek Hunziker asked on 12 Jul 2010, 06:39 PM
Hello,

My menu is showing down arrow graphics on items that have no child items. This occurs when all of the child items are being hidden via security trimming (IE. when they all have some sort of [Authorize] attribute applied) and the user is not logged in.

Is this the expected behavior? It's kind of misleading when there is an arrow but no drop-down items.

Thank you!

-Derek

6 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 13 Jul 2010, 08:13 AM
Hello Derek,

I have created a little test project in my attempt to reproduce the depicted issue, but to no avail. Everything works as expected on my end. When an item in not allowed it will not be rendered and its child items along with it.

The test project is attached to this message. Check it and let me know if there is some differences in your logic and in the test project.

Kind regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Derek Hunziker
Top achievements
Rank 1
answered on 13 Jul 2010, 06:16 PM
Hi Georgi,

Thank you for the sample. I think there is a problem with the logic. Take for example the Index3 node. In your sample it has three child items (public, admin, user). If you remove the public item, your code hides Index3 entirely because it has no more accessible child items. That is great in some cases, but the problem is that Index3 is an accessible page itself and shouldn't be hidden just because all of it's children are. Shouldn't it just render Index3 without an downwards arrow?

If you remove the ItemAction code in your sample to go back to the default behavior, I still get the downward arrow even though there are no child items: (Note: there is no sub <ul> but the <span> is still rendered)

<li class="t-item t-highlighted t-state-default">
    <a href="/" class="t-link">Index3
        <span class="t-icon t-arrow-down"></span></a>
</li>

As a temporary fix, I was able to get it working by modifying your ItemAction code as follows. However, I think this should be the default behavior. Your thoughts?

.ItemAction( item =>
{
    // Check if the item has accessible children
    bool hasAccessibleChildren = false;
    foreach (var child in item.Items)
    {
        if (child.IsAccessible(navAuthorization, ViewContext))
        {
            hasAccessibleChildren = true;
            break;
        }
    }
 
    // If the item itself is accessible and has no accessible child items, clear all child items (because there are none)
    if (item.IsAccessible(navAuthorization, ViewContext) && !hasAccessibleChildren)
        item.Items.Clear();                   
})





0
Accepted
Georgi Krustev
Telerik team
answered on 14 Jul 2010, 09:32 AM
Hi Derek,

You are absolutely correct about the menu rendering behavior. It should not render expand/collapse icon if there are no accessible children.

The logic related with ItemAction was required by other customer and was not intended for you.

I confirm that the fix of the problem will be included in the next official release of the Telerik Components for ASP.NET MVC.

Thank you for your collaboration. I have updated your Telerik points.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Derek Hunziker
Top achievements
Rank 1
answered on 29 Jul 2010, 07:23 PM
Just a quick note to let you know that the same issue occurs with hidden nodes (i.e. nodes that have visible="false").

This is my workaround:

.ItemAction(item =>
{
    // Check if the item has accessible & visible children
    bool hasAccessibleChildren = false;
    foreach (var child in item.Items)
    {
        if (child.IsAccessible(navAuthorization, ViewContext) && child.Visible)
        {
            hasAccessibleChildren = true;
            break;
        }
    }
 
    // If the item itself is accessible and has no accessible child items, clear all child items (because there are none)
    if (item.IsAccessible(navAuthorization, ViewContext) && !hasAccessibleChildren)
        item.Items.Clear();
})
0
Georgi Krustev
Telerik team
answered on 30 Jul 2010, 10:49 AM
Hello Derek Hunziker,

Thank you for drawing our attention to this issue. I am glad to inform you that it will be addressed in the next official release of Telerik Components for ASP.NET MVC.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Derek Hunziker
Top achievements
Rank 1
answered on 12 Aug 2010, 12:21 AM
Thanks Georgi!

I also wanted to draw your attention to another related issue I'm having... IsAccessible is always returning true for root menu items - even if the controller or view is decorated with an [Authorize] attribute. I tried the IsAccessibleToUser method of ServiceLocator and that returns true as well. Let me know if you need a sample project.

Any ideas on this one?

Thanks again for your continued help!
Tags
Menu
Asked by
Derek Hunziker
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Derek Hunziker
Top achievements
Rank 1
Share this question
or