File tree 4 files changed +20
-4
lines changed
tools/public_api_guard/material
4 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,9 @@ export class MatDialogConfig<D = any> {
110
110
*/
111
111
restoreFocus ?: boolean = true ;
112
112
113
+ /** Whether to wait for the opening animation to finish before trapping focus. */
114
+ delayFocusTrap ?: boolean = true ;
115
+
113
116
/** Scroll strategy to be used for the dialog. */
114
117
scrollStrategy ?: ScrollStrategy ;
115
118
Original file line number Diff line number Diff line change @@ -117,8 +117,6 @@ export abstract class _MatDialogContainerBase extends BasePortalOutlet {
117
117
if ( this . _document ) {
118
118
this . _elementFocusedBeforeDialogWasOpened = _getFocusedElementPierceShadowDom ( ) ;
119
119
}
120
-
121
- this . _trapFocus ( ) ;
122
120
}
123
121
124
122
/**
@@ -327,6 +325,10 @@ export class MatDialogContainer extends _MatDialogContainerBase {
327
325
_onAnimationDone ( { toState, totalTime} : AnimationEvent ) {
328
326
if ( toState === 'enter' ) {
329
327
this . _animationStateChanged . next ( { state : 'opened' , totalTime} ) ;
328
+
329
+ if ( this . _config . delayFocusTrap ) {
330
+ this . _trapFocus ( ) ;
331
+ }
330
332
} else if ( toState === 'exit' ) {
331
333
this . _restoreFocus ( ) ;
332
334
this . _animationStateChanged . next ( { state : 'closed' , totalTime} ) ;
@@ -350,4 +352,12 @@ export class MatDialogContainer extends _MatDialogContainerBase {
350
352
// view container is using OnPush change detection.
351
353
this . _changeDetectorRef . markForCheck ( ) ;
352
354
}
355
+
356
+ override _initializeWithAttachedContent ( ) {
357
+ super . _initializeWithAttachedContent ( ) ;
358
+
359
+ if ( ! this . _config . delayFocusTrap ) {
360
+ this . _trapFocus ( ) ;
361
+ }
362
+ }
353
363
}
Original file line number Diff line number Diff line change @@ -1388,7 +1388,7 @@ describe('MatDialog', () => {
1388
1388
1389
1389
tick ( 500 ) ;
1390
1390
viewContainerFixture . detectChanges ( ) ;
1391
- expect ( lastFocusOrigin ) . toBe ( null ) ;
1391
+ expect ( lastFocusOrigin ! ) . toBe ( 'program' ) ;
1392
1392
1393
1393
dispatchKeyboardEvent ( document . body , 'keydown' , ESCAPE ) ;
1394
1394
@@ -1421,7 +1421,7 @@ describe('MatDialog', () => {
1421
1421
1422
1422
tick ( 500 ) ;
1423
1423
viewContainerFixture . detectChanges ( ) ;
1424
- expect ( lastFocusOrigin ) . toBe ( null ) ;
1424
+ expect ( lastFocusOrigin ! ) . toBe ( 'program' ) ;
1425
1425
1426
1426
const backdrop = overlayContainerElement . querySelector (
1427
1427
'.cdk-overlay-backdrop' ,
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ export class MatDialogConfig<D = any> {
165
165
closeOnNavigation? : boolean ;
166
166
componentFactoryResolver? : ComponentFactoryResolver ;
167
167
data? : D | null ;
168
+ delayFocusTrap? : boolean ;
168
169
direction? : Direction ;
169
170
disableClose? : boolean ;
170
171
hasBackdrop? : boolean ;
@@ -185,6 +186,8 @@ export class MatDialogConfig<D = any> {
185
186
186
187
// @public
187
188
export class MatDialogContainer extends _MatDialogContainerBase {
189
+ // (undocumented)
190
+ _initializeWithAttachedContent(): void ;
188
191
_onAnimationDone({ toState , totalTime }: AnimationEvent_2 ): void ;
189
192
_onAnimationStart({ toState , totalTime }: AnimationEvent_2 ): void ;
190
193
_startExitAnimation(): void ;
You can’t perform that action at this time.
0 commit comments