@@ -12,14 +12,15 @@ import {
1212 QueryList ,
1313 TemplateRef ,
1414 ViewChild ,
15- ViewEncapsulation
15+ ViewEncapsulation ,
1616} from '@angular/core' ;
1717import { MenuPositionX , MenuPositionY } from './menu-positions' ;
1818import { MdMenuInvalidPositionX , MdMenuInvalidPositionY } from './menu-errors' ;
1919import { MdMenuItem } from './menu-item' ;
2020import { ListKeyManager } from '../core/a11y/list-key-manager' ;
2121import { MdMenuPanel } from './menu-panel' ;
2222import { Subscription } from 'rxjs/Subscription' ;
23+ import { transformMenu , fadeInItems } from './menu-animations' ;
2324
2425@Component ( {
2526 moduleId : module . id ,
@@ -28,6 +29,10 @@ import {Subscription} from 'rxjs/Subscription';
2829 templateUrl : 'menu.html' ,
2930 styleUrls : [ 'menu.css' ] ,
3031 encapsulation : ViewEncapsulation . None ,
32+ animations : [
33+ transformMenu ,
34+ fadeInItems
35+ ] ,
3136 exportAs : 'mdMenu'
3237} )
3338export class MdMenu implements AfterContentInit , MdMenuPanel , OnDestroy {
@@ -37,7 +42,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
3742 private _tabSubscription : Subscription ;
3843
3944 /** Config object to be passed into the menu's ngClass */
40- _classList : Object ;
45+ _classList : any = { } ;
4146
4247 positionX : MenuPositionX = 'after' ;
4348 positionY : MenuPositionY = 'below' ;
@@ -49,6 +54,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
4954 @Attribute ( 'y-position' ) posY : MenuPositionY ) {
5055 if ( posX ) { this . _setPositionX ( posX ) ; }
5156 if ( posY ) { this . _setPositionY ( posY ) ; }
57+ this . _setPositionClasses ( ) ;
5258 }
5359
5460 // TODO: internal
@@ -77,6 +83,7 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
7783 obj [ className ] = true ;
7884 return obj ;
7985 } , { } ) ;
86+ this . _setPositionClasses ( ) ;
8087 }
8188
8289 @Output ( ) close = new EventEmitter < void > ( ) ;
@@ -91,11 +98,12 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
9198 this . items . first . focus ( ) ;
9299 this . _keyManager . focusedItemIndex = 0 ;
93100 }
101+
94102 /**
95103 * This emits a close event to which the trigger is subscribed. When emitted, the
96104 * trigger will close the menu.
97105 */
98- private _emitCloseEvent ( ) : void {
106+ _emitCloseEvent ( ) : void {
99107 this . close . emit ( ) ;
100108 }
101109
@@ -112,4 +120,16 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
112120 }
113121 this . positionY = pos ;
114122 }
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+
115135}
0 commit comments