Skip to content

Tooltip Component

A tooltip is a contextual text bubble that displays a description for an element that appears on pointer hover or keyboard focus.

A tooltip activator can be provided in the default slot:

vue
<Tooltip text="Tooltip text" v-slot="{ attrs }">
  <button v-bind="attrs">Activator</button>
</Tooltip>

Or by setting a tooltip id and using it in the aria-describedby attribute on the activator:

vue
<Tooltip id="tooltip-example" text="Tooltip text" />
<button aria-describedby="tooltip-example">Activator</button>

Based on:

Demo

Code
vue
<template>
  <div class="d-demo">
    <Tooltip text="Tooltip text" v-slot="{ attrs }" class="d-tooltip">
      <button v-bind="attrs" class="d-btn">Basic</button>
    </Tooltip>

    <Tooltip
      text="Tooltip text"
      delay="1000"
      v-slot="{ attrs }"
      class="d-tooltip"
    >
      <button v-bind="attrs" class="d-btn">Delayed</button>
    </Tooltip>

    <Tooltip id="tooltip-demo" class="d-tooltip">
      <template #content>Any HTML content &#x1F61C;</template>
    </Tooltip>
    <button aria-describedby="tooltip-demo" class="d-btn">
      Custom content
    </button>
  </div>
</template>

<script setup lang="ts">
import { Tooltip } from "../../../src/main";
</script>

Tooltip

Properties

PropertyRequiredDescriptionTypeDefault
textfalseTooltip text.stringundefined
delayfalseThe delay before showing the tooltip in milliseconds.number | stringundefined
directionfalseThe direction of the tooltip.'up' | 'down' | 'left' | 'right''up'
idfalseThe ID of the tooltip.stringauto-generated

Slots

default

The default slot can be used to provide an activator. The slot provides the attrs attribute that must be binded to the activating element.

vue
<Tooltip text="Tooltip text" v-slot="{ attrs }">
  <button v-bind="attrs">Activator</button>
</Tooltip>

content

The content slot can be used to provide any custom html content for the tooltip.

vue
<Tooltip>
  <template #content>
    Any custom html content 
    <img src="..." />
  </template>
</Tooltip>

Keyboard interactions

  • Escape - Hides the tooltip without preventing the default action.

ARIA roles and attributes

Tooltips have the tooltip role.