@@ -26,8 +26,9 @@ describe('MatDrawer', () => {
26
26
DrawerSetToOpenedFalse ,
27
27
DrawerSetToOpenedTrue ,
28
28
DrawerDynamicPosition ,
29
- DrawerWitFocusableElements ,
29
+ DrawerWithFocusableElements ,
30
30
DrawerOpenBinding ,
31
+ DrawerWithoutFocusableElements ,
31
32
] ,
32
33
} ) ;
33
34
@@ -370,14 +371,14 @@ describe('MatDrawer', () => {
370
371
} ) ;
371
372
372
373
describe ( 'focus trapping behavior' , ( ) => {
373
- let fixture : ComponentFixture < DrawerWitFocusableElements > ;
374
- let testComponent : DrawerWitFocusableElements ;
374
+ let fixture : ComponentFixture < DrawerWithFocusableElements > ;
375
+ let testComponent : DrawerWithFocusableElements ;
375
376
let drawer : MatDrawer ;
376
377
let firstFocusableElement : HTMLElement ;
377
378
let lastFocusableElement : HTMLElement ;
378
379
379
380
beforeEach ( ( ) => {
380
- fixture = TestBed . createComponent ( DrawerWitFocusableElements ) ;
381
+ fixture = TestBed . createComponent ( DrawerWithFocusableElements ) ;
381
382
testComponent = fixture . debugElement . componentInstance ;
382
383
drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) . componentInstance ;
383
384
firstFocusableElement = fixture . debugElement . query ( By . css ( '.link1' ) ) . nativeElement ;
@@ -417,6 +418,21 @@ describe('MatDrawer', () => {
417
418
418
419
expect ( document . activeElement ) . toBe ( lastFocusableElement ) ;
419
420
} ) ) ;
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
+
420
436
} ) ;
421
437
} ) ;
422
438
@@ -676,10 +692,19 @@ class DrawerDynamicPosition {
676
692
<a class="link2" href="#">link2</a>
677
693
</mat-drawer-container>` ,
678
694
} )
679
- class DrawerWitFocusableElements {
695
+ class DrawerWithFocusableElements {
680
696
mode : string = 'over' ;
681
697
}
682
698
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 { }
683
708
684
709
@Component ( {
685
710
template : `
0 commit comments