On this page

Tooltip

Live examples of Tooltip, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz. Hover a trigger, or Tab to it.

Name an icon button

relationship="label": the tooltip text is the button’s name, written once.

TooltipLabel.vue
<script setup lang="ts">
import { Ellipsis, ListFilter, RefreshCw } from '@lucide/vue'
import { Button } from '@/components/ui/button'
import { ButtonGroup } from '@/components/ui/button-group'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'

const tools = [
  { label: 'Sync now', icon: RefreshCw },
  { label: 'Filter', icon: ListFilter },
  { label: 'More actions', icon: Ellipsis },
]
</script>

<template>
  <TooltipProvider>
    <ButtonGroup variant="spaced" aria-label="Order tools">
      <Tooltip v-for="tool in tools" :key="tool.label" relationship="label">
        <TooltipTrigger as-child>
          <Button variant="ghost" size="icon"><component :is="tool.icon" /></Button>
        </TooltipTrigger>
        <TooltipContent>{{ tool.label }}</TooltipContent>
      </Tooltip>
    </ButtonGroup>
  </TooltipProvider>
</template>

Describe a control

The default. The button has its own name; the tooltip adds one sentence.

TooltipDescription.vue
<script setup lang="ts">
import { RotateCcw } from '@lucide/vue'
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
</script>

<template>
  <TooltipProvider>
    <Tooltip>
      <TooltipTrigger as-child>
        <Button variant="outline"><RotateCcw />Retry failed orders</Button>
      </TooltipTrigger>
      <TooltipContent>Sends the 3 orders that failed in the last sync again.</TooltipContent>
    </Tooltip>
  </TooltipProvider>
</template>

Why a button is unavailable

The button keeps aria-disabled, so it stays focusable and the reason can show on focus too.

TooltipUnavailable.vue
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
</script>

<template>
  <TooltipProvider>
    <Tooltip>
      <TooltipTrigger as-child>
        <Button aria-disabled="true">Run sync</Button>
      </TooltipTrigger>
      <TooltipContent>Connect an online store first.</TooltipContent>
    </Tooltip>
  </TooltipProvider>
</template>

Text cut to one line

A store name of unknown length in a narrow column. The link is interactive, so its tooltip opens on focus too. As the link’s text is already its name, the tooltip is set as the label so the name is not read twice.

TooltipTruncated.vue
<script setup lang="ts">
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'

// A name of unknown length, cut to one line. The tooltip shows it whole; the link keeps the full name.
const store = 'Lotus Outdoor Supply – Wholesale and Trade Accounts'
</script>

<template>
  <TooltipProvider>
    <div class="w-48">
      <Tooltip>
        <TooltipTrigger as-child>
          <a href="#store" class="block truncate text-(--bh-color-link) [font:var(--bh-font-body-default)]">{{ store }}</a>
        </TooltipTrigger>
        <TooltipContent>{{ store }}</TooltipContent>
      </Tooltip>
    </div>
  </TooltipProvider>
</template>