File tree Expand file tree Collapse file tree 4 files changed +20
-4
lines changed
tools/public_api_guard/material Expand file tree Collapse file tree 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> {
110110 */
111111 restoreFocus ?: boolean = true ;
112112
113+ /** Whether to wait for the opening animation to finish before trapping focus. */
114+ delayFocusTrap ?: boolean = true ;
115+
113116 /** Scroll strategy to be used for the dialog. */
114117 scrollStrategy ?: ScrollStrategy ;
115118
Original file line number Diff line number Diff line change @@ -117,8 +117,6 @@ export abstract class _MatDialogContainerBase extends BasePortalOutlet {
117117 if ( this . _document ) {
118118 this . _elementFocusedBeforeDialogWasOpened = _getFocusedElementPierceShadowDom ( ) ;
119119 }
120-
121- this . _trapFocus ( ) ;
122120 }
123121
124122 /**
@@ -327,6 +325,10 @@ export class MatDialogContainer extends _MatDialogContainerBase {
327325 _onAnimationDone ( { toState, totalTime} : AnimationEvent ) {
328326 if ( toState === 'enter' ) {
329327 this . _animationStateChanged . next ( { state : 'opened' , totalTime} ) ;
328+
329+ if ( this . _config . delayFocusTrap ) {
330+ this . _trapFocus ( ) ;
331+ }
330332 } else if ( toState === 'exit' ) {
331333 this . _restoreFocus ( ) ;
332334 this . _animationStateChanged . next ( { state : 'closed' , totalTime} ) ;
@@ -350,4 +352,12 @@ export class MatDialogContainer extends _MatDialogContainerBase {
350352 // view container is using OnPush change detection.
351353 this . _changeDetectorRef . markForCheck ( ) ;
352354 }
355+
356+ override _initializeWithAttachedContent ( ) {
357+ super . _initializeWithAttachedContent ( ) ;
358+
359+ if ( ! this . _config . delayFocusTrap ) {
360+ this . _trapFocus ( ) ;
361+ }
362+ }
353363}
Original file line number Diff line number Diff line change @@ -1388,7 +1388,7 @@ describe('MatDialog', () => {
13881388
13891389 tick ( 500 ) ;
13901390 viewContainerFixture . detectChanges ( ) ;
1391- expect ( lastFocusOrigin ) . toBe ( null ) ;
1391+ expect ( lastFocusOrigin ! ) . toBe ( 'program' ) ;
13921392
13931393 dispatchKeyboardEvent ( document . body , 'keydown' , ESCAPE ) ;
13941394
@@ -1421,7 +1421,7 @@ describe('MatDialog', () => {
14211421
14221422 tick ( 500 ) ;
14231423 viewContainerFixture . detectChanges ( ) ;
1424- expect ( lastFocusOrigin ) . toBe ( null ) ;
1424+ expect ( lastFocusOrigin ! ) . toBe ( 'program' ) ;
14251425
14261426 const backdrop = overlayContainerElement . querySelector (
14271427 '.cdk-overlay-backdrop' ,
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ export class MatDialogConfig<D = any> {
165165 closeOnNavigation? : boolean ;
166166 componentFactoryResolver? : ComponentFactoryResolver ;
167167 data? : D | null ;
168+ delayFocusTrap? : boolean ;
168169 direction? : Direction ;
169170 disableClose? : boolean ;
170171 hasBackdrop? : boolean ;
@@ -185,6 +186,8 @@ export class MatDialogConfig<D = any> {
185186
186187// @public
187188export class MatDialogContainer extends _MatDialogContainerBase {
189+ // (undocumented)
190+ _initializeWithAttachedContent(): void ;
188191 _onAnimationDone({ toState , totalTime }: AnimationEvent_2 ): void ;
189192 _onAnimationStart({ toState , totalTime }: AnimationEvent_2 ): void ;
190193 _startExitAnimation(): void ;
You can’t perform that action at this time.
0 commit comments