Skip to content

Commit 1c92c17

Browse files
authored
Merge pull request #392 from devforth/AdminForth/911
fix: teleport tooltip to body
2 parents 3a74ad5 + 94af857 commit 1c92c17

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
<template>
2-
<div ref="triggerEl" class="afcl-tooltip inline-flex items-center">
2+
<div ref="triggerEl" class="afcl-tooltip inline-flex items-center" @mouseenter="mouseOn" @mouseleave="mouseOff">
33
<slot></slot>
44
</div>
5-
<div
6-
role="tooltip"
7-
class="absolute z-20 invisible inline-block px-3 py-2 text-sm font-medium text-lightTooltipText dark:darkTooltipText transition-opacity duration-300 bg-lightTooltipBackground rounded-lg shadow-sm opacity-0 tooltip dark:bg-darkTooltipBackground"
8-
ref="tooltip"
9-
>
10-
<slot name="tooltip"></slot>
11-
<div class="tooltip-arrow" data-popper-arrow></div>
12-
</div>
5+
<teleport to="body" v-if="showTooltip">
6+
<div
7+
role="tooltip"
8+
class="absolute z-20 invisible inline-block px-3 py-2 text-sm font-medium text-lightTooltipText dark:darkTooltipText transition-opacity duration-300 bg-lightTooltipBackground rounded-lg shadow-sm opacity-0 tooltip dark:bg-darkTooltipBackground"
9+
ref="tooltip"
10+
>
11+
<slot name="tooltip"></slot>
12+
<div class="tooltip-arrow" data-popper-arrow></div>
13+
</div>
14+
</teleport>
1315
</template>
1416

1517
<script setup lang="ts">
16-
import { ref, onMounted, nextTick, onUnmounted, type Ref } from 'vue';
18+
import { ref, nextTick, type Ref } from 'vue';
1719
import { Tooltip } from 'flowbite';
1820
1921
const triggerEl = ref(null);
2022
const tooltip = ref(null);
21-
23+
const showTooltip = ref(false);
2224
const tp: Ref<Tooltip|null> = ref(null);
2325
24-
onMounted(async () => {
25-
//await one tick when all is mounted
26+
async function mouseOn() {
27+
showTooltip.value = true;
2628
await nextTick();
29+
30+
tp.value?.destroy();
31+
2732
tp.value = new Tooltip(
2833
tooltip.value,
2934
triggerEl.value,
@@ -32,11 +37,15 @@ onMounted(async () => {
3237
triggerType: 'hover',
3338
},
3439
);
35-
})
3640
41+
tp.value.show();
42+
}
3743
38-
onUnmounted(() => {
39-
//destroy tooltip
44+
function mouseOff() {
45+
tp.value?.hide();
4046
tp.value?.destroy();
41-
})
47+
tp.value = null;
48+
showTooltip.value = false;
49+
}
50+
4251
</script>

0 commit comments

Comments
 (0)