@@ -6,11 +6,13 @@ import {
66 Attribute ,
77 Component ,
88 EventEmitter ,
9+ Input ,
910 Output ,
1011 TemplateRef ,
1112 ViewChild ,
1213 ViewEncapsulation
1314} from '@angular/core' ;
15+ import { MenuPositionX , MenuPositionY } from './menu-positions' ;
1416import { MdMenuInvalidPositionX , MdMenuInvalidPositionY } from './menu-errors' ;
1517
1618@Component ( {
@@ -25,52 +27,50 @@ import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
2527export class MdMenu {
2628 private _showClickCatcher : boolean = false ;
2729 private _classList : Object ;
28- positionX : 'before' | 'after' = 'after' ;
29- positionY : 'above' | 'below' = 'below' ;
30+ positionX : MenuPositionX = 'after' ;
31+ positionY : MenuPositionY = 'below' ;
3032
31- @Output ( ) close = new EventEmitter ;
3233 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
3334
34- constructor ( @Attribute ( 'x-position' ) posX : 'before' | 'after' ,
35- @Attribute ( 'y-position' ) posY : 'above' | 'below' ,
36- @Attribute ( 'class' ) classes : string ) {
35+ constructor ( @Attribute ( 'x-position' ) posX : MenuPositionX ,
36+ @Attribute ( 'y-position' ) posY : MenuPositionY ) {
3737 if ( posX ) { this . _setPositionX ( posX ) ; }
3838 if ( posY ) { this . _setPositionY ( posY ) ; }
39- this . _mirrorHostClasses ( classes ) ;
40- }
41-
42- /**
43- * This function toggles the display of the menu's click catcher element.
44- * This element covers the viewport when the menu is open to detect clicks outside the menu.
45- * TODO: internal
46- */
47- _setClickCatcher ( bool : boolean ) : void {
48- this . _showClickCatcher = bool ;
4939 }
5040
5141 /**
5242 * This method takes classes set on the host md-menu element and applies them on the
5343 * menu template that displays in the overlay container. Otherwise, it's difficult
5444 * to style the containing menu from outside the component.
55- * @param classes: list of class names
45+ * @param classes list of class names
5646 */
57- private _mirrorHostClasses ( classes : string ) : void {
58- if ( ! classes ) { return ; }
59-
47+ @Input ( 'class' )
48+ set classList ( classes : string ) {
6049 this . _classList = classes . split ( ' ' ) . reduce ( ( obj : any , className : string ) => {
6150 obj [ className ] = true ;
6251 return obj ;
6352 } , { } ) ;
6453 }
6554
66- private _setPositionX ( pos : 'before' | 'after' ) : void {
55+ @Output ( ) close = new EventEmitter ;
56+
57+ /**
58+ * This function toggles the display of the menu's click catcher element.
59+ * This element covers the viewport when the menu is open to detect clicks outside the menu.
60+ * TODO: internal
61+ */
62+ _setClickCatcher ( bool : boolean ) : void {
63+ this . _showClickCatcher = bool ;
64+ }
65+
66+ private _setPositionX ( pos : MenuPositionX ) : void {
6767 if ( pos !== 'before' && pos !== 'after' ) {
6868 throw new MdMenuInvalidPositionX ( ) ;
6969 }
7070 this . positionX = pos ;
7171 }
7272
73- private _setPositionY ( pos : 'above' | 'below' ) : void {
73+ private _setPositionY ( pos : MenuPositionY ) : void {
7474 if ( pos !== 'above' && pos !== 'below' ) {
7575 throw new MdMenuInvalidPositionY ( ) ;
7676 }
0 commit comments