@@ -12,8 +12,7 @@ import {
12
12
import { MdMenuPanel } from './menu-panel' ;
13
13
import { MdMenuMissingError } from './menu-errors' ;
14
14
import {
15
- ENTER ,
16
- SPACE ,
15
+ isFakeMousedownFromScreenReader ,
17
16
Overlay ,
18
17
OverlayState ,
19
18
OverlayRef ,
@@ -32,8 +31,8 @@ import { Subscription } from 'rxjs/Subscription';
32
31
selector : '[md-menu-trigger-for]' ,
33
32
host : {
34
33
'aria-haspopup' : 'true' ,
35
- '(keydown )' : '_handleKeydown ($event)' ,
36
- '(click)' : 'toggleMenu()'
34
+ '(mousedown )' : '_handleMousedown ($event)' ,
35
+ '(click)' : 'toggleMenu()' ,
37
36
} ,
38
37
exportAs : 'mdMenuTrigger'
39
38
} )
@@ -45,7 +44,7 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
45
44
46
45
// tracking input type is necessary so it's possible to only auto-focus
47
46
// the first item of the list when the menu is opened via the keyboard
48
- private _openedFromKeyboard : boolean = false ;
47
+ private _openedByMouse : boolean = false ;
49
48
50
49
@Input ( 'md-menu-trigger-for' ) menu : MdMenuPanel ;
51
50
@Output ( ) onMenuOpen = new EventEmitter < void > ( ) ;
@@ -118,7 +117,10 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
118
117
private _initMenu ( ) : void {
119
118
this . _setIsMenuOpen ( true ) ;
120
119
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 ) {
122
124
this . menu . focusFirstItem ( ) ;
123
125
}
124
126
} ;
@@ -130,10 +132,12 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
130
132
private _resetMenu ( ) : void {
131
133
this . _setIsMenuOpen ( false ) ;
132
134
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 ) {
134
138
this . focus ( ) ;
135
- this . _openedFromKeyboard = false ;
136
139
}
140
+ this . _openedByMouse = false ;
137
141
}
138
142
139
143
// set state rather than toggle to support triggers sharing a menu
@@ -191,10 +195,9 @@ export class MdMenuTrigger implements AfterViewInit, OnDestroy {
191
195
) ;
192
196
}
193
197
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 ;
198
201
}
199
202
}
200
203
0 commit comments