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

CommentFileSizeAuthor
#10 after-patch.mkv953.35 KBsourabhsisodia_
#10 before-patch.mkv734.28 KBsourabhsisodia_
Command icon 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

mambrus created an issue. See original summary.

wdrangnath@gmail.com’s picture

I 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

mambrus’s picture

Issue summary: View changes

crasx made their first commit to this issue’s fork.

knaffles’s picture

@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.

themodularlab’s picture

Status: Active » Postponed (maintainer needs more info)

@mambrus,

Can you provide some more info, particularly around @knaffles question? Is this still an issue?

knaffles changed the visibility of the branch 3369065-sub-navigation-doesnt-show to hidden.

knaffles’s picture

Status: Postponed (maintainer needs more info) » Needs review

Didn'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

sourabhsisodia_’s picture

StatusFileSize
new734.28 KB
new953.35 KB

Tested the MR , it successfully solves the above mentioned issue

sourabhsisodia_’s picture

Status: Needs review » Reviewed & tested by the community

  • knaffles committed 73d1452c on 3.x
    Issue #3369065 by knaffles, sourabhsisodia_, mambrus, themodularlab: Sub...
knaffles’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.