@@ -307,6 +307,28 @@ describe('MatDrawer', () => {
307
307
. toBe ( openButton , 'Expected focus to be restored to the open button on close.' ) ;
308
308
} ) ) ;
309
309
310
+ it ( 'should restore focus to an SVG element' , fakeAsync ( ( ) => {
311
+ const fixture = TestBed . createComponent ( BasicTestApp ) ;
312
+ fixture . detectChanges ( ) ;
313
+
314
+ const drawer = fixture . debugElement . query ( By . directive ( MatDrawer ) ) ! . componentInstance ;
315
+ const svg = fixture . componentInstance . svg . nativeElement ;
316
+ const drawerButton = fixture . componentInstance . drawerButton . nativeElement ;
317
+
318
+ svg . focus ( ) ;
319
+ drawer . open ( ) ;
320
+ fixture . detectChanges ( ) ;
321
+ flush ( ) ;
322
+ drawerButton . focus ( ) ;
323
+
324
+ drawer . close ( ) ;
325
+ fixture . detectChanges ( ) ;
326
+ flush ( ) ;
327
+
328
+ expect ( document . activeElement )
329
+ . toBe ( svg , 'Expected focus to be restored to the SVG element on close.' ) ;
330
+ } ) ) ;
331
+
310
332
it ( 'should not restore focus on close if focus is outside drawer' , fakeAsync ( ( ) => {
311
333
let fixture = TestBed . createComponent ( BasicTestApp ) ;
312
334
let drawer : MatDrawer = fixture . debugElement
@@ -907,6 +929,14 @@ class DrawerContainerTwoDrawerTestApp {
907
929
</mat-drawer>
908
930
<button (click)="drawer.open()" class="open" #openButton></button>
909
931
<button (click)="drawer.close()" class="close" #closeButton></button>
932
+ <svg
933
+ viewBox="0 0 100 100"
934
+ xmlns="http://www.w3.org/2000/svg"
935
+ tabindex="0"
936
+ focusable="true"
937
+ #svg>
938
+ <circle cx="50" cy="50" r="50"/>
939
+ </svg>
910
940
</mat-drawer-container>` ,
911
941
} )
912
942
class BasicTestApp {
@@ -920,6 +950,7 @@ class BasicTestApp {
920
950
@ViewChild ( 'drawer' ) drawer : MatDrawer ;
921
951
@ViewChild ( 'drawerButton' ) drawerButton : ElementRef < HTMLButtonElement > ;
922
952
@ViewChild ( 'openButton' ) openButton : ElementRef < HTMLButtonElement > ;
953
+ @ViewChild ( 'svg' ) svg : ElementRef < SVGElement > ;
923
954
@ViewChild ( 'closeButton' ) closeButton : ElementRef < HTMLButtonElement > ;
924
955
925
956
open ( ) {
0 commit comments