Skip to content

Commit 03a7c83

Browse files
committed
fix(core): floating tooltip hide
1 parent 6f0f1f2 commit 03a7c83

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

packages/core/src/client/webcomponents/components/FloatingTooltip.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { FloatingTooltip } from '../state/floating-tooltip'
2-
import { computed, defineComponent, h, ref, watchEffect } from 'vue'
2+
import { useDebounceFn } from '@vueuse/core'
3+
import { computed, defineComponent, h, ref, watch } from 'vue'
34
import { useFloatingTooltip } from '../state/floating-tooltip'
45

56
// @unocss-include
@@ -11,16 +12,12 @@ const FloatingTooltipComponent = defineComponent({
1112
name: 'FloatingTooltip',
1213
setup() {
1314
const current = useFloatingTooltip()
14-
const box = ref<FloatingTooltip>({
15-
render: '',
16-
width: 0,
17-
height: 0,
18-
left: 0,
19-
top: 0,
20-
})
15+
const box = ref<FloatingTooltip | null>(null)
2116

2217
// guess alignment of the tooltip based on viewport position
2318
const align = computed<'bottom' | 'left' | 'right' | 'top'>(() => {
19+
if (!box.value)
20+
return 'bottom'
2421
const vw = window.innerWidth
2522
const vh = window.innerHeight
2623
if (box.value.left < DETECT_MARGIN)
@@ -35,6 +32,8 @@ const FloatingTooltipComponent = defineComponent({
3532
})
3633

3734
const style = computed(() => {
35+
if (!box.value)
36+
return {}
3837
switch (align.value) {
3938
case 'bottom': {
4039
return {
@@ -70,14 +69,25 @@ const FloatingTooltipComponent = defineComponent({
7069
}
7170
})
7271

73-
watchEffect(() => {
74-
if (current.value) {
75-
box.value = { ...current.value }
76-
}
77-
})
72+
const clearThrottled = useDebounceFn(() => {
73+
if (current.value == null)
74+
box.value = null
75+
}, 800)
76+
77+
watch(
78+
current,
79+
(value) => {
80+
if (value) {
81+
box.value = { ...value }
82+
}
83+
else {
84+
clearThrottled()
85+
}
86+
},
87+
)
7888

7989
return () => {
80-
if (!box.value.render)
90+
if (!box.value?.render)
8191
return null
8292

8393
const content = typeof box.value.render === 'string' ? h('span', box.value.render) : box.value.render()

packages/core/src/client/webcomponents/utils/iconify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function getIconifySvg(collection: string, icon: string) {
1818
return promise
1919

2020
async function _get() {
21-
const url = `https://api.iconify.design/${collection}/${icon}.svg?color=currentColor&width=full`
21+
const url = `https://api.iconify.design/${collection}/${icon}.svg?color=currentColor&width=100%`
2222
const svg = await fetch(url).then(res => res.text())
2323
return purify.sanitize(svg)
2424
}

0 commit comments

Comments
 (0)