Improve mega menu submenu highlighting #6012
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We want a mega menu submenu to be highlighted (i.e. appear visually selected) when users are on a child page of that submenu.
The current logic assumes that we can determine this by comparing URL paths; for example, if a submenu contains a link to /foo/, and the user is on /foo/bar/, then we should highlight the submenu.
For increased flexibility, we also want to support the case when menu items point to links with query strings, for example /foo/?something. In this case, we want a page like /foo/bar/ to also mark the submenu as selected. This commit alters the logic so that we strip off the menu link query string before comparing it to the request path.
Note that this logic only applies to the top-level highlighting of submenus (for example Consumer Tools on the current site). This doesn't alter how the specific menu links themselves are highlighted.
How to test this PR
Checklist