Remove tooltips when their elements are unbound
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
kolaente 2020-11-10 21:42:51 +01:00
parent ddf618d7ba
commit 8fe6133058
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 15 additions and 3 deletions

View File

@ -63,7 +63,7 @@
:to="{name: 'namespace.edit', params: {id: n.id} }"
class="nsettings"
v-if="n.id > 0"
v-tooltip.right="'Settings'">
v-tooltip="'Settings'">
<span class="icon">
<icon icon="cog"/>
</span>

View File

@ -16,6 +16,11 @@ const calculateArrowTop = (top, tooltip) => {
return `${top + tooltip.offsetHeight}px`
}
// This global object holds all created tooltip elements (and their arrows) using the element they were created for as
// key. This allows us to find the tooltip elements if the element the tooltip was created for is unbound so that
// we can remove the tooltip element.
const createdTooltips = {}
export default {
inserted: (el, {value, modifiers}) => {
// First, we create the tooltip and arrow elements
@ -63,9 +68,16 @@ export default {
tooltip.classList.remove('visible')
arrow.classList.remove('visible')
})
createdTooltips[el] = {
tooltip: tooltip,
arrow: arrow,
}
},
unbind: el => {
// TODO: find the tooltip we added for that element and remove it from the dom.
console.log('unbind', el)
if (typeof createdTooltips[el] !== 'undefined') {
createdTooltips[el].tooltip.remove()
createdTooltips[el].arrow.remove()
}
},
}