Problem/Motivation
Toolbar tabs aren’t working properly, see the unexpected behavior below.

Observed behavior:
- Sometimes it works, but most of the time it doesn’t
- The expected tab is not activated consistently
Expected beheavior
- The clicked tab should be activated
- The other tabs should be deactivated
- The submenu (subtree) should appear
Steps to reproduce
1. Install a fresh Drupal 11.x site
2. Log in as admin
3. Click on the toolbar menu tabs — the clicked tab should become active, and the others should be deactivated, sometimes the clicked tab even open the sub menu.
Proposed resolution
Sometimes, for an unknown reason, Backbone does not trigger or update the activeTab model correctly.
To address this, I propose manually triggering the change event when the user clicks a tab.
We can trigger this event inside the onTabClick function in the ToolbarVisualView.js file.
Right after setting the model, similar to how it’s already triggered when the page loads:
this.model.trigger('change:activeTab');
Remaining tasks
- Code review
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | rec-after-patch.gif | 131.82 KB | angel_devoeted |
| #16 | rec-before-patch.gif | 135.12 KB | angel_devoeted |
| #11 | Confrim Tests Success with Patch.png | 298.65 KB | mdyoung3 |
| #11 | Confirm Tests Fail without patch.png | 399.2 KB | mdyoung3 |
| #9 | tests-before-patch.png | 201.93 KB | eric.vvf |
Issue fork drupal-3529674
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joaopauloc.dev commentedComment #4
joaopauloc.dev commentedToolbar working properly after applied the fix of the pull request.

Comment #5
joaopauloc.dev commentedComment #6
roshanibhangale commentedHi
I have tested the above issue on Drupal 11.x.
Steps to reproduce
After successfully applied MR12358, the toolbar menu tabs are working as expected. The clicked tab is activated, The other tabs are deactivated and The submenu (subtree) is appearing properly.
Hence this is RTBC +1.
Attaching video for reference.
Comment #7
smustgrave commentedSeems like something that can expand a javascript test
Comment #9
eric.vvf commentedI was able to reproduce this on Drupal 11.x-dev. It’s not a super obvious one to hit.
Based on @smustgrave’s note, I wrote a FunctionalJavascript test that follows that exact sequence:
Results:

Fails without @joaopaulocdev patch (two elements match > test goes red).
All tests passed after the patch:

Comment #10
eric.vvf commentedComment #11
mdyoung3 commentedI ran an install of 11.x-dev from the fork for this on my local. I clicked through the tabs and was able to replicate the bug on my local.
Then I checked out of the branch with the patch, and I was able to confirm it fixed the issue.
Also checked the test, which ran successfully for me with the patch...
And failed without the patch.
I hope this is a good review. Let me know if more is needed as it's my first time contributing. Please and thank you.
Comment #12
ressaThanks everyone for working on fixing this. I see high levels of dogged persistence by several contributors to replicate the bug, and will just mention that here is an even more demanding one to verify, with a lot more steps. But wouldn't it be great to fix it?
#3540339: Rebuild all caches, including APCu, when clicking "Clear all caches"
At least getting a verification whether there truly is a problem, would be awesome.
Comment #13
smustgrave commentedLooking at the current steps I don't see how shortcuts is needed. Note toolbar is being deprecated from core and Shortcut is up for discussion #3476880: [Policy] Move Shortcut module to contrib so may not want to mix their tests.
Comment #14
mdyoung3 commentedToolbar's deprecation is currently postponed: https://www.drupal.org/project/drupal/issues/3484850
Probably worth getting the fix in.
Comment #15
joaopauloc.dev commentedRemoved the dependency of shortcut module.
Comment #16
angel_devoeted commentedHi
I tested this on a clean Drupal 11.x-dev using Drupal Forge.
Before applying MR !12358, I was able to reproduce the issue where multiple toolbar tabs could remain active at the same time.
After applying the patch, the behavior is now correct (only one tab stays active, and sub-menus open and close as expected).
Before / After screenshots
Before
After
I also checked the test file
core/modules/toolbar/tests/src/FunctionalJavascript/ToolbarIntegrationTest.phpand confirmed that the Shortcut module dependency was removed and replaced with the
toolbar_testmodule.That keeps the test independent from Shortcut (based on its possible move out of core).
Everything works as expected on my end and matches the before/after screenshots I captured.
RTBC +1.
Comment #17
oily commentedThe test-only test outputs:
Test coverage seems fine.
Comment #18
oily commentedHave applied the IS template and re-structured/ re-written the IS accordingly.
The test coverage seems good. The code needs reviewed.
Comment #19
smustgrave commentedI can confirm this from the screenshot in #16, at first I wasn't able to trigger it but with the user link it was definitely reproducible very easily.
The MR does address the problem in all combinations of user link, shortcuts, and main tab. I did rebase the MR as it was 400+ commits back.
MR is still green
Comment #22
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.