@@ -16,14 +16,14 @@ import {
16
16
ComponentRef ,
17
17
inject ,
18
18
} from '@angular/core' ;
19
- import { BasePortalOutlet , ComponentPortal , TemplatePortal } from '../portal' ;
19
+ import { ComponentPortal , TemplatePortal } from '../portal' ;
20
20
import { of as observableOf , Observable , Subject , defer } from 'rxjs' ;
21
21
import { DialogRef } from './dialog-ref' ;
22
- import { DialogConfig } from './dialog-config' ;
22
+ import { DialogConfig , DialogContainer } from './dialog-config' ;
23
23
import { Directionality } from '../bidi' ;
24
24
import { _IdGenerator } from '../a11y' ;
25
25
import { ComponentType , Overlay , OverlayRef , OverlayConfig , OverlayContainer } from '../overlay' ;
26
- import { startWith } from 'rxjs/operators' ;
26
+ import { startWith , take } from 'rxjs/operators' ;
27
27
28
28
import { DEFAULT_DIALOG_CONFIG , DIALOG_DATA , DIALOG_SCROLL_STRATEGY } from './dialog-injectors' ;
29
29
import { CdkDialogContainer } from './dialog-container' ;
@@ -118,14 +118,24 @@ export class Dialog implements OnDestroy {
118
118
const dialogRef = new DialogRef ( overlayRef , config ) ;
119
119
const dialogContainer = this . _attachContainer ( overlayRef , dialogRef , config ) ;
120
120
121
- ( dialogRef as { containerInstance : BasePortalOutlet } ) . containerInstance = dialogContainer ;
122
- this . _attachDialogContent ( componentOrTemplateRef , dialogRef , dialogContainer , config ) ;
121
+ ( dialogRef as { containerInstance : DialogContainer } ) . containerInstance = dialogContainer ;
123
122
124
123
// If this is the first dialog that we're opening, hide all the non-overlay content.
125
124
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
+ }
127
136
}
128
137
138
+ this . _attachDialogContent ( componentOrTemplateRef , dialogRef , dialogContainer , config ) ;
129
139
( this . openDialogs as DialogRef < R , C > [ ] ) . push ( dialogRef ) ;
130
140
dialogRef . closed . subscribe ( ( ) => this . _removeOpenDialog ( dialogRef , true ) ) ;
131
141
this . afterOpened . next ( dialogRef ) ;
@@ -209,14 +219,14 @@ export class Dialog implements OnDestroy {
209
219
overlay : OverlayRef ,
210
220
dialogRef : DialogRef < R , C > ,
211
221
config : DialogConfig < D , DialogRef < R , C > > ,
212
- ) : BasePortalOutlet {
222
+ ) : DialogContainer {
213
223
const userInjector = config . injector || config . viewContainerRef ?. injector ;
214
224
const providers : StaticProvider [ ] = [
215
225
{ provide : DialogConfig , useValue : config } ,
216
226
{ provide : DialogRef , useValue : dialogRef } ,
217
227
{ provide : OverlayRef , useValue : overlay } ,
218
228
] ;
219
- let containerType : Type < BasePortalOutlet > ;
229
+ let containerType : Type < DialogContainer > ;
220
230
221
231
if ( config . container ) {
222
232
if ( typeof config . container === 'function' ) {
@@ -250,7 +260,7 @@ export class Dialog implements OnDestroy {
250
260
private _attachDialogContent < R , D , C > (
251
261
componentOrTemplateRef : ComponentType < C > | TemplateRef < C > ,
252
262
dialogRef : DialogRef < R , C > ,
253
- dialogContainer : BasePortalOutlet ,
263
+ dialogContainer : DialogContainer ,
254
264
config : DialogConfig < D , DialogRef < R , C > > ,
255
265
) {
256
266
if ( componentOrTemplateRef instanceof TemplateRef ) {
@@ -292,7 +302,7 @@ export class Dialog implements OnDestroy {
292
302
private _createInjector < R , D , C > (
293
303
config : DialogConfig < D , DialogRef < R , C > > ,
294
304
dialogRef : DialogRef < R , C > ,
295
- dialogContainer : BasePortalOutlet ,
305
+ dialogContainer : DialogContainer ,
296
306
fallbackInjector : Injector | undefined ,
297
307
) : Injector {
298
308
const userInjector = config . injector || config . viewContainerRef ?. injector ;
@@ -355,9 +365,7 @@ export class Dialog implements OnDestroy {
355
365
}
356
366
357
367
/** 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 ) {
361
369
// Ensure that the overlay container is attached to the DOM.
362
370
if ( overlayContainer . parentElement ) {
363
371
const siblings = overlayContainer . parentElement . children ;
0 commit comments