Used with a component · Tooltip
useTooltip
The headless tooltip behind <Tooltip>: open and close delays, a warm group in which the next tooltip opens at once and glides from the last one, hover onto the tooltip, Escape, and touch long-press. It positions through useFloatingPosition and listens on the trigger for you. It doesn't render or set aria-describedby. <Tooltip> adds the panel, the teleport, the ARIA wiring and the glide styles. Use it to attach the same behavior to markup of your own.
Install
import { useTooltip } from 'vael-ui'Examples
<script setup lang="ts">
import { shallowRef, useId, useTemplateRef } from 'vue'
import { useTooltip } from 'vael-ui'
const open = shallowRef(false)
const tipId = useId()
const triggerEl = useTemplateRef<HTMLElement>('trigger')
const positionerEl = useTemplateRef<HTMLElement>('positioner')
const { positionerStyle, transformOrigin } = useTooltip(open, {
triggerEl,
positionerEl,
side: 'bottom',
})
</script>
<template>
<button ref="trigger" :aria-describedby="open ? tipId : undefined">Copy</button>
<Teleport to="body">
<div v-if="open" :id="tipId" ref="positioner" role="tooltip" :style="positionerStyle">
<div class="tip" :style="{ transformOrigin }">Copy to clipboard</div>
</div>
</Teleport>
</template>