6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { NgZone } from '@angular/core' ;
10
- import { PortalHost , Portal } from '@angular/cdk/portal' ;
9
+ import { NgZone , ComponentRef , EmbeddedViewRef } from '@angular/core' ;
10
+ import { PortalHost , Portal , ComponentPortal , TemplatePortal } from '@angular/cdk/portal' ;
11
11
import { OverlayConfig } from './overlay-config' ;
12
12
import { Observable } from 'rxjs/Observable' ;
13
13
import { Subject } from 'rxjs/Subject' ;
@@ -39,8 +39,14 @@ export class OverlayRef implements PortalHost {
39
39
return this . _pane ;
40
40
}
41
41
42
+ attach < T > ( portal : ComponentPortal < T > ) : ComponentRef < T > ;
43
+ attach < T > ( portal : TemplatePortal < T > ) : EmbeddedViewRef < T > ;
44
+ attach ( portal : any ) : any ;
45
+
42
46
/**
43
- * Attaches the overlay to a portal instance and adds the backdrop.
47
+ * Attaches content, given via a Portal, to the overlay.
48
+ * If the overlay is configured to have a backdrop, it will be created.
49
+ *
44
50
* @param portal Portal instance to which to attach the overlay.
45
51
* @returns The portal attachment result.
46
52
*/
@@ -53,8 +59,8 @@ export class OverlayRef implements PortalHost {
53
59
54
60
// Update the pane element with the given configuration.
55
61
this . _updateStackingOrder ( ) ;
56
- this . updateSize ( ) ;
57
- this . updateDirection ( ) ;
62
+ this . _updateElementSize ( ) ;
63
+ this . _updateDirection ( ) ;
58
64
this . updatePosition ( ) ;
59
65
60
66
if ( this . _config . scrollStrategy ) {
@@ -107,9 +113,7 @@ export class OverlayRef implements PortalHost {
107
113
return detachmentResult ;
108
114
}
109
115
110
- /**
111
- * Cleans up the overlay from the DOM.
112
- */
116
+ /** Cleans up the overlay from the DOM. */
113
117
dispose ( ) : void {
114
118
if ( this . _config . positionStrategy ) {
115
119
this . _config . positionStrategy . dispose ( ) ;
@@ -127,35 +131,30 @@ export class OverlayRef implements PortalHost {
127
131
this . _detachments . complete ( ) ;
128
132
}
129
133
130
- /**
131
- * Checks whether the overlay has been attached.
132
- */
134
+ /** Whether the overlay has attached content. */
133
135
hasAttached ( ) : boolean {
134
136
return this . _portalHost . hasAttached ( ) ;
135
137
}
136
138
137
- /**
138
- * Returns an observable that emits when the backdrop has been clicked.
139
- */
139
+ /** Gets an observable that emits when the backdrop has been clicked. */
140
140
backdropClick ( ) : Observable < void > {
141
141
return this . _backdropClick . asObservable ( ) ;
142
142
}
143
143
144
- /** Returns an observable that emits when the overlay has been attached. */
144
+ /** Gets an observable that emits when the overlay has been attached. */
145
145
attachments ( ) : Observable < void > {
146
146
return this . _attachments . asObservable ( ) ;
147
147
}
148
148
149
- /** Returns an observable that emits when the overlay has been detached. */
149
+ /** Gets an observable that emits when the overlay has been detached. */
150
150
detachments ( ) : Observable < void > {
151
151
return this . _detachments . asObservable ( ) ;
152
152
}
153
153
154
- /**
155
- * Gets the current config of the overlay.
156
- */
154
+ /** Gets a clone of the the current overlay configuration. */
157
155
getConfig ( ) : OverlayConfig {
158
- return this . _config ;
156
+ // Clone the config so that it cannot be modified outside of this class.
157
+ return { ...this . _config } ;
159
158
}
160
159
161
160
/** Updates the position of the overlay based on the position strategy. */
@@ -165,13 +164,19 @@ export class OverlayRef implements PortalHost {
165
164
}
166
165
}
167
166
167
+ /** Update the size properties of the overlay. */
168
+ updateSize ( sizeConfig : OverlaySizeConfig ) {
169
+ this . _config = { ...this . _config , ...sizeConfig } ;
170
+ this . _updateElementSize ( ) ;
171
+ }
172
+
168
173
/** Updates the text direction of the overlay panel. */
169
- private updateDirection ( ) {
174
+ private _updateDirection ( ) {
170
175
this . _pane . setAttribute ( 'dir' , this . _config . direction ! ) ;
171
176
}
172
177
173
- /** Updates the size of the overlay based on the overlay config. */
174
- updateSize ( ) {
178
+ /** Updates the size of the overlay element based on the overlay config. */
179
+ private _updateElementSize ( ) {
175
180
if ( this . _config . width || this . _config . width === 0 ) {
176
181
this . _pane . style . width = formatCssUnit ( this . _config . width ) ;
177
182
}
@@ -220,10 +225,12 @@ export class OverlayRef implements PortalHost {
220
225
this . _backdropElement . addEventListener ( 'click' , ( ) => this . _backdropClick . next ( null ) ) ;
221
226
222
227
// Add class to fade-in the backdrop after one frame.
223
- requestAnimationFrame ( ( ) => {
224
- if ( this . _backdropElement ) {
225
- this . _backdropElement . classList . add ( 'cdk-overlay-backdrop-showing' ) ;
226
- }
228
+ this . _ngZone . runOutsideAngular ( ( ) => {
229
+ requestAnimationFrame ( ( ) => {
230
+ if ( this . _backdropElement ) {
231
+ this . _backdropElement . classList . add ( 'cdk-overlay-backdrop-showing' ) ;
232
+ }
233
+ } ) ;
227
234
} ) ;
228
235
}
229
236
@@ -284,3 +291,14 @@ export class OverlayRef implements PortalHost {
284
291
function formatCssUnit ( value : number | string ) {
285
292
return typeof value === 'string' ? value as string : `${ value } px` ;
286
293
}
294
+
295
+
296
+ /** Size properties for an overlay. */
297
+ export interface OverlaySizeConfig {
298
+ width ?: number | string ;
299
+ height ?: number | string ;
300
+ minWidth ?: number | string ;
301
+ minHeight ?: number | string ;
302
+ maxWidth ?: number | string ;
303
+ maxHeight ?: number | string ;
304
+ } ;
0 commit comments