@@ -12,8 +12,7 @@ import {
1212import { MdMenuPanel } from './menu-panel' ;
1313import { MdMenuMissingError } from './menu-errors' ;
1414import {
15- ENTER ,
16- SPACE ,
15+ isFakeMousedown ,
1716 Overlay ,
1817 OverlayState ,
1918 OverlayRef ,
@@ -32,8 +31,8 @@ import { Subscription } from 'rxjs/Subscription';
3231 selector : '[md-menu-trigger-for]' ,
3332 host : {
3433 'aria-haspopup' : 'true' ,
35- '(keydown )' : '_handleKeydown ($event)' ,
36- '(click)' : 'toggleMenu()'
34+ '(mousedown )' : '_handleMousedown ($event)' ,
35+ '(click)' : 'toggleMenu()' ,
3736 } ,
3837 exportAs : 'mdMenuTrigger'
3938} )
@@ -45,7 +44,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
4544
4645 // tracking input type is necessary so it's possible to only auto-focus
4746 // the first item of the list when the menu is opened via the keyboard
48- private _openedFromKeyboard : boolean = false ;
47+ private _openedByMouse : boolean = false ;
4948
5049 @Input ( 'md-menu-trigger-for' ) menu : MdMenuPanel ;
5150 @Output ( ) onMenuOpen = new EventEmitter < void > ( ) ;
@@ -118,7 +117,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
118117 private _initMenu ( ) : void {
119118 this . _setIsMenuOpen ( true ) ;
120119
121- if ( this . _openedFromKeyboard ) {
120+ if ( ! this . _openedByMouse ) {
122121 this . menu . focusFirstItem ( ) ;
123122 }
124123 } ;
@@ -130,10 +129,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
130129 private _resetMenu ( ) : void {
131130 this . _setIsMenuOpen ( false ) ;
132131
133- if ( this . _openedFromKeyboard ) {
132+ if ( ! this . _openedByMouse ) {
134133 this . focus ( ) ;
135- this . _openedFromKeyboard = false ;
136134 }
135+ this . _openedByMouse = false ;
137136 }
138137
139138 // set state rather than toggle to support triggers sharing a menu
@@ -191,10 +190,9 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
191190 ) ;
192191 }
193192
194- // TODO: internal
195- _handleKeydown ( event : KeyboardEvent ) : void {
196- if ( event . keyCode === ENTER || event . keyCode === SPACE ) {
197- this . _openedFromKeyboard = true ;
193+ _handleMousedown ( event : MouseEvent ) : void {
194+ if ( ! isFakeMousedown ( event ) ) {
195+ this . _openedByMouse = true ;
198196 }
199197 }
200198
0 commit comments