66 * found in the LICENSE file at https://angular.io/license
77 */
88
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' ;
1111import { OverlayConfig } from './overlay-config' ;
1212import { Observable } from 'rxjs/Observable' ;
1313import { Subject } from 'rxjs/Subject' ;
@@ -39,8 +39,14 @@ export class OverlayRef implements PortalHost {
3939 return this . _pane ;
4040 }
4141
42+ attach < T > ( portal : ComponentPortal < T > ) : ComponentRef < T > ;
43+ attach < T > ( portal : TemplatePortal < T > ) : EmbeddedViewRef < T > ;
44+ attach ( portal : any ) : any ;
45+
4246 /**
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+ *
4450 * @param portal Portal instance to which to attach the overlay.
4551 * @returns The portal attachment result.
4652 */
@@ -53,8 +59,8 @@ export class OverlayRef implements PortalHost {
5359
5460 // Update the pane element with the given configuration.
5561 this . _updateStackingOrder ( ) ;
56- this . updateSize ( ) ;
57- this . updateDirection ( ) ;
62+ this . _updateElementSize ( ) ;
63+ this . _updateDirection ( ) ;
5864 this . updatePosition ( ) ;
5965
6066 if ( this . _config . scrollStrategy ) {
@@ -107,9 +113,7 @@ export class OverlayRef implements PortalHost {
107113 return detachmentResult ;
108114 }
109115
110- /**
111- * Cleans up the overlay from the DOM.
112- */
116+ /** Cleans up the overlay from the DOM. */
113117 dispose ( ) : void {
114118 if ( this . _config . positionStrategy ) {
115119 this . _config . positionStrategy . dispose ( ) ;
@@ -127,35 +131,30 @@ export class OverlayRef implements PortalHost {
127131 this . _detachments . complete ( ) ;
128132 }
129133
130- /**
131- * Checks whether the overlay has been attached.
132- */
134+ /** Whether the overlay has attached content. */
133135 hasAttached ( ) : boolean {
134136 return this . _portalHost . hasAttached ( ) ;
135137 }
136138
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. */
140140 backdropClick ( ) : Observable < void > {
141141 return this . _backdropClick . asObservable ( ) ;
142142 }
143143
144- /** Returns an observable that emits when the overlay has been attached. */
144+ /** Gets an observable that emits when the overlay has been attached. */
145145 attachments ( ) : Observable < void > {
146146 return this . _attachments . asObservable ( ) ;
147147 }
148148
149- /** Returns an observable that emits when the overlay has been detached. */
149+ /** Gets an observable that emits when the overlay has been detached. */
150150 detachments ( ) : Observable < void > {
151151 return this . _detachments . asObservable ( ) ;
152152 }
153153
154- /**
155- * Gets the current config of the overlay.
156- */
154+ /** Gets a clone of the the current overlay configuration. */
157155 getConfig ( ) : OverlayConfig {
158- return this . _config ;
156+ // Clone the config so that it cannot be modified outside of this class.
157+ return { ...this . _config } ;
159158 }
160159
161160 /** Updates the position of the overlay based on the position strategy. */
@@ -165,13 +164,19 @@ export class OverlayRef implements PortalHost {
165164 }
166165 }
167166
167+ /** Update the size properties of the overlay. */
168+ updateSize ( sizeConfig : OverlaySizeConfig ) {
169+ this . _config = { ...this . _config , ...sizeConfig } ;
170+ this . _updateElementSize ( ) ;
171+ }
172+
168173 /** Updates the text direction of the overlay panel. */
169- private updateDirection ( ) {
174+ private _updateDirection ( ) {
170175 this . _pane . setAttribute ( 'dir' , this . _config . direction ! ) ;
171176 }
172177
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 ( ) {
175180 if ( this . _config . width || this . _config . width === 0 ) {
176181 this . _pane . style . width = formatCssUnit ( this . _config . width ) ;
177182 }
@@ -220,10 +225,12 @@ export class OverlayRef implements PortalHost {
220225 this . _backdropElement . addEventListener ( 'click' , ( ) => this . _backdropClick . next ( null ) ) ;
221226
222227 // 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+ } ) ;
227234 } ) ;
228235 }
229236
@@ -284,3 +291,14 @@ export class OverlayRef implements PortalHost {
284291function formatCssUnit ( value : number | string ) {
285292 return typeof value === 'string' ? value as string : `${ value } px` ;
286293}
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