@@ -20,6 +20,8 @@ import {FocusKeyManager} from '../core/a11y/focus-key-manager';
20
20
import { MdMenuPanel } from './menu-panel' ;
21
21
import { Subscription } from 'rxjs/Subscription' ;
22
22
import { transformMenu , fadeInItems } from './menu-animations' ;
23
+ import { ESCAPE } from '../core/keyboard/keycodes' ;
24
+
23
25
24
26
@Component ( {
25
27
moduleId : module . id ,
@@ -75,17 +77,6 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
75
77
/** Whether the menu should overlap its trigger. */
76
78
@Input ( ) overlapTrigger = true ;
77
79
78
- ngAfterContentInit ( ) {
79
- this . _keyManager = new FocusKeyManager ( this . items ) . withWrap ( ) ;
80
- this . _tabSubscription = this . _keyManager . tabOut . subscribe ( ( ) => this . _emitCloseEvent ( ) ) ;
81
- }
82
-
83
- ngOnDestroy ( ) {
84
- if ( this . _tabSubscription ) {
85
- this . _tabSubscription . unsubscribe ( ) ;
86
- }
87
- }
88
-
89
80
/**
90
81
* This method takes classes set on the host md-menu element and applies them on the
91
82
* menu template that displays in the overlay container. Otherwise, it's difficult
@@ -104,6 +95,28 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
104
95
/** Event emitted when the menu is closed. */
105
96
@Output ( ) close = new EventEmitter < void > ( ) ;
106
97
98
+ ngAfterContentInit ( ) {
99
+ this . _keyManager = new FocusKeyManager ( this . items ) . withWrap ( ) ;
100
+ this . _tabSubscription = this . _keyManager . tabOut . subscribe ( ( ) => this . _emitCloseEvent ( ) ) ;
101
+ }
102
+
103
+ ngOnDestroy ( ) {
104
+ if ( this . _tabSubscription ) {
105
+ this . _tabSubscription . unsubscribe ( ) ;
106
+ }
107
+ }
108
+
109
+ /** Handle a keyboard event from the menu, delegating to the appropriate action. */
110
+ _handleKeydown ( event : KeyboardEvent ) {
111
+ switch ( event . keyCode ) {
112
+ case ESCAPE :
113
+ this . _emitCloseEvent ( ) ;
114
+ return ;
115
+ default :
116
+ this . _keyManager . onKeydown ( event ) ;
117
+ }
118
+ }
119
+
107
120
/**
108
121
* Focus the first item in the menu. This method is used by the menu trigger
109
122
* to focus the first item when the menu is opened by the ENTER key.
0 commit comments