@@ -33,6 +33,7 @@ import {
33
33
Self ,
34
34
ViewContainerRef ,
35
35
} from '@angular/core' ;
36
+ import { normalizePassiveListenerOptions } from '@angular/cdk/platform' ;
36
37
import { asapScheduler , merge , of as observableOf , Subscription } from 'rxjs' ;
37
38
import { delay , filter , take , takeUntil } from 'rxjs/operators' ;
38
39
import { MatMenu } from './menu-directive' ;
@@ -60,6 +61,9 @@ export const MAT_MENU_SCROLL_STRATEGY_FACTORY_PROVIDER = {
60
61
/** Default top padding of the menu panel. */
61
62
export const MENU_PANEL_TOP_PADDING = 8 ;
62
63
64
+ /** Options for binding a passive event listener. */
65
+ const passiveEventListenerOptions = normalizePassiveListenerOptions ( { passive : true } ) ;
66
+
63
67
// TODO(andrewseguin): Remove the kebab versions in favor of camelCased attribute selectors
64
68
65
69
/**
@@ -72,7 +76,6 @@ export const MENU_PANEL_TOP_PADDING = 8;
72
76
'aria-haspopup' : 'true' ,
73
77
'[attr.aria-expanded]' : 'menuOpen || null' ,
74
78
'(mousedown)' : '_handleMousedown($event)' ,
75
- '(touchstart)' : '_openedBy = "touch"' ,
76
79
'(keydown)' : '_handleKeydown($event)' ,
77
80
'(click)' : '_handleClick($event)' ,
78
81
} ,
@@ -87,6 +90,12 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
87
90
private _menuCloseSubscription = Subscription . EMPTY ;
88
91
private _scrollStrategy : ( ) => ScrollStrategy ;
89
92
93
+ /**
94
+ * Handles touch start events on the trigger.
95
+ * Needs to be an arrow function so we can easily use addEventListener and removeEventListener.
96
+ */
97
+ private _handleTouchStart = ( ) => this . _openedBy = 'touch' ;
98
+
90
99
// Tracking input type is necessary so it's possible to only auto-focus
91
100
// the first item of the list when the menu is opened via the keyboard
92
101
_openedBy : 'mouse' | 'touch' | null = null ;
@@ -161,6 +170,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
161
170
// @breaking -change 8.0.0
162
171
private _focusMonitor ?: FocusMonitor ) {
163
172
173
+ _element . nativeElement . addEventListener ( 'touchstart' , this . _handleTouchStart ,
174
+ passiveEventListenerOptions ) ;
175
+
164
176
if ( _menuItemInstance ) {
165
177
_menuItemInstance . _triggersSubmenu = this . triggersSubmenu ( ) ;
166
178
}
@@ -179,6 +191,9 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
179
191
this . _overlayRef = null ;
180
192
}
181
193
194
+ this . _element . nativeElement . removeEventListener ( 'touchstart' , this . _handleTouchStart ,
195
+ passiveEventListenerOptions ) ;
196
+
182
197
this . _cleanUpSubscriptions ( ) ;
183
198
}
184
199
0 commit comments