From df431e40af66b5e44f92d18292fc8db0a21b70a3 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 20 Jun 2026 20:17:36 +0100 Subject: [PATCH] nav: highlight active dropdown toggle in _LoginPartial Add ActivePageAny(ViewContext, IEnumerable) so a dropdown toggle gets the active class + aria-current="page" whenever any of its children is the current route. Apply it to the Plateforme, Administration, and account menu toggles. --- src/Yavsc.Org/Helpers/PageHelpers.cs | 40 +++++++++++++------ .../Views/Shared/_LoginPartial.cshtml | 9 +++-- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/Yavsc.Org/Helpers/PageHelpers.cs b/src/Yavsc.Org/Helpers/PageHelpers.cs index 453951f6..c094495e 100644 --- a/src/Yavsc.Org/Helpers/PageHelpers.cs +++ b/src/Yavsc.Org/Helpers/PageHelpers.cs @@ -16,9 +16,31 @@ namespace Yavsc.Server.Helpers /// Pass an empty controller (or "Home" with action "Index") to match the site root. /// public static IHtmlContent ActivePage(this ViewContext viewContext, string controller, string action = null) + { + return MatchesCurrent(viewContext, controller, action) + ? ActiveMarker() + : HtmlString.Empty; + } + + /// + /// Returns "active" aria-current="page" when the current route targets any of + /// the given controllers. Useful for highlighting a dropdown toggle whose + /// children span several controllers. + /// + public static IHtmlContent ActivePageAny(this ViewContext viewContext, IEnumerable controllers) + { + if (controllers == null) return HtmlString.Empty; + foreach (var c in controllers) + { + if (MatchesCurrent(viewContext, c, null)) return ActiveMarker(); + } + return HtmlString.Empty; + } + + private static bool MatchesCurrent(ViewContext viewContext, string controller, string action) { var route = viewContext?.RouteData.Values; - if (route == null) return HtmlString.Empty; + if (route == null) return false; var currentController = route["controller"] as string; var currentAction = route["action"] as string; @@ -32,24 +54,18 @@ namespace Yavsc.Server.Helpers || (string.Equals(controller, "Home", cmp) && (action == null || string.Equals(action, "Index", cmp))); - bool isCurrent; if (isHome) { - isCurrent = string.IsNullOrEmpty(currentController) + return string.IsNullOrEmpty(currentController) || string.Equals(currentController, "Home", cmp) && (currentAction == null || string.Equals(currentAction, "Index", cmp)); } - else - { - isCurrent = string.Equals(currentController, controller, cmp) - && (action == null || string.Equals(currentAction, action, cmp)); - } - - return isCurrent - ? (IHtmlContent)new HtmlString("active\" aria-current=\"page") - : HtmlString.Empty; + return string.Equals(currentController, controller, cmp) + && (action == null || string.Equals(currentAction, action, cmp)); } + private static IHtmlContent ActiveMarker() => new HtmlString("active\" aria-current=\"page"); + public static List CreateSelectListItems (this IStringLocalizer localisation, Type enumType, object selectedValue =null) { string selectedName = (selectedValue != null) ? enumType.GetEnumName(selectedValue) : null; diff --git a/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml b/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml index b11ff227..e04891c8 100644 --- a/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml +++ b/src/Yavsc.Org/Views/Shared/_LoginPartial.cshtml @@ -5,9 +5,12 @@ @if (Context.User?.Identity?.IsAuthenticated ?? false) { string userName = User.GetUserName(); + var plateformeControllers = new[] { "Bug", "HyperLink", "Feature" }; + var administrationControllers = new[] { "Administration", "Announces", "Activity", "CommandForms", "Notifications", "SIRENExceptions", "Client", "MailingTemplate" }; + var accountMenuControllers = new[] { "Manage", "Grants", "Device", "Diagnostics", "Account" };