File tree Expand file tree Collapse file tree 2 files changed +24
-9
lines changed Expand file tree Collapse file tree 2 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,11 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
6666 }
6767
6868 openMenu ( ) : void {
69- this . _createOverlay ( ) ;
70- this . _overlayRef . attach ( this . _portal ) ;
71- this . _initMenu ( ) ;
69+ if ( ! this . _menuOpen ) {
70+ this . _createOverlay ( ) ;
71+ this . _overlayRef . attach ( this . _portal ) ;
72+ this . _initMenu ( ) ;
73+ }
7274 }
7375
7476 closeMenu ( ) : void {
Original file line number Diff line number Diff line change 11import { TestBed , async } from '@angular/core/testing' ;
2- import { Component } from '@angular/core' ;
3- import { MdMenuModule } from './menu' ;
2+ import { Component , ViewChild } from '@angular/core' ;
3+ import { MdMenuModule , MdMenuTrigger } from './menu' ;
44
55
66describe ( 'MdMenu' , ( ) => {
@@ -14,11 +14,24 @@ describe('MdMenu', () => {
1414 TestBed . compileComponents ( ) ;
1515 } ) ) ;
1616
17- it ( 'should add and remove focus class on focus/blur ' , ( ) => {
17+ it ( 'should open the menu as an idempotent operation ' , ( ) => {
1818 let fixture = TestBed . createComponent ( TestMenu ) ;
19- expect ( fixture ) . toBeTruthy ( ) ;
19+ fixture . detectChanges ( ) ;
20+ expect ( ( ) => {
21+ fixture . componentInstance . trigger . openMenu ( ) ;
22+ fixture . componentInstance . trigger . openMenu ( ) ;
23+ } ) . not . toThrowError ( ) ;
2024 } ) ;
2125} ) ;
2226
23- @Component ( { template : `` } )
24- class TestMenu { }
27+ @Component ( {
28+ template : `
29+ <button [md-menu-trigger-for]="menu">Toggle menu</button>
30+ <md-menu #menu="mdMenu">
31+ Content
32+ </md-menu>
33+ `
34+ } )
35+ class TestMenu {
36+ @ViewChild ( MdMenuTrigger ) trigger : MdMenuTrigger ;
37+ }
You can’t perform that action at this time.
0 commit comments