Skip to content

Commit 2b4f4c1

Browse files
author
Aaron
committed
Added minLevel to IsActive check
1 parent 0f2dc2e commit 2b4f4c1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Umbraco.Community.UmbNav.Core/Extensions/UmbNavItemExtensions.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,24 @@ public static string Url(this UmbNavItem item, string? culture = null, UrlMode m
117117
return item.Url ?? "#";
118118
}
119119

120-
public static bool IsActive(this UmbNavItem item, IPublishedContent currentPage, bool checkAncestors = false)
120+
public static bool IsActive(this UmbNavItem item, IPublishedContent currentPage, bool checkAncestors = false, int? minLevel = null)
121121
{
122-
if (item.ContentKey == currentPage.Key)
122+
var contentKey = item.ContentKey ?? item.Content?.Key;
123+
124+
if (contentKey is null || currentPage is null) return false;
125+
126+
var key = currentPage.Key;
127+
128+
if (contentKey == key)
123129
{
124130
return true;
125131
}
132+
133+
if (minLevel.HasValue && currentPage.Level > minLevel)
134+
{
135+
return currentPage.Ancestors().Any(x => x.Level >= minLevel
136+
&& x.Key == contentKey.GetValueOrDefault());
137+
}
126138

127139
if (checkAncestors)
128140
{

0 commit comments

Comments
 (0)