@@ -19,7 +19,7 @@ import {
19
19
signal ,
20
20
} from '@angular/core' ;
21
21
import { Observable , Subject , defer } from 'rxjs' ;
22
- import { startWith } from 'rxjs/operators' ;
22
+ import { startWith , take } from 'rxjs/operators' ;
23
23
import { _IdGenerator } from '../a11y' ;
24
24
import { Direction , Directionality } from '../bidi' ;
25
25
import {
@@ -30,8 +30,8 @@ import {
30
30
OverlayContainer ,
31
31
OverlayRef ,
32
32
} from '../overlay' ;
33
- import { BasePortalOutlet , ComponentPortal , TemplatePortal } from '../portal' ;
34
- import { DialogConfig } from './dialog-config' ;
33
+ import { ComponentPortal , TemplatePortal } from '../portal' ;
34
+ import { DialogConfig , DialogContainer } from './dialog-config' ;
35
35
import { DialogRef } from './dialog-ref' ;
36
36
37
37
import { CdkDialogContainer } from './dialog-container' ;
@@ -141,14 +141,24 @@ export class Dialog implements OnDestroy {
141
141
const dialogRef = new DialogRef ( overlayRef , config ) ;
142
142
const dialogContainer = this . _attachContainer ( overlayRef , dialogRef , config ) ;
143
143
144
- ( dialogRef as { containerInstance : BasePortalOutlet } ) . containerInstance = dialogContainer ;
145
- this . _attachDialogContent ( componentOrTemplateRef , dialogRef , dialogContainer , config ) ;
144
+ ( dialogRef as { containerInstance : DialogContainer } ) . containerInstance = dialogContainer ;
146
145
147
146
// If this is the first dialog that we're opening, hide all the non-overlay content.
148
147
if ( ! this . openDialogs . length ) {
149
- this . _hideNonDialogContentFromAssistiveTechnology ( ) ;
148
+ // Resolve this ahead of time, because some internal apps
149
+ // mock it out and depend on it being synchronous.
150
+ const overlayContainer = this . _overlayContainer . getContainerElement ( ) ;
151
+
152
+ if ( dialogContainer . _focusTrapped ) {
153
+ dialogContainer . _focusTrapped . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
154
+ this . _hideNonDialogContentFromAssistiveTechnology ( overlayContainer ) ;
155
+ } ) ;
156
+ } else {
157
+ this . _hideNonDialogContentFromAssistiveTechnology ( overlayContainer ) ;
158
+ }
150
159
}
151
160
161
+ this . _attachDialogContent ( componentOrTemplateRef , dialogRef , dialogContainer , config ) ;
152
162
( this . openDialogs as DialogRef < R , C > [ ] ) . push ( dialogRef ) ;
153
163
dialogRef . closed . subscribe ( ( ) => this . _removeOpenDialog ( dialogRef , true ) ) ;
154
164
this . afterOpened . next ( dialogRef ) ;
@@ -233,14 +243,14 @@ export class Dialog implements OnDestroy {
233
243
overlay : OverlayRef ,
234
244
dialogRef : DialogRef < R , C > ,
235
245
config : DialogConfig < D , DialogRef < R , C > > ,
236
- ) : BasePortalOutlet {
246
+ ) : DialogContainer {
237
247
const userInjector = config . injector || config . viewContainerRef ?. injector ;
238
248
const providers : StaticProvider [ ] = [
239
249
{ provide : DialogConfig , useValue : config } ,
240
250
{ provide : DialogRef , useValue : dialogRef } ,
241
251
{ provide : OverlayRef , useValue : overlay } ,
242
252
] ;
243
- let containerType : Type < BasePortalOutlet > ;
253
+ let containerType : Type < DialogContainer > ;
244
254
245
255
if ( config . container ) {
246
256
if ( typeof config . container === 'function' ) {
@@ -274,7 +284,7 @@ export class Dialog implements OnDestroy {
274
284
private _attachDialogContent < R , D , C > (
275
285
componentOrTemplateRef : ComponentType < C > | TemplateRef < C > ,
276
286
dialogRef : DialogRef < R , C > ,
277
- dialogContainer : BasePortalOutlet ,
287
+ dialogContainer : DialogContainer ,
278
288
config : DialogConfig < D , DialogRef < R , C > > ,
279
289
) {
280
290
if ( componentOrTemplateRef instanceof TemplateRef ) {
@@ -316,7 +326,7 @@ export class Dialog implements OnDestroy {
316
326
private _createInjector < R , D , C > (
317
327
config : DialogConfig < D , DialogRef < R , C > > ,
318
328
dialogRef : DialogRef < R , C > ,
319
- dialogContainer : BasePortalOutlet ,
329
+ dialogContainer : DialogContainer ,
320
330
fallbackInjector : Injector | undefined ,
321
331
) : Injector {
322
332
const userInjector = config . injector || config . viewContainerRef ?. injector ;
@@ -379,9 +389,7 @@ export class Dialog implements OnDestroy {
379
389
}
380
390
381
391
/** Hides all of the content that isn't an overlay from assistive technology. */
382
- private _hideNonDialogContentFromAssistiveTechnology ( ) {
383
- const overlayContainer = this . _overlayContainer . getContainerElement ( ) ;
384
-
392
+ private _hideNonDialogContentFromAssistiveTechnology ( overlayContainer : HTMLElement ) {
385
393
// Ensure that the overlay container is attached to the DOM.
386
394
if ( overlayContainer . parentElement ) {
387
395
const siblings = overlayContainer . parentElement . children ;
0 commit comments