Skip to content

Commit 8e99784

Browse files
committed
fix(tooltip): fix tooltip not properly targeting on HTML element
closes #140
1 parent 28657f6 commit 8e99784

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

packages/anu-vue/src/components/menu/AMenu.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { menuProps } from './props'
33
import { ACard } from '@/components'
44
import { AFloating } from '@/components/floating'
5+
import { useParent } from '@/composables'
56
67
const props = defineProps(menuProps)
78
@@ -18,7 +19,7 @@ defineOptions({
1819
name: 'AMenu',
1920
})
2021
21-
const parentEl = useParentElement()
22+
const parentEl = useParent()
2223
</script>
2324

2425
<template>

packages/anu-vue/src/components/tooltip/ATooltip.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Middleware } from '@floating-ui/vue'
55
import { flip, offset, shift } from '@floating-ui/vue'
66
import { tooltipProps } from './props'
77
import { AFloating } from '@/components/floating'
8+
import { useParent } from '@/composables'
89
910
const props = defineProps(tooltipProps)
1011
@@ -20,7 +21,10 @@ defineOptions({
2021
name: 'ATooltip',
2122
})
2223
23-
const parentEl = useParentElement()
24+
const parentEl = useParent()
25+
onMounted(() => {
26+
console.log('parentEl :>> ', parentEl.value)
27+
})
2428
2529
// const arrowEl = ref()
2630

packages/anu-vue/src/composables/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './useDOMScrollLock'
66
export * from './useGroupModel'
77
export * from './useIndeterminateCheckbox'
88
export * from './useLayer'
9+
export * from './useParent'
910
export * from './useSearch'
1011
export * from './useSort'
1112
export * from './useTeleport'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Ref } from 'vue'
2+
3+
export function useParent(): Readonly<Ref<HTMLElement | SVGElement | null | undefined>> {
4+
const parentElement = shallowRef<HTMLElement | SVGElement | null | undefined>()
5+
6+
const update = () => {
7+
const vm = getCurrentInstance()
8+
9+
const parentEl = vm!.parent!.vnode.el
10+
const proxyParentEl = vm!.proxy!.$el.parentElement
11+
12+
// @ts-expect-error - `vm!.vnode.ctx` give type error
13+
parentElement.value = vm!.vnode.ctx === vm!.vnode.el!.parentElement.__vnode.ctx ? proxyParentEl : parentEl
14+
}
15+
16+
tryOnMounted(update)
17+
18+
return parentElement
19+
}

0 commit comments

Comments
 (0)