Skip to content

Add InactiveClass parameter to NavLink#66365

Open
KitKeen wants to merge 1 commit intodotnet:mainfrom
KitKeen:feature/navlink-inactive-class
Open

Add InactiveClass parameter to NavLink#66365
KitKeen wants to merge 1 commit intodotnet:mainfrom
KitKeen:feature/navlink-inactive-class

Conversation

@KitKeen
Copy link
Copy Markdown

@KitKeen KitKeen commented Apr 19, 2026

Add InactiveClass parameter to NavLink
Fixes #37765

Summary

Adds an optional InactiveClass parameter to <NavLink> that mirrors ActiveClass. When the link's href does not match the current URI, the supplied class is appended to any user-provided class. The default is null, so existing usage is unaffected.

Example

<NavLink class="bg-dark-gray" ActiveClass="text-white" InactiveClass="text-gray" href="/page" />
- Active: <a class="bg-dark-gray text-white">
- Inactive: <a class="bg-dark-gray text-gray">

Implementation

Refactored UpdateCssClass() to pick ActiveClass (or "active" default) when active, or InactiveClass when inactive. Same CombineWithSpace helper.

Tests

Added 5 cases to NavLinkTest.cs:
- Active state ignores InactiveClass
- Inactive state applies InactiveClass
- Inactive without InactiveClass preserves prior behavior
- Inactive combines user class with InactiveClass
- Active combines user class with ActiveClass even when InactiveClass set

Public API

PublicAPI.Unshipped.txt updated with the new property.

Note

This is a public API addition. The shape was proposed in #37765 and matches the existing ActiveClass pattern, so should be uncontroversial — but flagging in case the team wants formal API review.

Adds an optional InactiveClass parameter to <NavLink> that mirrors
ActiveClass: when the link's href does not match the current URI,
the supplied class is appended to any user-provided class. The
default is null, so existing usage is unaffected.

Fixes dotnet#37765
@KitKeen KitKeen requested a review from a team as a code owner April 19, 2026 09:04
@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Apr 19, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 19, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Thanks for your PR, @KitKeen. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NavLink should have a core set of classes and inactive ones rather than just tacking on "Active" ones.

1 participant