@@ -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 ( {
@@ -24,53 +26,54 @@ import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
2426} )
2527export class MdMenu {
2628 private _showClickCatcher : boolean = false ;
29+
30+ // config object to be passed into the menu's ngClass
2731 private _classList : Object ;
28- positionX : 'before' | 'after' = 'after' ;
29- positionY : 'above' | 'below' = 'below' ;
3032
31- @Output ( ) close = new EventEmitter ;
33+ positionX : MenuPositionX = 'after' ;
34+ positionY : MenuPositionY = 'below' ;
35+
3236 @ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
3337
34- constructor ( @Attribute ( 'x-position' ) posX : 'before' | 'after' ,
35- @Attribute ( 'y-position' ) posY : 'above' | 'below' ,
36- @Attribute ( 'class' ) classes : string ) {
38+ constructor ( @Attribute ( 'x-position' ) posX : MenuPositionX ,
39+ @Attribute ( 'y-position' ) posY : MenuPositionY ) {
3740 if ( posX ) { this . _setPositionX ( posX ) ; }
3841 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 ;
4942 }
5043
5144 /**
5245 * This method takes classes set on the host md-menu element and applies them on the
5346 * menu template that displays in the overlay container. Otherwise, it's difficult
5447 * to style the containing menu from outside the component.
55- * @param classes: list of class names
48+ * @param classes list of class names
5649 */
57- private _mirrorHostClasses ( classes : string ) : void {
58- if ( ! classes ) { return ; }
59-
50+ @Input ( 'class' )
51+ set classList ( classes : string ) {
6052 this . _classList = classes . split ( ' ' ) . reduce ( ( obj : any , className : string ) => {
6153 obj [ className ] = true ;
6254 return obj ;
6355 } , { } ) ;
6456 }
6557
66- private _setPositionX ( pos : 'before' | 'after' ) : void {
58+ @Output ( ) close = new EventEmitter ;
59+
60+ /**
61+ * This function toggles the display of the menu's click catcher element.
62+ * This element covers the viewport when the menu is open to detect clicks outside the menu.
63+ * TODO: internal
64+ */
65+ _setClickCatcher ( bool : boolean ) : void {
66+ this . _showClickCatcher = bool ;
67+ }
68+
69+ private _setPositionX ( pos : MenuPositionX ) : void {
6770 if ( pos !== 'before' && pos !== 'after' ) {
6871 throw new MdMenuInvalidPositionX ( ) ;
6972 }
7073 this . positionX = pos ;
7174 }
7275
73- private _setPositionY ( pos : 'above' | 'below' ) : void {
76+ private _setPositionY ( pos : MenuPositionY ) : void {
7477 if ( pos !== 'above' && pos !== 'below' ) {
7578 throw new MdMenuInvalidPositionY ( ) ;
7679 }
0 commit comments