Skip to content

Commit

Permalink
MudNavLink: Allow custom ActiveClass (#5619)
Browse files Browse the repository at this point in the history
  • Loading branch information
TDroogers committed Nov 8, 2022
1 parent a36b2d7 commit 4539f0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/MudBlazor.UnitTests/Components/NavLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public async Task NavLink_CheckOnClickEvent()
clicked.Should().BeTrue();
}

[Test]
public async Task NavLink_Active()
{
const string activeClass = "Custom__nav_active_css";
var comp = Context.RenderComponent<MudNavLink>(Parameter(nameof(MudNavLink.ActiveClass), activeClass));
comp.Find(".mud-nav-link").Click();
comp.Markup.Should().Contain(activeClass);
}

[Test]
public async Task NavLink_Enabled_CheckNavigation()
{
Expand Down
4 changes: 2 additions & 2 deletions src/MudBlazor/Components/NavMenu/MudNavLink.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="@LinkClassname"
@attributes="@Attributes"
Match="@Match"
ActiveClass="active">
ActiveClass="@ActiveClass">
@if (!string.IsNullOrEmpty(Icon))
{
<MudIcon Icon="@Icon" Color="@IconColor" Class="@IconClassname"/>
Expand All @@ -23,7 +23,7 @@
{
<div @onclick="OnClickHandler"
class="@LinkClassname"
ActiveClass="active">
ActiveClass="@ActiveClass">
@if (!string.IsNullOrEmpty(Icon))
{
<MudIcon Icon="@Icon" Color="@IconColor" Class="@IconClassname" />
Expand Down
7 changes: 7 additions & 0 deletions src/MudBlazor/Components/NavMenu/MudNavLink.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public partial class MudNavLink : MudBaseSelectItem
[Category(CategoryTypes.NavMenu.ClickAction)]
public string Target { get; set; }

/// <summary>
/// User class names when active, separated by space.
/// </summary>
[Parameter]
[Category(CategoryTypes.ComponentBase.Common)]
public string ActiveClass { get; set; } = "active";

[CascadingParameter] INavigationEventReceiver NavigationEventReceiver { get; set; }

protected Task HandleNavigation()
Expand Down

0 comments on commit 4539f0f

Please sign in to comment.