fix(directives): use standard wheel event with passive option (#7256)

Both DOMMouseScroll and mousewheel event are non-standard now. And "[Violation]" warning will be
printed in console without setting `passive: true`.

fix #7016 #2016
This commit is contained in:
TANGENNT 2022-04-25 23:19:59 +08:00 committed by GitHub
parent 6f8d8326c3
commit 9b399385e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,4 @@
import normalizeWheel from 'normalize-wheel-es'
import { isFirefox } from '@element-plus/utils'
import type { DirectiveBinding, ObjectDirective } from 'vue'
const mousewheel = function (element, callback) {
@ -8,11 +7,7 @@ const mousewheel = function (element, callback) {
const normalized = normalizeWheel(event)
callback && Reflect.apply(callback, this, [event, normalized])
}
if (isFirefox()) {
element.addEventListener('DOMMouseScroll', fn)
} else {
element.onmousewheel = fn
}
element.addEventListener('wheel', fn, { passive: true })
}
}