@@ -336,8 +336,8 @@ describe('MDC-based dialog', () => {
336
336
let container =
337
337
overlayContainerElement . querySelector ( 'mat-mdc-dialog-container' ) as HTMLElement ;
338
338
dispatchKeyboardEvent ( document . body , 'keydown' , A ) ;
339
- dispatchKeyboardEvent ( document . body , 'keydown' , A , undefined , backdrop ) ;
340
- dispatchKeyboardEvent ( document . body , 'keydown' , A , undefined , container ) ;
339
+ dispatchKeyboardEvent ( backdrop , 'keydown' , A ) ;
340
+ dispatchKeyboardEvent ( container , 'keydown' , A ) ;
341
341
342
342
expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
343
343
} ) ) ;
@@ -1055,6 +1055,7 @@ describe('MDC-based dialog', () => {
1055
1055
1056
1056
tick ( 500 ) ;
1057
1057
viewContainerFixture . detectChanges ( ) ;
1058
+ expect ( lastFocusOrigin ! ) . toBeNull ( 'Expected the trigger button to be blurred' ) ;
1058
1059
1059
1060
const backdrop = overlayContainerElement
1060
1061
. querySelector ( '.cdk-overlay-backdrop' ) as HTMLElement ;
@@ -1089,6 +1090,7 @@ describe('MDC-based dialog', () => {
1089
1090
1090
1091
tick ( 500 ) ;
1091
1092
viewContainerFixture . detectChanges ( ) ;
1093
+ expect ( lastFocusOrigin ! ) . toBeNull ( 'Expected the trigger button to be blurred' ) ;
1092
1094
1093
1095
const closeButton = overlayContainerElement
1094
1096
. querySelector ( 'button[mat-dialog-close]' ) as HTMLElement ;
@@ -1125,6 +1127,7 @@ describe('MDC-based dialog', () => {
1125
1127
1126
1128
tick ( 500 ) ;
1127
1129
viewContainerFixture . detectChanges ( ) ;
1130
+ expect ( lastFocusOrigin ! ) . toBeNull ( 'Expected the trigger button to be blurred' ) ;
1128
1131
1129
1132
const closeButton = overlayContainerElement
1130
1133
. querySelector ( 'button[mat-dialog-close]' ) as HTMLElement ;
@@ -1669,6 +1672,20 @@ describe('MDC-based dialog with animations enabled', () => {
1669
1672
expect ( dialogRef . getState ( ) ) . toBe ( MatDialogState . CLOSED ) ;
1670
1673
} ) ) ;
1671
1674
1675
+ it ( 'should attach the focus trap even if automatic focus is disabled' , fakeAsync ( ( ) => {
1676
+ dialog . open ( PizzaMsg , {
1677
+ viewContainerRef : testViewContainerRef ,
1678
+ autoFocus : false
1679
+ } ) ;
1680
+
1681
+ viewContainerFixture . detectChanges ( ) ;
1682
+ flush ( ) ;
1683
+
1684
+ const containerElement = overlayContainer . getContainerElement ( ) ;
1685
+ expect ( containerElement . querySelectorAll ( '.cdk-focus-trap-anchor' ) . length )
1686
+ . toBeGreaterThan ( 0 ) ;
1687
+ } ) ) ;
1688
+
1672
1689
it ( 'should re-focus trigger element when dialog closes' , fakeAsync ( ( ) => {
1673
1690
// Create a element that has focus before the dialog is opened.
1674
1691
let button = document . createElement ( 'button' ) ;
0 commit comments