1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-05-17 14:22:02 +00:00
bramw_baserow/web-frontend/modules/core/directives/preventParentScroll.js
2021-01-06 20:23:15 +00:00

23 lines
1 KiB
JavaScript

/**
* Because the scroll directive uses the wheel event it prevents all other elements
* being able to scroll. This directive can be used on a child element that supports
* scrolling, it makes sure that scrolling works and so that it doesn't scroll the
* parent.
*/
export default {
bind(el) {
el.preventParentScrollDirectiveEvent = (event) => {
event.stopPropagation()
}
el.addEventListener('wheel', el.preventParentScrollDirectiveEvent)
el.addEventListener('touchstart', el.preventParentScrollDirectiveEvent)
el.addEventListener('touchend', el.preventParentScrollDirectiveEvent)
el.addEventListener('touchmove', el.preventParentScrollDirectiveEvent)
},
unbind(el) {
el.removeEventListener('wheel', el.preventParentScrollDirectiveEvent)
el.removeEventListener('touchstart', el.preventParentScrollDirectiveEvent)
el.removeEventListener('touchend', el.preventParentScrollDirectiveEvent)
el.removeEventListener('touchmove', el.preventParentScrollDirectiveEvent)
},
}