Skip to content

Improve active state check for menu and tree item #19281

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

Merged

Conversation

madsrasmussen
Copy link
Contributor

This PR improves the active state check for menu and tree items to prevent highlighting multiple items when paths include the same part.

Before

Currently, these items are both shown as active:

  • /test-1
  • /test-1-2

Because /test-1 is part of both of them.

Screenshot 2025-05-08 at 19 02 10 Screenshot 2025-05-08 at 19 02 47

After

With the new solution, we add a slash at the end of the part we compare, so the check now looks like this:

  • /test-1/
  • /test-1-2/

/test-1/ is not part of /test-1-2/.

Screenshot 2025-05-08 at 19 03 21

@Copilot Copilot AI review requested due to automatic review settings May 8, 2025 17:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refines the active state check for menu and tree items by ensuring path comparisons include a trailing slash to avoid false positives when one path is a substring of another.

  • Updated the active state logic in tree items by applying ensureSlash to both the current location and the item's path.
  • Updated the active state logic in menu items by applying ensureSlash to both the current location and the item's href.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts Applies ensureSlash to the location and tree item path to prevent incorrect active state highlighting.
src/Umbraco.Web.UI.Client/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts Applies ensureSlash to the location and menu href to prevent collisions in active state detection.

…-tree-item

# Conflicts:
#	src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item/tree-item-base/tree-item-context-base.ts
@nielslyngsoe nielslyngsoe enabled auto-merge (squash) May 9, 2025 08:41
@nielslyngsoe nielslyngsoe merged commit f772c26 into release/16.0 May 9, 2025
23 checks passed
@nielslyngsoe nielslyngsoe deleted the v16/hotfix/active-state-for-menu-and-tree-item branch May 9, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants