Problem/Motivation
Submenus won't show on mouse hover in front end.
Steps to reproduce
Just install the module on D10.1 and try with the default theme.
Proposed resolution
This problem occurs when there are 2 menu elements with same ID on the page (which they are out of the box for me).
I have traced this problem to the following code (from the webpack-built JS file dist/js/frontend.js):
first part: const tbMega = new _plugin_js__WEBPACK_IMPORTED_MODULE_0__["TBMegaMenu"](menu.getAttribute('id'));
second part: this.navParent = document.getElementById(this.id);
The problem is that while the first part initializes the Mega Menu for each of the relevant components (which are queried by their class names), the actual constructor will receive an element ID - which it then uses to get only first of the 2 elements on page. Since one of those elements seems to be a hidden (mobile?) menu and the other one is a visible menu container, only the hidden container is ever converted into the TB Menu. Thus, all of the initialization (mouse events etc.) on the second container is never performed and the menu never shows on mouse over.
My patch in the webpacked JS file was as follows (it will need to get converted into the non-webpacked code somehow but that's outside of my expertise):
// change the following in the Drupal.behaviors.tbMegaMenuInit function
menu.setAttribute('data-initialized', 'true');
const tbMega = new _plugin_js__WEBPACK_IMPORTED_MODULE_0__["TBMegaMenu"]( menu );
tbMega.init();// change the following TBMegaMenu constructor function
constructor(el) {
this.id = el.id;
this.navParent = el;
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | after-patch.mkv | 953.35 KB | sourabhsisodia_ |
| #10 | before-patch.mkv | 734.28 KB | sourabhsisodia_ |
Issue fork tb_megamenu-3369065
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:
- 3369065-3.x
changes, plain diff MR !87
- 3369065-sub-navigation-doesnt-show
compare
Comments
Comment #2
wdrangnath@gmail.com commentedI have installed the module and set it as explained the in document. then I place the same menu on a region in blocks but it is not loading the sub menus in column which is setup in Tb Mega Menu. it is showing the same menu which is created through structure -> menu section.
Can anyone please guide.
Drupal version : 10.0.8 and php version is 8.1.12
Comment #3
mambrus commentedComment #5
knaffles commented@mambrus - Just to clarify, are you placing two instances (blocks) of the same mega menu on the page? I can see how this is an issue in that scenario, but from your description it's not necessarily clear that that's what you're doing. If only one instance of a menu is placed on the page, I only see one element in the markup with that particular ID and it doesn't appear to be an issue.
Comment #6
themodularlab@mambrus,
Can you provide some more info, particularly around @knaffles question? Is this still an issue?
Comment #9
knaffles commentedDidn't get a reply from the original reporter, but I'm assuming the issue is due to the fact that they had more than one mega menu on the same page, with each associated with the same Drupal menu. The result is that each menu has the same `id` attribute on the front end which messes up the initialization of the menus. The merge request below fixes the issue by generating a unique uuid for each mega menu. In the process, I fixed a related issue on mobile where a single button to trigger the open/close of a menu was opening/closing all mega menus on the page at the same time.
https://git.drupalcode.org/project/tb_megamenu/-/merge_requests/87
Comment #10
sourabhsisodia_ commentedTested the MR , it successfully solves the above mentioned issue
Comment #11
sourabhsisodia_ commentedComment #13
knaffles commented