Phi
Tooltip
@dicehub/phiv1.0.0-beta.1

Tooltip

A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.

<script setup lang="ts">
import { PhPlus } from "@phosphor-icons/vue";
import { Button } from "@dicehub/phi/components/button";
import { Tooltip, TooltipProvider } from "@dicehub/phi/components/tooltip";
</script>

<template>
  <TooltipProvider>
    <Tooltip as-child content="Add new item">
      <Button shape="square" :icon="PhPlus" aria-label="Add new item" />
    </Tooltip>
  </TooltipProvider>
</template>

Installation

Barrel

import { Tooltip, TooltipProvider } from "@dicehub/phi";

Granular

import { Tooltip, TooltipProvider } from "@dicehub/phi/components/tooltip";

Usage

<script setup lang="ts">
import { Button } from "@dicehub/phi/components/button";
import { Tooltip } from "@dicehub/phi/components/tooltip";
</script>

<template>
  <Tooltip as-child content="Tooltip text">
    <Button>Hover me</Button>
  </Tooltip>
</template>

For delay grouping across multiple tooltips, see TooltipProvider.

Examples

Basic Tooltip

A concise tooltip for labeling an icon-only control.

<script setup lang="ts">
import { PhPlus } from "@phosphor-icons/vue";
import { Button } from "@dicehub/phi/components/button";
import { Tooltip, TooltipProvider } from "@dicehub/phi/components/tooltip";
</script>

<template>
  <TooltipProvider>
    <Tooltip as-child content="Add">
      <Button shape="square" :icon="PhPlus" aria-label="Add" />
    </Tooltip>
  </TooltipProvider>
</template>

Multiple Tooltips

Wrap nearby tooltips in TooltipProvider to group open delay behavior.

<script setup lang="ts">
import { PhPlus, PhTranslate } from "@phosphor-icons/vue";
import { Button } from "@dicehub/phi/components/button";
import { Tooltip, TooltipProvider } from "@dicehub/phi/components/tooltip";
</script>

<template>
  <TooltipProvider>
    <div class="flex gap-2">
      <Tooltip as-child content="Add">
        <Button shape="square" :icon="PhPlus" aria-label="Add" />
      </Tooltip>
      <Tooltip as-child content="Change language">
        <Button shape="square" :icon="PhTranslate" aria-label="Change language" />
      </Tooltip>
    </div>
  </TooltipProvider>
</template>

Long Content / Overflow

Long tooltip content wraps within the available viewport width.

<script setup lang="ts">
import { Button } from "@dicehub/phi/components/button";
import { Tooltip, TooltipProvider } from "@dicehub/phi/components/tooltip";

const longContent = "Long tooltip text that wraps within the available viewport width.";
</script>

<template>
  <TooltipProvider>
    <div class="flex w-full justify-between gap-3">
      <Tooltip as-child :content="longContent" side="bottom">
        <Button variant="secondary">Near left edge</Button>
      </Tooltip>
      <Tooltip as-child :content="longContent" side="bottom">
        <Button variant="secondary">Centered</Button>
      </Tooltip>
      <Tooltip as-child :content="longContent" side="bottom">
        <Button variant="secondary">Near right edge</Button>
      </Tooltip>
    </div>
  </TooltipProvider>
</template>

Delay Control

Use delay and closeDelay to tune hover and focus timing.

<script setup lang="ts">
import { Button } from "@dicehub/phi/components/button";
import { Tooltip, TooltipProvider } from "@dicehub/phi/components/tooltip";
</script>

<template>
  <TooltipProvider>
    <div class="flex flex-wrap gap-4">
      <Tooltip as-child content="Opens after 1 second" :delay="1000">
        <Button variant="secondary">1s open delay</Button>
      </Tooltip>
      <Tooltip as-child content="Stays open 500ms after leaving" :close-delay="500">
        <Button variant="secondary">500ms close delay</Button>
      </Tooltip>
    </div>
  </TooltipProvider>
</template>

Custom Trigger

Without asChild, Tooltip renders an internal trigger button and applies className to it. The trigger inherits line height so nested Text retains its normal height.

<script setup lang="ts">
import { PhInfo } from "@phosphor-icons/vue";
import { Text } from "@dicehub/phi/components/text";
import { Tooltip } from "@dicehub/phi/components/tooltip";
</script>

<template>
  <Tooltip content="Click to learn more" class-name="help-trigger">
    <PhInfo aria-hidden="true" />
    <span>Help</span>
  </Tooltip>
  <div style="line-height: 1.75rem">
    <Tooltip content="Project environments and deployment settings">
      <Text truncate style="max-width: 8rem">Project environments and deployment settings</Text>
    </Tooltip>
  </div>
</template>

API Reference

Tooltip

The root convenience component. It renders the trigger and tooltip content.

Prop / EventTypeDefaultDescription
contentstring | number | null-Text shown inside the tooltip. Use the content slot for custom content.
asChildbooleanfalseRender the slotted element as the trigger. In templates, use as-child.
side"top" | "bottom" | "left" | "right""top"Preferred side of the trigger.
align"start" | "center" | "end""center"Alignment along the trigger.
delaynumber600How long to wait before opening, in milliseconds.
closeDelaynumber0How long to wait before closing, in milliseconds.
containerstring | HTMLElement"body"Teleport target for the portalled content.
classNamestring-Additional classes for the trigger.
contentClassNamestring-Additional classes for the tooltip popup.
v-model:openboolean-Vue controlled open state.
@open-change(details: TooltipOpenChangeDetails) => void-Emitted whenever the tooltip opens or closes.
positioningTooltipRootProps['positioning']-Advanced Ark positioning options.

TooltipProvider

Groups nearby tooltips so switching between them can skip the open delay.

Prop / EventTypeDefaultDescription
delaynumber600Default open delay for tooltips inside the provider.
closeDelaynumber0Default close delay for tooltips inside the provider.
timeoutnumber400Grace period during which a just-closed tooltip causes the next tooltip to open instantly.