Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Tooltip for Astro

Astro hints for hover and keyboard focus on a labelled control.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/tooltip

Usage

import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
<Tooltip>
  <TooltipTrigger class="rounded-md border px-3 py-2">
  Show Tooltip
  </TooltipTrigger>
  <TooltipContent>
  Add to project
  </TooltipContent>
</Tooltip>

Composition

Arrange the parts as shown for a Tooltip:

Tooltip
├── TooltipTrigger
└── TooltipContent

Examples

Tooltip Sides

Control the position of the tooltip with the side prop.

API Reference

TooltipProps

PropType
delay?number

Delay before showing tooltip (ms). Default: 300

Typenumber
skipDelayDuration?number

Duration to skip delay after closing (ms). Set to 0 to disable warm-up. Default: 300

Typenumber
side?TooltipSide

Preferred side of tooltip relative to trigger. Default: 'top'.

TypeTooltipSide
align?TooltipAlign

Preferred alignment along the side. Default: 'center'.

TypeTooltipAlign
sideOffset?number

Distance from trigger in pixels. Default: 4

Typenumber
alignOffset?number

Alignment-axis offset in pixels. Default: 0

Typenumber
mountStrategy?MountStrategy

Detach closed content by default; eager keeps it connected and hidden.

TypeMountStrategy
avoidCollisions?boolean

Enable collision handling. Default: true

Typeboolean
collisionPadding?number

Viewport edge padding used by collision handling. Default: 8

Typenumber
portal?boolean

Portal content to body while open. Default: true

Typeboolean

TooltipContentProps

PropType
side?TooltipSide

Preferred side of tooltip relative to trigger. Default: 'top'.

TypeTooltipSide
align?TooltipAlign

Preferred alignment along the side. Default: 'center'.

TypeTooltipAlign
sideOffset?number

Distance from trigger in pixels. Default: 4

Typenumber
alignOffset?number

Alignment-axis offset in pixels. Default: 0

Typenumber
avoidCollisions?boolean

Enable collision handling. Default: true

Typeboolean
collisionPadding?number

Viewport edge padding used by collision handling. Default: 8

Typenumber

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the tooltip root. The root emits the outbound events.

Outbound events

Event Detail
tooltip:change { open: boolean, trigger: HTMLElement, content: HTMLElement, reason: "pointer" | "focus" | "blur" | "escape" | "api" }

Inbound events

Event Detail
tooltip:set { open: boolean }

Read the installed source for the complete prop types.

When to use Tooltip

Use Tooltip for a short explanation that supports an already understandable control. Keep the trigger and content under one root. Essential instructions belong in visible page text.

Keyboard and behavior

The data-slot controller handles timing and visibility. Check keyboard focus as well as pointer hover. The control still needs an accessible name; a tooltip is not a substitute for an icon button label.

Theme and layout

The popup uses the shared popover surface and compact text. Test placement near viewport edges and keep the message short. Interactive content is better placed in a popover.