@@ -20,6 +20,8 @@ import {FocusKeyManager} from '../core/a11y/focus-key-manager';
2020import { MdMenuPanel } from './menu-panel' ;
2121import { Subscription } from 'rxjs/Subscription' ;
2222import { transformMenu , fadeInItems } from './menu-animations' ;
23+ import { ESCAPE } from '../core/keyboard/keycodes' ;
24+
2325
2426@Component ( {
2527 moduleId : module . id ,
@@ -75,17 +77,6 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
7577 /** Whether the menu should overlap its trigger. */
7678 @Input ( ) overlapTrigger = true ;
7779
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-
8980 /**
9081 * This method takes classes set on the host md-menu element and applies them on the
9182 * menu template that displays in the overlay container. Otherwise, it's difficult
@@ -104,6 +95,28 @@ export class MdMenu implements AfterContentInit, MdMenuPanel, OnDestroy {
10495 /** Event emitted when the menu is closed. */
10596 @Output ( ) close = new EventEmitter < void > ( ) ;
10697
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+
107120 /**
108121 * Focus the first item in the menu. This method is used by the menu trigger
109122 * to focus the first item when the menu is opened by the ENTER key.
0 commit comments