diff --git a/src/Core/Components/NavMenu/FluentNavLink.razor b/src/Core/Components/NavMenu/FluentNavLink.razor
index f84e437d52..c32e7585d9 100644
--- a/src/Core/Components/NavMenu/FluentNavLink.razor
+++ b/src/Core/Components/NavMenu/FluentNavLink.razor
@@ -9,7 +9,13 @@
@if (!OnClick.HasDelegate && Href is not null)
{
-
+ }
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_KeyboardNavigation_InsideNavGroup.verified.html b/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_KeyboardNavigation_InsideNavGroup.verified.html
new file mode 100644
index 0000000000..82519a63bf
--- /dev/null
+++ b/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_KeyboardNavigation_InsideNavGroup.verified.html
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
diff --git a/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_KeyboardNavigation_Standalone.verified.html b/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_KeyboardNavigation_Standalone.verified.html
new file mode 100644
index 0000000000..82519a63bf
--- /dev/null
+++ b/tests/Core/NavMenu/FluentNavLinkTests.FluentNavLink_KeyboardNavigation_Standalone.verified.html
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
diff --git a/tests/Core/NavMenu/FluentNavLinkTests.cs b/tests/Core/NavMenu/FluentNavLinkTests.cs
index f846c0e2ff..156bac5d58 100644
--- a/tests/Core/NavMenu/FluentNavLinkTests.cs
+++ b/tests/Core/NavMenu/FluentNavLinkTests.cs
@@ -1,8 +1,11 @@
// ------------------------------------------------------------------------
// This file is licensed to you under the MIT License.
// ------------------------------------------------------------------------
+using Bunit;
+using Bunit.Rendering;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.FluentUI.AspNetCore.Components.Tests.Extensions;
using Xunit;
@@ -10,6 +13,11 @@ namespace Microsoft.FluentUI.AspNetCore.Components.Tests.NavMenu;
public class FluentNavLinkTests : TestBase
{
+ public FluentNavLinkTests()
+ {
+ TestContext.JSInterop.Mode = JSRuntimeMode.Loose;
+ TestContext.Services.AddSingleton(LibraryConfiguration.ForUnitTests);
+ }
[Fact]
public void FluentNavLink_Default()
{
@@ -179,6 +187,78 @@ public void FluentNavLink_OnClick()
cut.Verify();
}
+ [Fact]
+ public void FluentNavLink_InsideNavGroup_WithHref()
+ {
+ // Arrange & Act
+ var m = new FluentNavMenu
+ {
+ Expanded = true
+ };
+ var cut = TestContext.RenderComponent(parameters =>
+ {
+ parameters.Add(p => p.Owner, m);
+ parameters.Add(p => p.Href, "/example-page");
+ parameters.AddChildContent("NavLink text");
+ });
+
+ // Assert
+ cut.Verify();
+
+ // Verify that FluentKeyCode is added when Owner is not null and Href is set
+ var fluentKeyCode = cut.FindComponent();
+ Assert.NotNull(fluentKeyCode);
+
+ // Verify the anchor points to the NavLink element
+ var navLinkId = cut.Find("a[id]").GetAttribute("id");
+ Assert.Contains("navlink", navLinkId);
+ }
+
+ [Fact]
+ public void FluentNavLink_KeyboardNavigation_InsideNavGroup()
+ {
+ // Arrange & Act - Test NavLink inside a NavGroup scenario
+ var m = new FluentNavMenu
+ {
+ Expanded = true
+ };
+ var cut = TestContext.RenderComponent(parameters =>
+ {
+ parameters.Add(p => p.Owner, m);
+ parameters.Add(p => p.Href, "/example-page");
+ parameters.AddChildContent("Example page");
+ });
+
+ // Assert - Verify that keyboard handling is added for NavLink inside group
+ cut.Verify();
+
+ // Verify FluentKeyCode component is present
+ var fluentKeyCode = cut.FindComponent();
+ Assert.NotNull(fluentKeyCode);
+
+ // Verify the NavLink has the expected id
+ var navLink = cut.Find("a[id]");
+ var navLinkId = navLink.GetAttribute("id");
+ Assert.Contains("-navlink", navLinkId);
+ }
+
+ [Fact]
+ public void FluentNavLink_KeyboardNavigation_Standalone()
+ {
+ // Arrange & Act - Test standalone NavLink (no Owner)
+ var cut = TestContext.RenderComponent(parameters =>
+ {
+ parameters.Add(p => p.Href, "/example-page");
+ parameters.AddChildContent("Example page");
+ });
+
+ // Assert - Verify that no keyboard handling is added for standalone NavLink
+ cut.Verify();
+
+ // Verify no FluentKeyCode component is present
+ Assert.Throws(() => cut.FindComponent());
+ }
+
//ActiveClass
//Match
//Target