@@ -12,14 +12,15 @@ import {
12
12
QueryList ,
13
13
TemplateRef ,
14
14
ViewChild ,
15
- ViewEncapsulation
15
+ ViewEncapsulation ,
16
16
} from '@angular/core' ;
17
17
import { MenuPositionX , MenuPositionY } from './menu-positions' ;
18
18
import { MdMenuInvalidPositionX , MdMenuInvalidPositionY } from './menu-errors' ;
19
19
import { MdMenuItem } from './menu-item' ;
20
20
import { ListKeyManager } from '../core/a11y/list-key-manager' ;
21
21
import { MdMenuPanel } from './menu-panel' ;
22
22
import { Subscription } from 'rxjs/Subscription' ;
23
+ import { transformMenu , fadeInItems } from './menu-animations' ;
23
24
24
25
@Component ( {
25
26
moduleId : module . id ,
@@ -28,6 +29,10 @@ import {Subscription} from 'rxjs/Subscription';
28
29
templateUrl : 'menu.html' ,
29
30
styleUrls : [ 'menu.css' ] ,
30
31
encapsulation : ViewEncapsulation . None ,
32
+ animations : [
33
+ transformMenu ,
34
+ fadeInItems
35
+ ] ,
31
36
exportAs : 'mdMenu'
32
37
} )
33
38
export class MdMenu implements AfterContentInit , MdMenuPanel , OnDestroy {
@@ -37,7 +42,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
37
42
private _tabSubscription : Subscription ;
38
43
39
44
/** Config object to be passed into the menu's ngClass */
40
- _classList : Object ;
45
+ _classList : any = { } ;
41
46
42
47
positionX : MenuPositionX = 'after' ;
43
48
positionY : MenuPositionY = 'below' ;
@@ -49,6 +54,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
49
54
@Attribute ( 'y-position' ) posY : MenuPositionY ) {
50
55
if ( posX ) { this . _setPositionX ( posX ) ; }
51
56
if ( posY ) { this . _setPositionY ( posY ) ; }
57
+ this . _setPositionClasses ( ) ;
52
58
}
53
59
54
60
// TODO: internal
@@ -77,6 +83,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
77
83
obj [ className ] = true ;
78
84
return obj ;
79
85
} , { } ) ;
86
+ this . _setPositionClasses ( ) ;
80
87
}
81
88
82
89
@Output ( ) close = new EventEmitter < void > ( ) ;
@@ -91,11 +98,12 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
91
98
this . items . first . focus ( ) ;
92
99
this . _keyManager . focusedItemIndex = 0 ;
93
100
}
101
+
94
102
/**
95
103
* This emits a close event to which the trigger is subscribed. When emitted, the
96
104
* trigger will close the menu.
97
105
*/
98
- private _emitCloseEvent ( ) : void {
106
+ _emitCloseEvent ( ) : void {
99
107
this . close . emit ( ) ;
100
108
}
101
109
@@ -112,4 +120,16 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
112
120
}
113
121
this . positionY = pos ;
114
122
}
123
+
124
+ /**
125
+ * It's necessary to set position-based classes to ensure the menu panel animation
126
+ * folds out from the correct direction.
127
+ */
128
+ private _setPositionClasses ( ) {
129
+ this . _classList [ 'md-menu-before' ] = this . positionX == 'before' ;
130
+ this . _classList [ 'md-menu-after' ] = this . positionX == 'after' ;
131
+ this . _classList [ 'md-menu-above' ] = this . positionY == 'above' ;
132
+ this . _classList [ 'md-menu-below' ] = this . positionY == 'below' ;
133
+ }
134
+
115
135
}
0 commit comments