@@ -16,14 +16,14 @@ import {
1616 ComponentRef ,
1717 inject ,
1818} from '@angular/core' ;
19- import { BasePortalOutlet , ComponentPortal , TemplatePortal } from '../portal' ;
19+ import { ComponentPortal , TemplatePortal } from '../portal' ;
2020import { of as observableOf , Observable , Subject , defer } from 'rxjs' ;
2121import { DialogRef } from './dialog-ref' ;
22- import { DialogConfig } from './dialog-config' ;
22+ import { DialogConfig , DialogContainer } from './dialog-config' ;
2323import { Directionality } from '../bidi' ;
2424import { _IdGenerator } from '../a11y' ;
2525import { ComponentType , Overlay , OverlayRef , OverlayConfig , OverlayContainer } from '../overlay' ;
26- import { startWith } from 'rxjs/operators' ;
26+ import { startWith , take } from 'rxjs/operators' ;
2727
2828import { DEFAULT_DIALOG_CONFIG , DIALOG_DATA , DIALOG_SCROLL_STRATEGY } from './dialog-injectors' ;
2929import { CdkDialogContainer } from './dialog-container' ;
@@ -118,14 +118,24 @@ export class Dialog implements OnDestroy {
118118 const dialogRef = new DialogRef ( overlayRef , config ) ;
119119 const dialogContainer = this . _attachContainer ( overlayRef , dialogRef , config ) ;
120120
121- ( dialogRef as { containerInstance : BasePortalOutlet } ) . containerInstance = dialogContainer ;
122- this . _attachDialogContent ( componentOrTemplateRef , dialogRef , dialogContainer , config ) ;
121+ ( dialogRef as { containerInstance : DialogContainer } ) . containerInstance = dialogContainer ;
123122
124123 // If this is the first dialog that we're opening, hide all the non-overlay content.
125124 if ( ! this . openDialogs . length ) {
126- this . _hideNonDialogContentFromAssistiveTechnology ( ) ;
125+ // Resolve this ahead of time, because some internal apps
126+ // mock it out and depend on it being synchronous.
127+ const overlayContainer = this . _overlayContainer . getContainerElement ( ) ;
128+
129+ if ( dialogContainer . _focusTrapped ) {
130+ dialogContainer . _focusTrapped . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
131+ this . _hideNonDialogContentFromAssistiveTechnology ( overlayContainer ) ;
132+ } ) ;
133+ } else {
134+ this . _hideNonDialogContentFromAssistiveTechnology ( overlayContainer ) ;
135+ }
127136 }
128137
138+ this . _attachDialogContent ( componentOrTemplateRef , dialogRef , dialogContainer , config ) ;
129139 ( this . openDialogs as DialogRef < R , C > [ ] ) . push ( dialogRef ) ;
130140 dialogRef . closed . subscribe ( ( ) => this . _removeOpenDialog ( dialogRef , true ) ) ;
131141 this . afterOpened . next ( dialogRef ) ;
@@ -209,14 +219,14 @@ export class Dialog implements OnDestroy {
209219 overlay : OverlayRef ,
210220 dialogRef : DialogRef < R , C > ,
211221 config : DialogConfig < D , DialogRef < R , C > > ,
212- ) : BasePortalOutlet {
222+ ) : DialogContainer {
213223 const userInjector = config . injector || config . viewContainerRef ?. injector ;
214224 const providers : StaticProvider [ ] = [
215225 { provide : DialogConfig , useValue : config } ,
216226 { provide : DialogRef , useValue : dialogRef } ,
217227 { provide : OverlayRef , useValue : overlay } ,
218228 ] ;
219- let containerType : Type < BasePortalOutlet > ;
229+ let containerType : Type < DialogContainer > ;
220230
221231 if ( config . container ) {
222232 if ( typeof config . container === 'function' ) {
@@ -250,7 +260,7 @@ export class Dialog implements OnDestroy {
250260 private _attachDialogContent < R , D , C > (
251261 componentOrTemplateRef : ComponentType < C > | TemplateRef < C > ,
252262 dialogRef : DialogRef < R , C > ,
253- dialogContainer : BasePortalOutlet ,
263+ dialogContainer : DialogContainer ,
254264 config : DialogConfig < D , DialogRef < R , C > > ,
255265 ) {
256266 if ( componentOrTemplateRef instanceof TemplateRef ) {
@@ -292,7 +302,7 @@ export class Dialog implements OnDestroy {
292302 private _createInjector < R , D , C > (
293303 config : DialogConfig < D , DialogRef < R , C > > ,
294304 dialogRef : DialogRef < R , C > ,
295- dialogContainer : BasePortalOutlet ,
305+ dialogContainer : DialogContainer ,
296306 fallbackInjector : Injector | undefined ,
297307 ) : Injector {
298308 const userInjector = config . injector || config . viewContainerRef ?. injector ;
@@ -355,9 +365,7 @@ export class Dialog implements OnDestroy {
355365 }
356366
357367 /** Hides all of the content that isn't an overlay from assistive technology. */
358- private _hideNonDialogContentFromAssistiveTechnology ( ) {
359- const overlayContainer = this . _overlayContainer . getContainerElement ( ) ;
360-
368+ private _hideNonDialogContentFromAssistiveTechnology ( overlayContainer : HTMLElement ) {
361369 // Ensure that the overlay container is attached to the DOM.
362370 if ( overlayContainer . parentElement ) {
363371 const siblings = overlayContainer . parentElement . children ;
0 commit comments