@@ -19,8 +19,9 @@ describe('MatDrawer', () => {
19
19
DrawerSetToOpenedFalse ,
20
20
DrawerSetToOpenedTrue ,
21
21
DrawerDynamicPosition ,
22
- DrawerWitFocusableElements ,
22
+ DrawerWithFocusableElements ,
23
23
DrawerOpenBinding ,
24
+ DrawerWithoutFocusableElements ,
24
25
] ,
25
26
} ) ;
26
27
@@ -363,14 +364,14 @@ describe('MatDrawer', () => {
363
364
} ) ;
364
365
365
366
describe ( 'focus trapping behavior' , ( ) => {
366
- let fixture : ComponentFixture < DrawerWitFocusableElements > ;
367
- let testComponent : DrawerWitFocusableElements ;
367
+ let fixture : ComponentFixture < DrawerWithFocusableElements > ;
368
+ let testComponent : DrawerWithFocusableElements ;
368
369
let drawer : MatDrawer ;
369
370
let firstFocusableElement : HTMLElement ;
370
371
let lastFocusableElement : HTMLElement ;
371
372
372
373
beforeEach ( ( ) => {
373
- fixture = TestBed . createComponent ( DrawerWitFocusableElements ) ;
374
+ fixture = TestBed . createComponent ( DrawerWithFocusableElements ) ;
374
375
testComponent = fixture . debugElement . componentInstance ;
375
376
drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) . componentInstance ;
376
377
firstFocusableElement = fixture . debugElement . query ( By . css ( '.link1' ) ) . nativeElement ;
@@ -410,6 +411,21 @@ describe('MatDrawer', () => {
410
411
411
412
expect ( document . activeElement ) . toBe ( lastFocusableElement ) ;
412
413
} ) ) ;
414
+
415
+ it ( 'should focus the drawer if there are no focusable elements' , fakeAsync ( ( ) => {
416
+ fixture . destroy ( ) ;
417
+
418
+ const nonFocusableFixture = TestBed . createComponent ( DrawerWithoutFocusableElements ) ;
419
+ const drawerEl = nonFocusableFixture . debugElement . query ( By . directive ( MatDrawer ) ) ;
420
+ nonFocusableFixture . detectChanges ( ) ;
421
+
422
+ drawerEl . componentInstance . open ( ) ;
423
+ nonFocusableFixture . detectChanges ( ) ;
424
+ tick ( ) ;
425
+
426
+ expect ( document . activeElement ) . toBe ( drawerEl . nativeElement ) ;
427
+ } ) ) ;
428
+
413
429
} ) ;
414
430
} ) ;
415
431
@@ -644,10 +660,19 @@ class DrawerDynamicPosition {
644
660
<a class="link2" href="#">link2</a>
645
661
</mat-drawer-container>` ,
646
662
} )
647
- class DrawerWitFocusableElements {
663
+ class DrawerWithFocusableElements {
648
664
mode : string = 'over' ;
649
665
}
650
666
667
+ @Component ( {
668
+ template : `
669
+ <mat-drawer-container>
670
+ <mat-drawer position="start" mode="over">
671
+ <button disabled>Not focusable</button>
672
+ </mat-drawer>
673
+ </mat-drawer-container>` ,
674
+ } )
675
+ class DrawerWithoutFocusableElements { }
651
676
652
677
@Component ( {
653
678
template : `
0 commit comments