Tooltip
A tooltip shows a short, non-interactive description when its trigger is hovered or focused. It is an enhancement, not a control: the description duplicates information the trigger should already convey, so nothing here is required to operate the interface.
Zag.js wires aria-describedby from the trigger to the content, so screen readers announce the description without any extra work. The bubble is positioned with fixed coordinates, so opening one never shifts layout.
The component is composed from parts. <Tooltip> owns the state machine; the remaining parts read it from context, so they must all be rendered inside <Tooltip>.
Interactive Preview
Section titled “Interactive Preview”import { Tooltip, TooltipTrigger, TooltipPositioner, TooltipContent,} from "@/components/ui/tooltip";
export function CopyButton() { return ( <Tooltip openDelay={300}> <TooltipTrigger>Copy to clipboard</TooltipTrigger> <TooltipPositioner> <TooltipContent>Copies the component source to your clipboard.</TooltipContent> </TooltipPositioner> </Tooltip> );}<script lang="ts"> import Tooltip from "@/components/ui/tooltip.svelte"; import TooltipTrigger from "@/components/ui/tooltip-trigger.svelte"; import TooltipPositioner from "@/components/ui/tooltip-positioner.svelte"; import TooltipContent from "@/components/ui/tooltip-content.svelte";</script>
<Tooltip openDelay={300}> <TooltipTrigger>Copy to clipboard</TooltipTrigger> <TooltipPositioner> <TooltipContent>Copies the component source to your clipboard.</TooltipContent> </TooltipPositioner></Tooltip>import { Tooltip, TooltipTrigger, TooltipPositioner, TooltipContent,} from "@/components/ui/tooltip";
export function CopyButton() { return ( <Tooltip openDelay={300}> <TooltipTrigger>Copy to clipboard</TooltipTrigger> <TooltipPositioner> <TooltipContent>Copies the component source to your clipboard.</TooltipContent> </TooltipPositioner> </Tooltip> );}Installation
Section titled “Installation”npx @glaceon/cli add tooltip --framework react # or svelte, solidData Attributes
Section titled “Data Attributes”| Attribute | Values | Applied to |
|---|---|---|
data-scope |
tooltip |
every part |
data-part |
trigger, positioner, content |
matching part |
data-state |
open, closed |
trigger, content |
Two behaviours are essential when styling this component:
- The content receives the
hiddenattribute while closed. Do not add an unconditional Tailwind display utility to it: a utility and the[hidden]rule have equal specificity, and the utility wins, which leaves a closed tooltip visible. - The positioner is never hidden. Zag hides the content inside it, so the positioner must stay rendered and must not carry a
hiddenclass.
API Reference (Props)
Section titled “API Reference (Props)”| Part | Prop | Type | Default | Description |
|---|---|---|---|---|
Tooltip |
children |
content | None | The trigger and the bubble |
Tooltip |
openDelay |
number |
300 |
Milliseconds before opening |
Tooltip |
closeDelay |
number |
None | Milliseconds before closing |
Tooltip |
defaultOpen |
boolean |
false |
Open on first render |
Tooltip |
disabled |
boolean |
false |
Never open |
Tooltip |
onOpenChange |
(details: { open: boolean }) => void |
None | Called whenever the open state changes |
TooltipTrigger |
children |
content | None | Usually a short label or an icon |
TooltipPositioner |
children |
content | None | Wraps the content; handles anchoring and portal |
TooltipContent |
children |
content | None | The bubble text |
Every part also accepts className (React) or class (Svelte, Solid), merged over the base classes with cn().
Keyboard Interactions
Section titled “Keyboard Interactions”| Key | Behaviour |
|---|---|
Tab |
Focusing the trigger opens the tooltip |
Escape |
Dismisses the tooltip while the trigger stays focused |
Accessibility
Section titled “Accessibility”aria-describedby is wired from the trigger to the content by the Zag.js machine, and the content carries role="tooltip". Position updates use the popover positioning engine, so the trigger never moves and there is no layout shift.
The bubble uses the inverted token pair (bg-ink on text-surface): dark on light in light mode, light on dark in dark mode, so it always contrasts with the page without a dedicated tooltip token. The trigger meets the 44px minimum target size (WCAG 2.2 SC 2.5.8) and uses the --action focus ring at 2px.
Because a tooltip is an enhancement, never place interactive content inside one: it is dismissed on pointer leave and would be unreachable by keyboard.