@@ -12,8 +12,7 @@ import {
1212import { MdMenuPanel } from './menu-panel' ;
1313import { MdMenuMissingError } from './menu-errors' ;
1414import {
15- ENTER ,
16- SPACE ,
15+ isFakeMousedownFromScreenReader ,
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,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
118117 private _initMenu ( ) : void {
119118 this . _setIsMenuOpen ( true ) ;
120119
121- if ( this . _openedFromKeyboard ) {
120+ // Should only set focus if opened via the keyboard, so keyboard users can
121+ // can easily navigate menu items. According to spec, mouse users should not
122+ // see the focus style.
123+ if ( ! this . _openedByMouse ) {
122124 this . menu . focusFirstItem ( ) ;
123125 }
124126 } ;
@@ -130,10 +132,12 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
130132 private _resetMenu ( ) : void {
131133 this . _setIsMenuOpen ( false ) ;
132134
133- if ( this . _openedFromKeyboard ) {
135+ // Focus only needs to be reset to the host element if the menu was opened
136+ // by the keyboard and manually shifted to the first menu item.
137+ if ( ! this . _openedByMouse ) {
134138 this . focus ( ) ;
135- this . _openedFromKeyboard = false ;
136139 }
140+ this . _openedByMouse = false ;
137141 }
138142
139143 // set state rather than toggle to support triggers sharing a menu
@@ -191,10 +195,9 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
191195 ) ;
192196 }
193197
194- // TODO: internal
195- _handleKeydown ( event : KeyboardEvent ) : void {
196- if ( event . keyCode === ENTER || event . keyCode === SPACE ) {
197- this . _openedFromKeyboard = true ;
198+ _handleMousedown ( event : MouseEvent ) : void {
199+ if ( ! isFakeMousedownFromScreenReader ( event ) ) {
200+ this . _openedByMouse = true ;
198201 }
199202 }
200203
0 commit comments