metismenu icon indicating copy to clipboard operation
metismenu copied to clipboard

toggle doesn't work when no sub-menu is present

Open dzaeny opened this issue 9 years ago • 20 comments

Hi, I found out that toggle doesn't work right with items that don't have sub-menus.

For example:

<ul id="menu">
    <li><a href="#/page1">Page 1</a>
        <ul>
            <li><a href="#/sub-page1">Sub-page </a></li>
            <li><a href="#/sub-page2">Sub-page 2</a></li>
        </ul>
    </li>
    <li><a href="#/page2">Page 2</a></li>
</ul>

The problem is line 37 in the code:

$this.find("li").has("ul").children("a").on("click" + "." + pluginName, function(e) ...

Everything works fine when I remove .has("ul") from the code.

The thing is I'm working with angular and not using direct links but routing based on my location, so even when the link doesn't have a sub-menu, it still doesn't go to a new page but should toggle the other menus.

Cheers, Jan Fucik

dzaeny avatar Sep 02 '14 14:09 dzaeny

I have the same problem, I tried the new version 2.0.0 and the behaviour is the same in all versions.

Thanks.

serloal avatar Jan 21 '15 15:01 serloal

+1, please can you fix it?

Thanks in advance!

pballester avatar Jan 21 '15 16:01 pballester

Same here! Any fixes?

Zephyrante avatar Jan 26 '15 08:01 Zephyrante

<ul id="sidebar-left-menu">
   <li data="{autoShowFlg:0,menuUnder:''}" id="LSMS04000000">
      <a href="javascript:addNewTab('Admin','user.action',300)">
      <i class="glyphicon glyphicon-chevron-right"></i>&nbsp;&nbsp;
      <span class="sidebar-link1">ADMIN</span>
      </a>
      <!-- Sub menu -->
      <ul class="collapse" style="height: 0px;">
         <li data="{autoShowFlg:0,menuUnder:'LSMS04000000'}" id="LSMS04100000">
            <a href="#">
            &nbsp;&nbsp;<i class="glyphicon glyphicon-chevron-right"></i>&nbsp;&nbsp;
            <span class="sidebar-link1">MANAGEMENT</span>
            </a>
            <!-- Sub menu -->
            <ul class="collapse" style="height: 0px;">
               <li data="{autoShowFlg:0,menuUnder:'LSMS04100000'}" id="LSMS04110000">
                  <a href="javascript:addNewTab('Role Group','roleGroup.action',300)">
                  &nbsp;&nbsp;&nbsp;&nbsp;<i class="glyphicon glyphicon-chevron-right"></i>&nbsp;&nbsp;
                  <span class="sidebar-link1">ROLE GROUP</span>
                  </a>
               </li>
               <li data="{autoShowFlg:0,menuUnder:'LSMS04100000'}" id="LSMS04120000">
                  <a href="javascript:addNewTab('Role','role.action',300)">
                  &nbsp;&nbsp;&nbsp;&nbsp;<i class="glyphicon glyphicon-chevron-right"></i>&nbsp;&nbsp;
                  <span class="sidebar-link1">ROLE</span>
                  </a>
               </li>
               <li data="{autoShowFlg:0,menuUnder:'LSMS04100000'}" id="LSMS04130000">
                  <a href="javascript:addNewTab('User','user.action',300)">
                  &nbsp;&nbsp;&nbsp;&nbsp;<i class="glyphicon glyphicon-chevron-right"></i>&nbsp;&nbsp;
                  <span class="sidebar-link1">USER</span>
                  </a>
               </li>
            </ul>
         </li>
      </ul>
   </li>
</ul>

I have same problem. Sub of sub menu is not collapse when I click root menu to close toggle.

from code when I click menu "Admin" and click "MANAGEMENT". After that I click Admin for toggle close of all the menu "MANAGEMENT" level is toggle close. But "ROLE GROUP, ROLE, USER" is not close toggle.

Could you please fix that?

update : from version 1.1.3 i change from $(this).parent("li").siblings().removeClass("active").children("ul.in").collapse("hide"); to $(this).parent("li").find('li').removeClass("active").children("ul.in").collapse("hide");

jirapatj avatar Mar 11 '15 07:03 jirapatj

Same problem here. I'm using this with ember.js which uses single page routing, the toggle function does not work. Any fix for this?

Also. Going directly to a hash based route (http://dom.com/#/some/route) causes the menu to be fully expanded on load. Not sure if this is an issue with my setup, or with the plugin itself.

laszlof avatar Apr 15 '15 14:04 laszlof

I managed to fix the specific problem I was having by adding another "click" listener for the sub menu links.

    this.$element.find('li').not(':has(ul)').children('a').on('click.metisMenu', function() {
      if ($this.options.toggle) {
        var $parent = $(this).closest('ul.in');
        $this.hide($parent);
      }
    });

As for my second issue, it actually came down to having some matching (temporary) links that were going to "#", which matched the current page, so the plugin was marking them "active" and expanding the groups. Not really an issue with the plugin itself.

laszlof avatar Apr 15 '15 15:04 laszlof

+1

lenamtl avatar May 22 '15 13:05 lenamtl

Hi, here is a listener to inject into metisMenu which works fine.

var that = this;
this.$element.children('li').not(':has(ul)').children('a').on('click.metisMenu', function(e) {
  if ($this.options.toggle) {
    var $parent = that.$element.find('ul.in');
    $this.hide($parent);
  }
});

slimsoft avatar Oct 27 '15 11:10 slimsoft

Hello there,

I'm having an issue similar to the one reported by @laszlof and I haven't been able to find the solution yet. I doesn't matter how deep the menu is, when the url ends with a hashtag (http://localhost/myApp/# as an example) the entire menu is fully expanded on load. Any thoughts on how to solve it?. Cheers.

jujoramos avatar Nov 10 '15 16:11 jujoramos

Any solution to this? Thanks!!

harrywang avatar Dec 04 '15 19:12 harrywang

Replace your dummy href="#" with href="#any-word", worked for me. :)

elvis7 avatar Mar 24 '16 10:03 elvis7

I think I have this problem too. My menu have some menus without submenus and some menus with submenus. When a menu with submenu is open, and I click on a menu without submenu, the previous menu with submenu open doesn't collapse. I want to use metis release without modifying myself the lib. any idea ?

MoxFulder avatar Aug 25 '16 08:08 MoxFulder

Please fix this! The fix from slimsoft from over a year ago works, why hasn't it been integrated? I don't want to edit a node module!

PTC-JoshuaMatthews avatar Nov 11 '16 19:11 PTC-JoshuaMatthews

Please fix it!

gsag avatar May 10 '17 23:05 gsag

@dzaeny @serloal @pballester @Zephyrante @jirapatj @laszlof @lenamtl @slimsoft @jujoramos @harrywang @elvis7 @MoxFulder @PTC-JoshuaMatthews @gsag

Please try https://github.com/onokumus/metismenu/tree/parent-toogle

onokumus avatar May 11 '17 20:05 onokumus

I still have the same issue using the parent-toggle branch.

MoxFulder avatar Aug 15 '17 09:08 MoxFulder

I have the same bug..

notridan avatar Nov 01 '17 22:11 notridan

Wow... what an old bug! I'm having this trouble now and just discovered this is here over 3 years! @onokumus this menu is beautiful, and I really want to fix it to stay with it! Can you please do the fix suggested or help us with the better way to do it? Thank you for the component anyway! Is parent-toggle a branch just to solve this problem? Will it be merged to master?

setefocos avatar Nov 17 '17 17:11 setefocos

News?

pereiradiogo avatar Jan 23 '19 12:01 pereiradiogo

Hi! Hava the problem solved in this branch: https://github.com/pereiradiogo/metismenu/tree/fix_parent_menus

@onokumus Check de PR

pereiradiogo avatar Jan 28 '19 17:01 pereiradiogo