@@ -43,7 +43,7 @@ export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
43
43
private _activeDragInstances = new Set < I > ( ) ;
44
44
45
45
/** Keeps track of the event listeners that we've bound to the `document`. */
46
- private _globalListeners = new Map < 'touchmove' | 'mousemove' | 'touchend' | 'mouseup' , {
46
+ private _globalListeners = new Map < 'touchmove' | 'mousemove' | 'touchend' | 'mouseup' | 'wheel' , {
47
47
handler : PointerEventHandler ,
48
48
options ?: AddEventListenerOptions | boolean
49
49
} > ( ) ;
@@ -81,10 +81,13 @@ export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
81
81
registerDragItem ( drag : I ) {
82
82
this . _dragInstances . add ( drag ) ;
83
83
84
+ // The `touchmove` event gets bound once, ahead of time, because WebKit
85
+ // won't preventDefault on a dynamically-added `touchmove` listener.
86
+ // See https://bugs.webkit.org/show_bug.cgi?id=184250.
84
87
if ( this . _dragInstances . size === 1 ) {
85
88
this . _ngZone . runOutsideAngular ( ( ) => {
86
- // The event handler has to be explicitly active, because
87
- // newer browsers make it passive by default.
89
+ // The event handler has to be explicitly active,
90
+ // because newer browsers make it passive by default.
88
91
this . _document . addEventListener ( 'touchmove' , this . _preventScrollListener ,
89
92
activeCapturingEventOptions ) ;
90
93
} ) ;
@@ -135,12 +138,22 @@ export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
135
138
. set ( upEvent , {
136
139
handler : e => this . pointerUp . next ( e ) ,
137
140
options : true
138
- } )
139
- . forEach ( ( config , name ) => {
140
- this . _ngZone . runOutsideAngular ( ( ) => {
141
- this . _document . addEventListener ( name , config . handler , config . options ) ;
142
- } ) ;
143
141
} ) ;
142
+
143
+ // TODO(crisbeto): prevent mouse wheel scrolling while
144
+ // dragging until we've set up proper scroll handling.
145
+ if ( ! isTouchEvent ) {
146
+ this . _globalListeners . set ( 'wheel' , {
147
+ handler : this . _preventScrollListener ,
148
+ options : activeCapturingEventOptions
149
+ } ) ;
150
+ }
151
+
152
+ this . _ngZone . runOutsideAngular ( ( ) => {
153
+ this . _globalListeners . forEach ( ( config , name ) => {
154
+ this . _document . addEventListener ( name , config . handler , config . options ) ;
155
+ } ) ;
156
+ } ) ;
144
157
}
145
158
}
146
159
@@ -173,11 +186,9 @@ export class DragDropRegistry<I, C extends {id: string}> implements OnDestroy {
173
186
}
174
187
175
188
/**
176
- * Listener used to prevent `touchmove` events while the element is being dragged.
177
- * This gets bound once, ahead of time, because WebKit won't preventDefault on a
178
- * dynamically-added `touchmove` listener. See https://bugs.webkit.org/show_bug.cgi?id=184250.
189
+ * Listener used to prevent `touchmove` and `wheel` events while the element is being dragged.
179
190
*/
180
- private _preventScrollListener = ( event : TouchEvent ) => {
191
+ private _preventScrollListener = ( event : Event ) => {
181
192
if ( this . _activeDragInstances . size ) {
182
193
event . preventDefault ( ) ;
183
194
}
0 commit comments