@@ -48,7 +48,9 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
48
48
private _previousFocus : Element | null = null ;
49
49
50
50
@Input ( )
51
- get open ( ) : boolean { return this . _open ; }
51
+ get open ( ) : boolean {
52
+ return this . _open ;
53
+ }
52
54
set open ( value : boolean ) {
53
55
const newValue = coerceBooleanProperty ( value ) ;
54
56
if ( newValue !== this . _open ) {
@@ -59,30 +61,38 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
59
61
private _open : boolean = false ;
60
62
61
63
@Input ( )
62
- get anchorElement ( ) : HTMLElement | null { return this . _anchorElement ; }
64
+ get anchorElement ( ) : HTMLElement | null {
65
+ return this . _anchorElement ;
66
+ }
63
67
set anchorElement ( element : HTMLElement | null ) {
64
68
this . _anchorElement = element ;
65
69
}
66
70
private _anchorElement : HTMLElement | null = null ;
67
71
68
72
@Input ( )
69
- get anchorCorner ( ) : AnchorCorner { return this . _anchorCorner ; }
73
+ get anchorCorner ( ) : AnchorCorner {
74
+ return this . _anchorCorner ;
75
+ }
70
76
set anchorCorner ( value : AnchorCorner ) {
71
77
this . _anchorCorner = value || 'topStart' ;
72
78
this . _foundation . setAnchorCorner ( ANCHOR_CORNER_MAP [ this . _anchorCorner ] ) ;
73
79
}
74
80
private _anchorCorner : AnchorCorner = 'topStart' ;
75
81
76
82
@Input ( )
77
- get quickOpen ( ) : boolean { return this . _quickOpen ; }
83
+ get quickOpen ( ) : boolean {
84
+ return this . _quickOpen ;
85
+ }
78
86
set quickOpen ( value : boolean ) {
79
87
this . _quickOpen = coerceBooleanProperty ( value ) ;
80
88
this . _foundation . setQuickOpen ( this . _quickOpen ) ;
81
89
}
82
90
private _quickOpen : boolean = false ;
83
91
84
92
@Input ( )
85
- get fixed ( ) : boolean { return this . _fixed ; }
93
+ get fixed ( ) : boolean {
94
+ return this . _fixed ;
95
+ }
86
96
set fixed ( value : boolean ) {
87
97
this . _fixed = coerceBooleanProperty ( value ) ;
88
98
this . _fixed ? this . _getHostElement ( ) . classList . add ( 'mdc-menu-surface--fixed' ) :
@@ -92,23 +102,29 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
92
102
private _fixed : boolean = false ;
93
103
94
104
@Input ( )
95
- get coordinates ( ) : Coordinates { return this . _coordinates ; }
105
+ get coordinates ( ) : Coordinates {
106
+ return this . _coordinates ;
107
+ }
96
108
set coordinates ( value : Coordinates ) {
97
109
this . _coordinates = value ;
98
110
this . _foundation . setAbsolutePosition ( value . x , value . y ) ;
99
111
}
100
- private _coordinates : Coordinates = { x : 0 , y : 0 } ;
112
+ private _coordinates : Coordinates = { x : 0 , y : 0 } ;
101
113
102
114
@Input ( )
103
- get anchorMargin ( ) : AnchorMargin { return this . _anchorMargin ; }
115
+ get anchorMargin ( ) : AnchorMargin {
116
+ return this . _anchorMargin ;
117
+ }
104
118
set anchorMargin ( value : AnchorMargin ) {
105
119
this . _anchorMargin = value ;
106
120
this . _foundation . setAnchorMargin ( this . _anchorMargin ) ;
107
121
}
108
122
private _anchorMargin : AnchorMargin = { } ;
109
123
110
124
@Input ( )
111
- get hoistToBody ( ) : boolean { return this . _hoistToBody ; }
125
+ get hoistToBody ( ) : boolean {
126
+ return this . _hoistToBody ;
127
+ }
112
128
set hoistToBody ( value : boolean ) {
113
129
this . _hoistToBody = coerceBooleanProperty ( value ) ;
114
130
if ( this . _hoistToBody ) {
@@ -141,56 +157,38 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
141
157
this . _registerWindowClickListener ( ) ;
142
158
} ,
143
159
isElementInContainer : ( el : Element ) => this . _getHostElement ( ) === el || this . _getHostElement ( ) . contains ( el ) ,
144
- isRtl : ( ) => {
145
- if ( ! this . platform . isBrowser ) { return false ; }
146
-
147
- return window . getComputedStyle ( this . _getHostElement ( ) ) . getPropertyValue ( 'direction' ) === 'rtl' ;
148
- } ,
149
- setTransformOrigin : ( origin : string ) => {
150
- if ( ! this . platform . isBrowser ) { return ; }
151
-
152
- this . _getHostElement ( ) . style [ `${ util . getTransformPropertyName ( window ) } -origin` as any ] = origin ;
153
- } ,
160
+ isRtl : ( ) => this . platform . isBrowser ?
161
+ window . getComputedStyle ( this . _getHostElement ( ) ) . getPropertyValue ( 'direction' ) === 'rtl' : false ,
162
+ setTransformOrigin : ( origin : string ) =>
163
+ this . platform . isBrowser ?
164
+ this . _getHostElement ( ) . style [ `${ util . getTransformPropertyName ( window ) } -origin` as any ] = origin : false ,
154
165
isFocused : ( ) => this . platform . isBrowser ? document . activeElement ! === this . _getHostElement ( ) : false ,
155
- saveFocus : ( ) => {
156
- if ( ! this . platform . isBrowser ) { return ; }
157
- this . _previousFocus = document . activeElement ! ;
158
- } ,
166
+ saveFocus : ( ) => this . platform . isBrowser ? this . _previousFocus = document . activeElement ! : { } ,
159
167
restoreFocus : ( ) => {
160
- if ( ! this . platform . isBrowser ) { return ; }
161
-
162
- if ( this . _getHostElement ( ) . contains ( document . activeElement ! ) ) {
168
+ if ( ! this . platform . isBrowser && this . _getHostElement ( ) . contains ( document . activeElement ! ) ) {
163
169
if ( this . _previousFocus && ( < any > this . _previousFocus ) . focus ) {
164
170
( < any > this . _previousFocus ) . focus ( ) ;
165
171
}
166
172
}
167
173
} ,
168
- getInnerDimensions : ( ) => {
169
- return { width : this . _getHostElement ( ) . offsetWidth , height : this . _getHostElement ( ) . offsetHeight } ;
170
- } ,
171
- getAnchorDimensions : ( ) => {
172
- if ( ! this . platform . isBrowser || ! this . anchorElement ) { return null ; }
173
- return this . _anchorElement ! . getBoundingClientRect ( ) ;
174
- } ,
175
- getWindowDimensions : ( ) => {
176
- return {
177
- width : this . platform . isBrowser ? window . innerWidth : 0 ,
178
- height : this . platform . isBrowser ? window . innerHeight : 0
179
- } ;
180
- } ,
181
- getBodyDimensions : ( ) => {
182
- return {
183
- width : this . platform . isBrowser ? document . body ! . clientWidth : 0 ,
184
- height : this . platform . isBrowser ? document . body ! . clientHeight : 0
185
- } ;
186
- } ,
187
- getWindowScroll : ( ) => {
188
- return {
189
- x : this . platform . isBrowser ? window . pageXOffset : 0 ,
190
- y : this . platform . isBrowser ? window . pageYOffset : 0
191
- } ;
192
- } ,
193
- setPosition : ( position : { left : number , right : number , top : number , bottom : number } ) => {
174
+ getInnerDimensions : ( ) =>
175
+ ( { width : this . _getHostElement ( ) . offsetWidth , height : this . _getHostElement ( ) . offsetHeight } ) ,
176
+ getAnchorDimensions : ( ) =>
177
+ this . platform . isBrowser || ! this . anchorElement ?
178
+ this . _anchorElement ! . getBoundingClientRect ( ) : { top : 0 , right : 0 , bottom : 0 , left : 0 , width : 0 , height : 0 } ,
179
+ getWindowDimensions : ( ) => ( {
180
+ width : this . platform . isBrowser ? window . innerWidth : 0 ,
181
+ height : this . platform . isBrowser ? window . innerHeight : 0
182
+ } ) ,
183
+ getBodyDimensions : ( ) => ( {
184
+ width : this . platform . isBrowser ? document . body ! . clientWidth : 0 ,
185
+ height : this . platform . isBrowser ? document . body ! . clientHeight : 0
186
+ } ) ,
187
+ getWindowScroll : ( ) => ( {
188
+ x : this . platform . isBrowser ? window . pageXOffset : 0 ,
189
+ y : this . platform . isBrowser ? window . pageYOffset : 0
190
+ } ) ,
191
+ setPosition : ( position : { left : number , right : number , top : number , bottom : number } ) => {
194
192
this . _getHostElement ( ) . style . left = 'left' in position ? `${ position . left } px` : '' ;
195
193
this . _getHostElement ( ) . style . right = 'right' in position ? `${ position . right } px` : '' ;
196
194
this . _getHostElement ( ) . style . top = 'top' in position ? `${ position . top } px` : '' ;
@@ -206,7 +204,6 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
206
204
public platform : Platform ,
207
205
@Optional ( ) private _ngZone : NgZone ,
208
206
public elementRef : ElementRef < HTMLElement > ) {
209
-
210
207
super ( elementRef ) ;
211
208
}
212
209
@@ -233,14 +230,16 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
233
230
234
231
protected setOpen ( ) : void {
235
232
this . _open ? this . _foundation . open ( ) : this . _foundation . close ( ) ;
236
- }
233
+ }
237
234
238
235
/**
239
236
* Removes the menu-surface from it's current location and appends it to the
240
237
* body to overcome any overflow:hidden issues.
241
238
*/
242
239
protected setHoistToBody ( ) : void {
243
- if ( ! this . platform . isBrowser ) { return ; }
240
+ if ( ! this . platform . isBrowser ) {
241
+ return ;
242
+ }
244
243
245
244
const parentEl = this . _getHostElement ( ) . parentElement ;
246
245
if ( parentEl ) {
@@ -256,7 +255,9 @@ export abstract class MdcMenuSurfaceBase extends MDCComponent<MDCMenuSurfaceFoun
256
255
}
257
256
258
257
private _registerWindowClickListener ( ) : void {
259
- if ( ! this . platform . isBrowser ) { return ; }
258
+ if ( ! this . platform . isBrowser ) {
259
+ return ;
260
+ }
260
261
261
262
this . _windowClickSubscription =
262
263
this . _ngZone . runOutsideAngular ( ( ) =>
0 commit comments