Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronSadlerUK committed Jul 6, 2023
2 parents 3439c14 + a3febd6 commit 37b473b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion TestSiteV10/Views/Partials/Navigation/TopNavigation.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using UmbNav.Core.Models
@using UmbNav.Core.Extensions
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@{
var site = Model.Root();
Expand All @@ -12,5 +13,6 @@
}*@
@foreach (var item in umbNav)
{
<umbnavitem menu-item="item" active-class="nav-link--active" class="nav-link"></umbnavitem>
@*<umbnavitem menu-item="item" active-class="nav-link--active" class="nav-link"></umbnavitem>*@
<a class="nav-link @Html.If(item.IsActive(Model, true), " nav-link--active")" href="@item.Url()">@item.Name</a>
}
18 changes: 18 additions & 0 deletions src/UmbNav.Core/Extensions/UmbNavItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,23 @@ public static string Url(this UmbNavItem item, string culture = null, UrlMode mo

return item.Url;
}

public static bool IsActive(this UmbNavItem item, IPublishedContent currentPage, bool checkAncestors = false)
{
if (item.Key == currentPage.Key)
{
return true;
}

if (checkAncestors)
{
if (item.Content.IsAncestorOrSelf(currentPage) && item.Content != currentPage.Root())
{
return true;
}
}

return false;
}
}
}
1 change: 1 addition & 0 deletions src/UmbNav.Core/Models/UmbNavItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class UmbNavItem
[JsonProperty("itemType")] internal string MenuItemType { get; set; } = "link";

[JsonIgnore]
[Obsolete("If you need to check ancestors, use the IsActive() extension instead")]
public bool IsActive { get; set; }

[JsonProperty("displayAsLabel")]
Expand Down
11 changes: 10 additions & 1 deletion src/UmbNav.Core/TagHelpers/UmbnavItemTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class UmbnavitemTagHelper : TagHelper
public string Culture { get; set; }
public string LabelTagName { get; set; } = "span";
public string ActiveClass { get; set; }
public bool IsActiveAncestorCheck { get; set; } = false;
public IPublishedContent CurrentPage { get; set; } = null;
private bool IsLabel { get { return MenuItem.ItemType == UmbNavItemType.Label; } }

public override void Process(TagHelperContext context, TagHelperOutput output)
Expand All @@ -33,7 +35,14 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
output.AddClass(MenuItem.CustomClasses, HtmlEncoder.Default);
}

if (!string.IsNullOrEmpty(ActiveClass) && MenuItem.IsActive)
if (!string.IsNullOrEmpty(ActiveClass) && CurrentPage != null && IsActiveAncestorCheck)
{
if (MenuItem.IsActive(CurrentPage, true))
{
output.AddClass(ActiveClass, HtmlEncoder.Default);
}
}
else if (!string.IsNullOrEmpty(ActiveClass) && MenuItem.IsActive)
{
output.AddClass(ActiveClass, HtmlEncoder.Default);
}
Expand Down
4 changes: 2 additions & 2 deletions src/UmbNav.Core/UmbNav.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<Copyright>2023 UmbHost Limited</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>2.0.2</AssemblyVersion>
<AssemblyVersion>2.0.3</AssemblyVersion>
<Version>$(AssemblyVersion)</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>Fixes member visiblity</PackageReleaseNotes>
<PackageReleaseNotes>Added IsActive extension with ancestor check</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net60'">
Expand Down
4 changes: 2 additions & 2 deletions src/UmbNav.Web/UmbNav.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<Copyright>2023 UmbHost Limited</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyVersion>2.0.7</AssemblyVersion>
<AssemblyVersion>2.0.8</AssemblyVersion>
<Version>$(AssemblyVersion)</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>Fixes member visiblity</PackageReleaseNotes>
<PackageReleaseNotes>Added IsActive extension with ancestor check</PackageReleaseNotes>
</PropertyGroup>


Expand Down

0 comments on commit 37b473b

Please sign in to comment.