2
0
mirror of https://github.com/tenrok/vue-select.git synced 2026-05-17 02:29:37 +03:00
Files
vue-select/src/directives/appendToBody.js
T
Rafał Gałka f2479434e4 fix: memory leak when positioning with popper (#1094)
* fix: memory leak when positioning with popper
* docs: update calculate position docs

Co-authored-by: Jeff <sagalbot@gmail.com>
2020-03-09 19:08:57 -07:00

27 lines
830 B
JavaScript

export default {
inserted (el, bindings, {context}) {
if (context.appendToBody) {
const {height, top, left} = context.$refs.toggle.getBoundingClientRect();
el.unbindPosition = context.calculatePosition(el, context, {
width: context.$refs.toggle.clientWidth + 'px',
top: (window.scrollY + top + height) + 'px',
left: (window.scrollX + left) + 'px',
});
document.body.appendChild(el);
}
},
unbind (el, bindings, {context}) {
if (context.appendToBody) {
if (el.unbindPosition && typeof el.unbindPosition === 'function') {
el.unbindPosition();
}
if (el.parentNode) {
el.parentNode.removeChild(el);
}
}
},
}