File tree 2 files changed +24
-9
lines changed
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 {
66
66
}
67
67
68
68
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
+ }
72
74
}
73
75
74
76
closeMenu ( ) : void {
Original file line number Diff line number Diff line change 1
1
import { 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' ;
4
4
5
5
6
6
describe ( 'MdMenu' , ( ) => {
@@ -14,11 +14,24 @@ describe('MdMenu', () => {
14
14
TestBed . compileComponents ( ) ;
15
15
} ) ) ;
16
16
17
- it ( 'should add and remove focus class on focus/blur ' , ( ) => {
17
+ it ( 'should open the menu as an idempotent operation ' , ( ) => {
18
18
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 ( ) ;
20
24
} ) ;
21
25
} ) ;
22
26
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