@@ -3,18 +3,25 @@ import type { HTMLAttributes } from 'vue'
33import type { Placement } from ' @floating-ui/vue'
44import { autoUpdate , flip , offset , shift , useFloating } from ' @floating-ui/vue'
55
6- const props = defineProps <{
7- /** Tooltip text (optional when using content slot) */
8- text? : string
9- /** Position: 'top' | 'bottom' | 'left' | 'right' */
10- position? : ' top' | ' bottom' | ' left' | ' right'
11- /** is tooltip visible */
12- isVisible: boolean
13- /** Allow pointer events on tooltip (for interactive content like links) */
14- interactive? : boolean
15- /** attributes for tooltip element */
16- tooltipAttr? : HTMLAttributes
17- }>()
6+ const props = withDefaults (
7+ defineProps <{
8+ /** Tooltip text (optional when using content slot) */
9+ text? : string
10+ /** Position: 'top' | 'bottom' | 'left' | 'right' */
11+ position? : ' top' | ' bottom' | ' left' | ' right'
12+ /** is tooltip visible */
13+ isVisible: boolean
14+ /** Allow pointer events on tooltip (for interactive content like links) */
15+ interactive? : boolean
16+ /** attributes for tooltip element */
17+ tooltipAttr? : HTMLAttributes
18+ /** Teleport target for the tooltip content (defaults to 'body') */
19+ to? : string | HTMLElement
20+ }>(),
21+ {
22+ to: ' body' ,
23+ },
24+ )
1825
1926const triggerRef = useTemplateRef (' triggerRef' )
2027const tooltipRef = useTemplateRef (' tooltipRef' )
@@ -32,7 +39,7 @@ const { floatingStyles } = useFloating(triggerRef, tooltipRef, {
3239 <div ref =" triggerRef" class =" inline-flex" >
3340 <slot />
3441
35- <Teleport to =" body " >
42+ <Teleport : to =" props.to " >
3643 <Transition
3744 enter-active-class =" transition-opacity duration-150 motion-reduce:transition-none"
3845 leave-active-class =" transition-opacity duration-100 motion-reduce:transition-none"
0 commit comments