@@ -13,7 +13,7 @@ import {Observable, Subject} from 'rxjs';
13
13
import { take } from 'rxjs/operators' ;
14
14
import { OverlayKeyboardDispatcher } from './keyboard/overlay-keyboard-dispatcher' ;
15
15
import { OverlayConfig } from './overlay-config' ;
16
- import { coerceCssPixelValue } from '@angular/cdk/coercion' ;
16
+ import { coerceCssPixelValue , coerceArray } from '@angular/cdk/coercion' ;
17
17
18
18
19
19
/** An object where all of its properties cannot be written. */
@@ -115,12 +115,7 @@ export class OverlayRef implements PortalOutlet {
115
115
}
116
116
117
117
if ( this . _config . panelClass ) {
118
- // We can't do a spread here, because IE doesn't support setting multiple classes.
119
- if ( Array . isArray ( this . _config . panelClass ) ) {
120
- this . _config . panelClass . forEach ( cssClass => this . _pane . classList . add ( cssClass ) ) ;
121
- } else {
122
- this . _pane . classList . add ( this . _config . panelClass ) ;
123
- }
118
+ this . _toggleClasses ( this . _pane , this . _config . panelClass , true ) ;
124
119
}
125
120
126
121
// Only emit the `attachments` event once all other setup is done.
@@ -292,7 +287,7 @@ export class OverlayRef implements PortalOutlet {
292
287
this . _backdropElement . classList . add ( 'cdk-overlay-backdrop' ) ;
293
288
294
289
if ( this . _config . backdropClass ) {
295
- this . _backdropElement . classList . add ( this . _config . backdropClass ) ;
290
+ this . _toggleClasses ( this . _backdropElement , this . _config . backdropClass , true ) ;
296
291
}
297
292
298
293
// Insert the backdrop before the pane in the DOM order,
@@ -353,7 +348,7 @@ export class OverlayRef implements PortalOutlet {
353
348
backdropToDetach . classList . remove ( 'cdk-overlay-backdrop-showing' ) ;
354
349
355
350
if ( this . _config . backdropClass ) {
356
- backdropToDetach . classList . remove ( this . _config . backdropClass ) ;
351
+ this . _toggleClasses ( backdropToDetach , this . _config . backdropClass , false ) ;
357
352
}
358
353
359
354
backdropToDetach . addEventListener ( 'transitionend' , finishDetach ) ;
@@ -368,6 +363,16 @@ export class OverlayRef implements PortalOutlet {
368
363
this . _ngZone . runOutsideAngular ( ( ) => setTimeout ( finishDetach , 500 ) ) ;
369
364
}
370
365
}
366
+
367
+ /** Toggles a single CSS class or an array of classes on an element. */
368
+ private _toggleClasses ( element : HTMLElement , cssClasses : string | string [ ] , isAdd : boolean ) {
369
+ const classList = element . classList ;
370
+
371
+ coerceArray ( cssClasses ) . forEach ( cssClass => {
372
+ // We can't do a spread here, because IE doesn't support setting multiple classes.
373
+ isAdd ? classList . add ( cssClass ) : classList . remove ( cssClass ) ;
374
+ } ) ;
375
+ }
371
376
}
372
377
373
378
0 commit comments