Skip to content

Commit 840e416

Browse files
committed
feat: support -to- customization in tooltip
1 parent 91df60a commit 840e416

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

app/components/Tooltip/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const props = defineProps<{
66
position?: 'top' | 'bottom' | 'left' | 'right'
77
/** Enable interactive tooltip (pointer events + hide delay for clickable content) */
88
interactive?: boolean
9+
/** Teleport target for the tooltip content (defaults to 'body') */
10+
to?: string | HTMLElement
911
}>()
1012
1113
const isVisible = shallowRef(false)
@@ -48,6 +50,7 @@ const tooltipAttrs = computed(() => {
4850
:position
4951
:interactive
5052
:tooltip-attr="tooltipAttrs"
53+
:to="props.to"
5154
@mouseenter="show"
5255
@mouseleave="hide"
5356
@focusin="show"

app/components/Tooltip/Base.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@ import type { HTMLAttributes } from 'vue'
33
import type { Placement } from '@floating-ui/vue'
44
import { 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
1926
const triggerRef = useTemplateRef('triggerRef')
2027
const 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

Comments
 (0)