Created
March 10, 2020 09:28
-
-
Save sigma207/b9300fe12a996c07b2389ee03c1464ed to your computer and use it in GitHub Desktop.
vue-multiselect overflow directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<multiselect | |
v-select-overflow | |
... | |
/> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
install(Vue) { | |
Vue.directive('select-overflow', { | |
inserted: (el, _binding, vnode) => { | |
let originalWidth | |
let originalPosition | |
let originalZIndex | |
let selectIsOpen = false | |
vnode.child.$watch('isOpen', isOpen => { | |
selectIsOpen = isOpen | |
if (isOpen) { | |
const { offsetWidth } = el | |
originalWidth = el.style.width | |
originalPosition = el.style.position | |
originalZIndex = el.style.zIndex | |
el.style.width = `${offsetWidth}px` | |
el.style.position = 'fixed' | |
el.style.zIndex = 2 | |
} else { | |
el.style.position = originalPosition | |
el.style.width = originalWidth | |
el.style.zIndex = originalZIndex | |
} | |
}) | |
window.addEventListener('wheel', event => { | |
if (selectIsOpen) { | |
// disabled outside scroll when select is open | |
event.stopPropagation() | |
} | |
}, true) | |
}, | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A patched version is available here: shentao/vue-multiselect#723 (comment)