Tooltip
Supplementary text on hover or focus — delayed, collision-aware, never interactive.
"use client";
import { Tooltip, Button, Icon } from "astralis-ui";
import { Wand2 } from "lucide-react";
export function TooltipDemo() {
return (
<Tooltip>
<Tooltip.Trigger>
<Button variant="outline" colorScheme="gray" leftIcon={<Icon as={Wand2} size="xs" />} aria-label="Auto-format" />
</Tooltip.Trigger>
<Tooltip.Content withArrow>Auto-format the document</Tooltip.Content>
</Tooltip>
);
}Import#
import { Tooltip } from "astralis-ui";
// Tooltip.Trigger, Tooltip.ContentUsage#
Wrap any focusable element in Tooltip.Trigger. The tooltip shows after a
delay on hover and on keyboard focus, and flips automatically when it
would leave the viewport. Tooltips are for supplementary hints only — the
icon-button above still needs its aria-label; if the content must be
clickable, use a Popover.
Sides#
"use client";
import { Tooltip, Button, HStack } from "astralis-ui";
const sides = ["top", "right", "bottom", "left"] as const;
export function TooltipSides() {
return (
<HStack gap="3" wrap="wrap" justifyContent="center">
{sides.map((side) => (
<Tooltip key={side} side={side} delay={100}>
<Tooltip.Trigger>
<Button variant="subtle" size="sm">{side}</Button>
</Tooltip.Trigger>
<Tooltip.Content withArrow>Anchored {side}</Tooltip.Content>
</Tooltip>
))}
</HStack>
);
}Props#
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "right" | "bottom" | "left" | "top" | Preferred placement; flips on collision. |
align | "start" | "center" | "end" | "center" | Alignment along the side. |
sideOffset | number | 6 | Gap from the trigger, in pixels. |
delay | number | 300 | Hover delay before showing (ms). |
avoidCollisions | boolean | true | Flip/shift to stay in the viewport. |
open / defaultOpen / onOpenChange | — | — / false / — | Controlled API. |
Tooltip.Content additionally takes withArrow (default false).
Keyboard#
| Key | Action |
|---|---|
| Focus the trigger | Show (no hover delay) |
Blur / Esc | Hide |
Accessibility#
- Renders
role="tooltip"and wiresaria-describedbyonto the trigger while open. - Shows on focus for keyboard users; Escape dismisses.
- Pointer-events are disabled — it can never trap the cursor.