@@ -26,8 +26,9 @@ describe('MatDrawer', () => {
2626 DrawerSetToOpenedFalse ,
2727 DrawerSetToOpenedTrue ,
2828 DrawerDynamicPosition ,
29- DrawerWitFocusableElements ,
29+ DrawerWithFocusableElements ,
3030 DrawerOpenBinding ,
31+ DrawerWithoutFocusableElements ,
3132 ] ,
3233 } ) ;
3334
@@ -370,14 +371,14 @@ describe('MatDrawer', () => {
370371 } ) ;
371372
372373 describe ( 'focus trapping behavior' , ( ) => {
373- let fixture : ComponentFixture < DrawerWitFocusableElements > ;
374- let testComponent : DrawerWitFocusableElements ;
374+ let fixture : ComponentFixture < DrawerWithFocusableElements > ;
375+ let testComponent : DrawerWithFocusableElements ;
375376 let drawer : MatDrawer ;
376377 let firstFocusableElement : HTMLElement ;
377378 let lastFocusableElement : HTMLElement ;
378379
379380 beforeEach ( ( ) => {
380- fixture = TestBed . createComponent ( DrawerWitFocusableElements ) ;
381+ fixture = TestBed . createComponent ( DrawerWithFocusableElements ) ;
381382 testComponent = fixture . debugElement . componentInstance ;
382383 drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) . componentInstance ;
383384 firstFocusableElement = fixture . debugElement . query ( By . css ( '.link1' ) ) . nativeElement ;
@@ -417,6 +418,21 @@ describe('MatDrawer', () => {
417418
418419 expect ( document . activeElement ) . toBe ( lastFocusableElement ) ;
419420 } ) ) ;
421+
422+ it ( 'should focus the drawer if there are no focusable elements' , fakeAsync ( ( ) => {
423+ fixture . destroy ( ) ;
424+
425+ const nonFocusableFixture = TestBed . createComponent ( DrawerWithoutFocusableElements ) ;
426+ const drawerEl = nonFocusableFixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
427+ nonFocusableFixture . detectChanges ( ) ;
428+
429+ drawerEl . componentInstance . open ( ) ;
430+ nonFocusableFixture . detectChanges ( ) ;
431+ tick ( ) ;
432+
433+ expect ( document . activeElement ) . toBe ( drawerEl . nativeElement ) ;
434+ } ) ) ;
435+
420436 } ) ;
421437} ) ;
422438
@@ -676,10 +692,19 @@ class DrawerDynamicPosition {
676692 <a class="link2" href="#">link2</a>
677693 </mat-drawer-container>` ,
678694} )
679- class DrawerWitFocusableElements {
695+ class DrawerWithFocusableElements {
680696 mode : string = 'over' ;
681697}
682698
699+ @Component ( {
700+ template : `
701+ <mat-drawer-container>
702+ <mat-drawer position="start" mode="over">
703+ <button disabled>Not focusable</button>
704+ </mat-drawer>
705+ </mat-drawer-container>` ,
706+ } )
707+ class DrawerWithoutFocusableElements { }
683708
684709@Component ( {
685710 template : `
0 commit comments