Skip to content

Commit 1427276

Browse files
anjarupnikanja-q42
andauthored
fix(Tooltip): empty ariaLabel for nested components in Content (#2294)
* fix (TooltipContent): fix empty ariaLabel for nested components * fix(tooltip): fix ariaLabel in TooltipContent --------- Co-authored-by: Anja <[email protected]>
1 parent 9cb81d5 commit 1427276

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

packages/core/src/Tooltip/TooltipContentImpl.vue

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import type { VNode } from 'vue'
32
import type { PopperContentProps } from '@/Popper'
43
import type { PrimitiveProps } from '@/Primitive'
54
import { useForwardExpose } from '@/shared'
@@ -42,7 +41,7 @@ export interface TooltipContentImplProps
4241

4342
<script setup lang="ts">
4443
import { useEventListener } from '@vueuse/core'
45-
import { Comment, computed, onMounted, useSlots } from 'vue'
44+
import { computed, onMounted } from 'vue'
4645
import { DismissableLayer } from '@/DismissableLayer'
4746
import { PopperContent } from '@/Popper'
4847
import { VisuallyHidden } from '@/VisuallyHidden'
@@ -64,24 +63,8 @@ const emits = defineEmits<TooltipContentImplEmits>()
6463
6564
const rootContext = injectTooltipRootContext()
6665
67-
const { forwardRef } = useForwardExpose()
68-
const slot = useSlots()
69-
const defaultSlot = computed(() => slot.default?.({}))
70-
const ariaLabel = computed(() => {
71-
if (props.ariaLabel)
72-
return props.ariaLabel
73-
let content = ''
74-
75-
function recursiveTextSearch(node: VNode) {
76-
if (typeof node.children === 'string' && node.type !== Comment)
77-
content += node.children
78-
else if (Array.isArray(node.children))
79-
node.children.forEach(child => recursiveTextSearch(child as VNode))
80-
}
81-
82-
defaultSlot.value?.forEach((node: VNode) => recursiveTextSearch(node))
83-
return content
84-
})
66+
const { forwardRef, currentElement } = useForwardExpose()
67+
const ariaLabel = computed(() => props.ariaLabel || currentElement.value?.textContent)
8568
8669
const popperContentProps = computed(() => {
8770
const { ariaLabel: _, ...restProps } = props

0 commit comments

Comments
 (0)