-
-
Notifications
You must be signed in to change notification settings - Fork 522
Fix menu highlighting to show correct active page #7724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -118,9 +118,14 @@ public function isVisible(): bool | |||||||||||||||||
| public function openMenu(): bool | ||||||||||||||||||
| { | ||||||||||||||||||
| foreach ($this->subItems as $item) { | ||||||||||||||||||
| // Check if this child is active | ||||||||||||||||||
| if ($item->isActive()) { | ||||||||||||||||||
| return true; | ||||||||||||||||||
| } | ||||||||||||||||||
| // Recursively check if any nested submenu has an active item | ||||||||||||||||||
| if ($item->isMenu() && $item->openMenu()) { | ||||||||||||||||||
| return true; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return false; | ||||||||||||||||||
|
|
@@ -132,6 +137,41 @@ public function isActive(): bool | |||||||||||||||||
| return false; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return $_SERVER['REQUEST_URI'] == $this->getURI(); | ||||||||||||||||||
| $menuUri = $this->getURI(); | ||||||||||||||||||
| $currentUri = $_SERVER['REQUEST_URI']; | ||||||||||||||||||
|
|
||||||||||||||||||
| // Parse both URIs | ||||||||||||||||||
| $currentPath = parse_url($currentUri, PHP_URL_PATH); | ||||||||||||||||||
| $menuPath = parse_url($menuUri, PHP_URL_PATH); | ||||||||||||||||||
| $menuQuery = parse_url($menuUri, PHP_URL_QUERY); | ||||||||||||||||||
| $currentQuery = parse_url($currentUri, PHP_URL_QUERY); | ||||||||||||||||||
|
Comment on lines
+144
to
+147
|
||||||||||||||||||
| $currentPath = parse_url($currentUri, PHP_URL_PATH); | |
| $menuPath = parse_url($menuUri, PHP_URL_PATH); | |
| $menuQuery = parse_url($menuUri, PHP_URL_QUERY); | |
| $currentQuery = parse_url($currentUri, PHP_URL_QUERY); | |
| $currentPath = parse_url($currentUri, PHP_URL_PATH) ?? ''; | |
| $menuPath = parse_url($menuUri, PHP_URL_PATH) ?? ''; | |
| $menuQuery = parse_url($menuUri, PHP_URL_QUERY) ?? ''; | |
| $currentQuery = parse_url($currentUri, PHP_URL_QUERY) ?? ''; |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The improved URL matching logic with query parameter support is a significant behavioral change for menu highlighting, but there are no UI tests to verify this works correctly. Consider adding a Cypress test in cypress/e2e/ui/ that:
- Navigates to a page with query parameters (e.g.,
/v2/family?mode=inactive) - Verifies the correct menu item has the
activeclass applied - Navigates to the same page without query params (e.g.,
/v2/family) - Verifies a different menu item is now active
- Tests nested submenu activation with the new recursive
openMenu()logic
Example test structure:
describe('Menu Highlighting', () => {
beforeEach(() => {
cy.setupAdminSession();
});
it('should highlight menu item with query parameters', () => {
cy.visit('/v2/family?mode=inactive');
cy.get('.nav-link.active').should('contain', 'View Inactive Families');
});
it('should highlight menu item without query parameters', () => {
cy.visit('/v2/family');
cy.get('.nav-link.active').should('contain', 'View Active Families');
});
});| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ private static function renderMenuItem(MenuItem $menuItem): void | |||||
| { | ||||||
| ?> | ||||||
| <li class="nav-item<?= $menuItem->isActive() ? " active" : ""?>"> | ||||||
| <a href="<?= htmlspecialchars($menuItem->getURI(), ENT_QUOTES, 'UTF-8') ?>" <?= $menuItem->isExternal() ? "target='_blank'" : "" ?> class="nav-link"> | ||||||
| <a href="<?= htmlspecialchars($menuItem->getURI(), ENT_QUOTES, 'UTF-8') ?>" <?= $menuItem->isExternal() ? "target='_blank'" : "" ?> class="nav-link<?= $menuItem->isActive() ? " active" : ""?>"> | ||||||
|
||||||
| <a href="<?= htmlspecialchars($menuItem->getURI(), ENT_QUOTES, 'UTF-8') ?>" <?= $menuItem->isExternal() ? "target='_blank'" : "" ?> class="nav-link<?= $menuItem->isActive() ? " active" : ""?>"> | |
| <a href="<?= htmlspecialchars($menuItem->getURI(), ENT_QUOTES, 'UTF-8') ?>" <?= $menuItem->isExternal() ? "target='_blank' rel='noopener noreferrer'" : "" ?> class="nav-link<?= $menuItem->isActive() ? " active" : ""?>"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a docblock comment above the
isActive()method to document the new query parameter matching behavior:This would help future maintainers understand the matching behavior without reading through the implementation.