material icon indicating copy to clipboard operation
material copied to clipboard

md-menu: not opening/closing menu and showing md-menu-content without clicking

Open ruben1 opened this issue 11 years ago • 19 comments

So, I have this code that is very similar to the example on the documentation. The problem is there's no errors in my console and it's not working. It doesn't open or close the popup. Also, the content of md-menu-content is not hidden.

<md-menu>
  <md-button ng-click="$mdOpenMenu()" class="md-icon-button" aria-label="Open sample menu">
    <md-icon md-menu-origin md-svg-icon="./assets/images/sensor_icon.svg"></md-icon>
  </md-button>
  <md-menu-content>
    <md-menu-item><md-button ng-click="vm.goThere()">Do Something</md-button></md-menu-item>
  </md-menu-content>
</md-menu>

ruben1 avatar Jun 17 '15 15:06 ruben1

The menu is working correctly. http://codepen.io/anon/pen/BNwyrB

mukilane avatar Jun 18 '15 07:06 mukilane

Nice. It must be something in my app then.

ruben1 avatar Jun 18 '15 08:06 ruben1

Update to version 0.10.0 to fix it

ruben1 avatar Jun 18 '15 10:06 ruben1

It still has a weird behaviour. It works perfectly when it's alone in the page. But sometimes the positioning of the popup menu is not done right. I'll check out the code to see what might be the problem.

ruben1 avatar Jun 18 '15 11:06 ruben1

Well, the menu component is added in v0.10.0. It won't be supported in the previous versions. https://github.com/angular/material/blob/master/CHANGELOG.md

mukilane avatar Jun 18 '15 11:06 mukilane

Cool. But still, I have some problems with the positioning. I'll look into it now El 18/6/2015 13:30, "Mukil Elango" [email protected] escribió:

Well, the menu component is added in v0.10.0. It won't be supported in the previous versions. https://github.com/angular/material/blob/master/CHANGELOG.md

— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/3326#issuecomment-113120666.

ruben1 avatar Jun 18 '15 12:06 ruben1

So, something was conflicting with the popup menu appended to the body. In Angular Material, I changed the parent container to another element located inside the body that contains all my site and it's fixed.

The problem was that the 'top' css property of the popup menu appended was set to a large negative number(ex: -500px). It must be something on my site that mess up the calculations for the positioning but I guess it can happen to other sites so it's worth to look into

ruben1 avatar Jun 18 '15 13:06 ruben1

having same issue. top is very high negative value. @ruben1 How do you set the parent ?

atinder avatar Jun 26 '15 04:06 atinder

https://github.com/angular/material/blob/master/src/components/menu/menu-interim-element.js#L80 I changed it to the closest children of body and it calculated the top correctly.

btw, the large negative value on top is applied somehow here https://github.com/angular/material/blob/master/src/components/menu/menu-interim-element.js#L101

Do you have any fixed elements on your page?

ruben1 avatar Jun 26 '15 09:06 ruben1

no i don't think so.

how do you pass the optional parent argument ?

I tried using

<md-menu parent="mySelector">
</md-menu>

but didn't worked.

Edit : peaked into source code and i think it is not exposed yet. Editing angular material's source code directly wont be possible in my environment.

atinder avatar Jun 29 '15 10:06 atinder

I'm also having Ruben's problem, to show the menu I added a style, but I don't like it that way, I can't find what is interfering with the menu :disappointed:

danieladz avatar Jun 30 '15 18:06 danieladz

I'm also facing the same issue, the popup position is not correct. Maybe we are missing some documentation here.

vivekimsit avatar Jul 01 '15 06:07 vivekimsit

I tried with this < md-menu-content style="position: fixed; right:10px; top:64px;" > this helps me to show it, but all the options are shown in the same line, and it's awful this way,

danieladz avatar Jul 01 '15 13:07 danieladz

fixed, at least for me, we had, for some strange reason, a copy of and old angular-material css :100:

danieladz avatar Jul 01 '15 14:07 danieladz

Fixed on my side too :+1:

vivekimsit avatar Jul 03 '15 13:07 vivekimsit

This was causing issues for me when I had a table with a good number of elements. Eventually when I do this:

      //clamp(position);

      el.css({
        top: Math.abs(position.top) + 'px',
        left: position.left + 'px'
      });

Everything just works. I think there might be an issue in the clamp() logic.

https://github.com/angular/material/blob/master/src/components/menu/menu-interim-element.js#L363

juliusl avatar Jul 31 '15 23:07 juliusl

That fix worked for me, however some elements on the page still get the top: -500px property and get lost on the page. Does anyone have a solution for this?

sunnypatel avatar Sep 23 '15 14:09 sunnypatel

I wasted one in trying to make mdMenu work but later I opened the codepen and pasted the code in my html template to surprisingly find it working. I noticed that it had $mdOpenMenu() while on the official documentation which is found here https://material.angularjs.org/latest/demo/menu has $mdMenu.open($event). Don't know but maybe this is due to some version difference. Hope you guys correct it.

mohdsalmanshaikh63 avatar Nov 25 '17 11:11 mohdsalmanshaikh63

@mohdsalmanshaikh63 you didn't provide any information on the version of AngularJS Material you are using. However, in this commit the $mdOpenMenu method was deprecated. This landed in 1.1.2. You should see a warning in the console if you use it due to: https://github.com/angular/material/blob/master/src/components/menu/js/menuController.js#L241-L245.

Splaktar avatar Nov 29 '17 09:11 Splaktar