0

I have come across a case where I am using the @UI.Menu helper and customizing the look using the css classes that are applied by default and I think a class is being added when it probably should not be.

If the 'has-child' class is on then I am adding a + sign using the following:

.sub-menu > li.has-child:before {
    content: "+";
}

When the only pages below a page are hidden, as is the case with my client, the + is still added as the 'has-child' class is still added.

Looking through the source of UIHelper.cs i think the following code change would fix it in the RenderLI method:

// NEW
var hasChild = page.Pages.Where(p => p.IsHidden == false).ToList().Count > 0 ? " has-child" : "";                    
// Original
//var hasChild = page.Pages.Count > 0 ? " has-child" : "" ;

str.AppendLine("<li" + (curr.Id == page.Id ? " class=\"active" + hasChild + "\"" : 
                        (ChildActive(page, curr.Id) ? " class=\"active-child" + hasChild + "\"" :
                        (page.Pages.Count > 0 ? " class=\"has-child\"" : ""))) + ">") ;

I haven't had the opportunity to update the source code and test yet but I think that would do the trick.

In the meantime I have worked around it in js

$("li.has-child").each(function (i, e) {
        if ($(this).find("ul").length == 0) {
            $(this).removeClass("has-child");
        }
    }) 

Let me know if you need further clarification.

0 Answers0