Skip to content

fix(ui): sidebar active state desync when opening links in new tabs - #25047

Open
eduardomozart wants to merge 3 commits into
glpi-project:11.0/bugfixesfrom
eduardomozart:fix-issue-25046
Open

fix(ui): sidebar active state desync when opening links in new tabs#25047
eduardomozart wants to merge 3 commits into
glpi-project:11.0/bugfixesfrom
eduardomozart:fix-issue-25046

Conversation

@eduardomozart

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

Description

When a user opens a sidebar menu item in a new tab using a keyboard modifier (Ctrl + Click on Windows / Cmd + Click on macOS) or a middle-click, the sidebar's active/selected state in the current tab immediately changes to the newly clicked item, causing a visual desync with the actual page content currently being viewed (Closes #25046).

Additionally, the click detection was slightly flawed and could trigger incorrectly on inner elements (like icons or text spans) instead of the link itself.

Changes Made

  • Updated the JavaScript handler in templates/layout/parts/menu.html.twig to correctly identify when a link is opened in a new tab/window by checking the underlying MouseEvent for modifier keys (ctrlKey, metaKey, shiftKey, altKey) and middle-clicks (button === 1).
  • Bypassed eagerly applying the active CSS class to the clicked item if the click involved a modifier key.
  • Replaced a fragile className.indexOf('dropdown-item') !== false check with closest('.dropdown-item') to reliably detect clicks on the dropdown item or its children (icons/text).

Screenshots (if appropriate):

Gravacao.de.Tela.2026-07-30.as.13.13.52.mov

Fixes a visual desync where opening a sidebar menu item in a new tab (e.g. via Ctrl+Click or Cmd+Click) would incorrectly change the active state of the menu in the original tab.

Modifies templates/layout/parts/menu.html.twig to ignore modifier clicks and middle-clicks when eagerly setting the active class. Also improves accuracy of click detection by replacing a flawed className.indexOf('dropdown-item') !== false check with closest('.dropdown-item').
Fixes a visual desync where opening a sidebar menu item in a new tab (e.g. via Ctrl+Click or Cmd+Click) would incorrectly change the active state of the menu in the original tab.

Modifies templates/layout/parts/menu.html.twig to ignore modifier clicks and middle-clicks when eagerly setting the active class. Also improves accuracy of click detection by replacing a flawed className.indexOf('dropdown-item') !== false check with closest('.dropdown-item').
@cconard96

Copy link
Copy Markdown
Member

I cannot recreate the original issue and these changes seem to have no effect.

@eduardomozart

Copy link
Copy Markdown
Contributor Author

I know it may sound like a silly question, but did you clean up the Twig cache before testing? GLPI 12 uses the same logic as GLPI 11, so it should be reproducible even in newer GLPI versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sidebar active state updates incorrectly when opening a menu link in a new tab

2 participants