@@ -6,11 +6,13 @@ import {
6
6
Attribute ,
7
7
Component ,
8
8
EventEmitter ,
9
+ Input ,
9
10
Output ,
10
11
TemplateRef ,
11
12
ViewChild ,
12
13
ViewEncapsulation
13
14
} from '@angular/core' ;
15
+ import { MenuPositionX , MenuPositionY } from './menu-positions' ;
14
16
import { MdMenuInvalidPositionX , MdMenuInvalidPositionY } from './menu-errors' ;
15
17
16
18
@Component ( {
@@ -25,52 +27,50 @@ import {MdMenuInvalidPositionX, MdMenuInvalidPositionY} from './menu-errors';
25
27
export class MdMenu {
26
28
private _showClickCatcher : boolean = false ;
27
29
private _classList : Object ;
28
- positionX : 'before' | 'after' = 'after' ;
29
- positionY : 'above' | 'below' = 'below' ;
30
+ positionX : MenuPositionX = 'after' ;
31
+ positionY : MenuPositionY = 'below' ;
30
32
31
- @Output ( ) close = new EventEmitter ;
32
33
@ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
33
34
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 ) {
37
37
if ( posX ) { this . _setPositionX ( posX ) ; }
38
38
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 ;
49
39
}
50
40
51
41
/**
52
42
* This method takes classes set on the host md-menu element and applies them on the
53
43
* menu template that displays in the overlay container. Otherwise, it's difficult
54
44
* to style the containing menu from outside the component.
55
- * @param classes: list of class names
45
+ * @param classes list of class names
56
46
*/
57
- private _mirrorHostClasses ( classes : string ) : void {
58
- if ( ! classes ) { return ; }
59
-
47
+ @Input ( 'class' )
48
+ set classList ( classes : string ) {
60
49
this . _classList = classes . split ( ' ' ) . reduce ( ( obj : any , className : string ) => {
61
50
obj [ className ] = true ;
62
51
return obj ;
63
52
} , { } ) ;
64
53
}
65
54
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 {
67
67
if ( pos !== 'before' && pos !== 'after' ) {
68
68
throw new MdMenuInvalidPositionX ( ) ;
69
69
}
70
70
this . positionX = pos ;
71
71
}
72
72
73
- private _setPositionY ( pos : 'above' | 'below' ) : void {
73
+ private _setPositionY ( pos : MenuPositionY ) : void {
74
74
if ( pos !== 'above' && pos !== 'below' ) {
75
75
throw new MdMenuInvalidPositionY ( ) ;
76
76
}
0 commit comments