@@ -152,7 +152,11 @@ export class EventDelegator {
152152 infoForElement . preventDefault ( eventName , value ) ;
153153
154154 if ( ! currentValue && value ) {
155- this . eventInfoStore . addGlobalListener ( eventName ) ;
155+ // To ensure that preventDefault works for wheel and touch events,,
156+ // we need to register a listener with the passive mode explicitly disabled.
157+ // Note that this does not change behavior for other events as those
158+ // use active mode by default.
159+ this . eventInfoStore . addActiveGlobalListener ( eventName ) ;
156160 } else if ( currentValue && ! value ) {
157161 this . eventInfoStore . decrementCountByEventName ( eventName ) ;
158162 }
@@ -293,6 +297,25 @@ class EventInfoStore {
293297 }
294298 }
295299
300+ public addActiveGlobalListener ( eventName : string ) {
301+ // If this event name is an alias, update the global listener for the corresponding browser event
302+ eventName = getBrowserEventName ( eventName ) ;
303+
304+ // If the listener for this event is already registered, we recreate it to ensure
305+ // that it is using the active mode.
306+ if ( Object . prototype . hasOwnProperty . call ( this . countByEventName , eventName ) ) {
307+ this . countByEventName [ eventName ] ++ ;
308+ document . removeEventListener ( eventName , this . globalListener ) ;
309+ } else {
310+ this . countByEventName [ eventName ] = 1 ;
311+ }
312+
313+ // To make delegation work with non-bubbling events, register a 'capture' listener.
314+ // We preserve the non-bubbling behavior by only dispatching such events to the targeted element.
315+ const useCapture = Object . prototype . hasOwnProperty . call ( nonBubblingEvents , eventName ) ;
316+ document . addEventListener ( eventName , this . globalListener , { capture : useCapture , passive : false } ) ;
317+ }
318+
296319 public update ( oldEventHandlerId : number , newEventHandlerId : number ) {
297320 if ( Object . prototype . hasOwnProperty . call ( this . infosByEventHandlerId , newEventHandlerId ) ) {
298321 // Should never happen, but we want to know if it does
0 commit comments