From 3177c88e3d7e8154382f801baf80234493ef9924 Mon Sep 17 00:00:00 2001 From: Vincent Baaij Date: Thu, 10 Jul 2025 16:37:06 +0200 Subject: [PATCH 1/2] Track active state for menu items with an OnClick handler --- ...crosoft.FluentUI.AspNetCore.Components.xml | 13 ++ .../Demo/Shared/Pages/Lab/IssueTester.razor | 22 +- .../Components/NavMenu/FluentNavLink.razor | 13 +- .../Components/NavMenu/FluentNavLink.razor.cs | 220 +++++++++++++++++- .../NavMenu/FluentNavMenu.razor.css | 2 +- 5 files changed, 261 insertions(+), 9 deletions(-) diff --git a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml index 1f48fe52e7..754f3bf124 100644 --- a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml +++ b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml @@ -7744,6 +7744,19 @@ Gets or sets a callback that is triggered whenever changes. + + + + + + Determines whether the current URI should match the link. + + The absolute URI of the current location. + True if the link should be highlighted as active; otherwise, false. + + + + Gets or sets the content to be rendered for the collapse icon when the menu is collapsible. diff --git a/examples/Demo/Shared/Pages/Lab/IssueTester.razor b/examples/Demo/Shared/Pages/Lab/IssueTester.razor index 5f282702bb..498cfd636c 100644 --- a/examples/Demo/Shared/Pages/Lab/IssueTester.razor +++ b/examples/Demo/Shared/Pages/Lab/IssueTester.razor @@ -1 +1,21 @@ - \ No newline at end of file + + + + Item 1 + + + + + Item 1 + + + Item 2 + + + +@code { + private void OnClick() + { + + } +} diff --git a/src/Core/Components/NavMenu/FluentNavLink.razor b/src/Core/Components/NavMenu/FluentNavLink.razor index f84e437d52..5ddf60b296 100644 --- a/src/Core/Components/NavMenu/FluentNavLink.razor +++ b/src/Core/Components/NavMenu/FluentNavLink.razor @@ -6,6 +6,7 @@ @if (Owner == null || Owner.Expanded || (HasIcon && (!Owner.CollapsedChildNavigation || SubMenu == null))) { + - - - - - - Determines whether the current URI should match the link. - - The absolute URI of the current location. - True if the link should be highlighted as active; otherwise, false. - - - - Gets or sets the content to be rendered for the collapse icon when the menu is collapsible. diff --git a/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_Default.verified.html b/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_Default.verified.html index dd8671fb3e..e4274621c8 100644 --- a/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_Default.verified.html +++ b/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_Default.verified.html @@ -1,11 +1,13 @@ -