Skip to content

NavLink ActiveClass is always active #903

@TDroogers

Description

@TDroogers

Describe the bug

If you add an attribute ActiveClass this class is always added to the class.

I tried using var navMan = Services.GetRequiredService<NavigationManager>(); but with no success.

Example:
Testing this component:

        <NavLink @onclick="@HandleNavigation" 
                 class="@LinkClassname" 
                 @attributes="@Attributes"
                 Match="@Match" 
                 ActiveClass="@ActiveClass">
            @if (!string.IsNullOrEmpty(Icon))
            {
                <MudIcon Icon="@Icon" Color="@IconColor" Class="@IconClassname"/>
            }
            <div class="mud-nav-link-text">
                @ChildContent
            </div>
        </NavLink>

With this test:

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

Results in this output:

Did not expect comp.Markup "<div class="mud-nav-item mud-ripple"><a blazor:onclick="1" rel="" class="mud-nav-link Custom__nav_active_css"><div class="...

Expected behavior:

ActiveClass should be part of css depending on the page you are.

Version info:

  • bUnit version: 1.11.7
  • .NET Runtime and Blazor version: 6.x
  • OS type and version: windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions