diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs index 239b03a5..46623d03 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/TrimEmptyGroupingNodesVisibilityProvider.cs @@ -1,21 +1,25 @@ using System; using System.Collections.Generic; +using System.Linq; namespace MvcSiteMapProvider { /// - /// Removes non-clickable nodes that have no accessible children. + /// Removes non-clickable nodes that have no accessible and/or visible children. /// public class TrimEmptyGroupingNodesVisibilityProvider : SiteMapNodeVisibilityProviderBase { public override bool IsVisible(ISiteMapNode node, IDictionary sourceMetadata) { - if (!node.HasChildNodes && !node.Clickable) + // Optimization - return quickly if clickable. + if (node.Clickable) { - return false; + return true; } - return true; + + var childNodes = node.ChildNodes; + return childNodes == null || childNodes.Any(c => c.IsVisible(sourceMetadata)); } } }