Tooltip
AlphaA lightweight, accessible tooltip that appears on hover or focus. Uses role='tooltip' with proper aria-describedby wiring.
Import
import { Tooltip } from "@compa11y/react";Usage
Example.tsx
import { Tooltip, Button } from "@compa11y/react";
function Example() {
return (
<div style={{ display: "flex", gap: "16px" }}>
<Tooltip label="Save your changes">
<Button>Save</Button>
</Tooltip>
<Tooltip label="Delete this item permanently" side="bottom">
<Button variant="danger">Delete</Button>
</Tooltip>
<Tooltip label="Copy to clipboard" side="right">
<Button variant="ghost">Copy</Button>
</Tooltip>
</div>
);
}Features
- role='tooltip' with aria-describedby on the trigger
- Opens on hover and keyboard focus
- Configurable open/close delay
- Placement options: top, right, bottom, left
- Escape key to dismiss
- Respects prefers-reduced-motion
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label* | string | - | Tooltip text content |
side | 'top' | 'right' | 'bottom' | 'left' | 'top' | Preferred placement |
align | 'start' | 'center' | 'end' | 'center' | Alignment along the side axis |
delayOpen | number | 300 | Delay in ms before showing |
delayClose | number | 100 | Delay in ms before hiding |
disabled | boolean | false | Prevents the tooltip from showing |
children* | ReactNode | - | Trigger element |
Keyboard Interactions
Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
| Key | Action |
|---|---|
| Tab (focus) | Shows the tooltip when the trigger receives keyboard focus |
| Escape | Dismisses the tooltip |