@@ -102,6 +102,18 @@ describe('MdDrawer', () => {
102
102
expect ( testComponent . backdropClickedCount ) . toBe ( 1 ) ;
103
103
} ) ) ;
104
104
105
+ it ( 'should emit the escapeKeydown event when ESCAPE key is pressed' , ( ) => {
106
+ let fixture = TestBed . createComponent ( BasicTestApp ) ;
107
+ let testComponent : BasicTestApp = fixture . debugElement . componentInstance ;
108
+ let drawer = fixture . debugElement . query ( By . directive ( MdDrawer ) ) ;
109
+ expect ( testComponent . escapeKeydownCount ) . toBe ( 0 ) ;
110
+
111
+ dispatchKeyboardEvent ( drawer . nativeElement , 'keydown' , ESCAPE ) ;
112
+ fixture . detectChanges ( ) ;
113
+
114
+ expect ( testComponent . escapeKeydownCount ) . toBe ( 1 ) ;
115
+ } ) ;
116
+
105
117
it ( 'should close when pressing escape' , fakeAsync ( ( ) => {
106
118
let fixture = TestBed . createComponent ( BasicTestApp ) ;
107
119
@@ -386,7 +398,8 @@ class DrawerContainerTwoDrawerTestApp {
386
398
<md-drawer-container (backdropClick)="backdropClicked()">
387
399
<md-drawer #drawer position="start"
388
400
(open)="open()"
389
- (close)="close()">
401
+ (close)="close()"
402
+ (escapeKeydown)="escapeKeydown()">
390
403
<button #drawerButton>Content.</button>
391
404
</md-drawer>
392
405
<button (click)="drawer.open()" class="open" #openButton></button>
@@ -397,6 +410,7 @@ class BasicTestApp {
397
410
openCount : number = 0 ;
398
411
closeCount : number = 0 ;
399
412
backdropClickedCount : number = 0 ;
413
+ escapeKeydownCount : number = 0 ;
400
414
401
415
@ViewChild ( 'drawerButton' ) drawerButton : ElementRef ;
402
416
@ViewChild ( 'openButton' ) openButton : ElementRef ;
@@ -413,6 +427,10 @@ class BasicTestApp {
413
427
backdropClicked ( ) {
414
428
this . backdropClickedCount ++ ;
415
429
}
430
+
431
+ escapeKeydown ( ) {
432
+ this . escapeKeydownCount ++ ;
433
+ }
416
434
}
417
435
418
436
@Component ( {
0 commit comments