@@ -238,6 +238,9 @@ const getOffsetRect = (el: HTMLElement) => {
238
238
return elementRect
239
239
}
240
240
241
+ const stopFn = ( ev : Event ) => {
242
+ ev . stopPropagation ( )
243
+ }
241
244
interface PopperOptions {
242
245
arrowOffset : number
243
246
arrowElement : string
@@ -366,6 +369,8 @@ class Popper {
366
369
update ( ) {
367
370
let data = { instance : this , styles : { } } as unknown as UpdateData
368
371
372
+ this . stopEventBubble ( ) // 每次更新都检查
373
+
369
374
this . popperOuterSize = null as unknown as { width : number ; height : number }
370
375
data . placement = data . _originalPlacement = this . _options . placement
371
376
data . offsets = this . _getRefPopOffsets ( this . _popper , this . _reference , data . placement )
@@ -377,6 +382,14 @@ class Popper {
377
382
typeof this . state . updateCallback === 'function' && this . state . updateCallback ( data )
378
383
}
379
384
385
+ // 阻止popper的mousewheel等事件冒泡。 通过 onxxx 绑定,是为了避免重复绑定事件
386
+ stopEventBubble ( ) {
387
+ if ( ! this . _popper ) return
388
+
389
+ if ( ! this . _popper . onmousewheel ) this . _popper . onmousewheel = stopFn
390
+ if ( ! this . _popper . onwheel ) this . _popper . onwheel = stopFn
391
+ }
392
+
380
393
/** 按顺序执行Modifiers, 如果传入终点modifier,则执行到指定位置 */
381
394
runModifiers ( data : UpdateData , modifiers : Function [ ] , ends ?: Function ) {
382
395
let modifiersToRun = modifiers . slice ( )
@@ -385,7 +398,7 @@ class Popper {
385
398
if ( ends !== undefined ) {
386
399
modifiersToRun = this . _options . modifierFns . slice (
387
400
0 ,
388
- _options . modifierFns . findIndex ( ( m ) => m == ends )
401
+ _options . modifierFns . findIndex ( ( m ) => m === ends )
389
402
)
390
403
}
391
404
0 commit comments