Tooltip
npx shadcn add @klarhimmel/tooltip @klarhimmel/buttonCopy for AIExamples
Basic
Open
Shortcut
DetailsAbout, usage, props and more
A short label for a control, shown on hover and keyboard focus. Built on Radix Tooltip.
When to use
Use for
Naming an icon, or showing the shortcut for a control.
Not for
Text people need to finish a task. Touch screens never show it.
Pairs with
Icon button (built in), Kbd.
Preview
Hover or tab to a control. Escape hides the tip.
Import
Import
- Files
- tooltip.tsx, button.tsx, in components/klarhimmel/ui/. With it: editing, kbd, theme, utils. npm: radix-ui.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- Limit
- Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
Tooltip.content | ReactNode | required | Required. Keep it to a few words. |
Tooltip.shortcut | string | - | A keyboard shortcut shown after the text. |
Tooltip.side | 'top' | 'right' | 'bottom' | 'left' | 'top' | Where it opens; it flips to stay on screen. |
Tooltip.delay | number | - | Milliseconds before it opens on hover. Focus opens it at once. |
Tooltip.defaultOpen | boolean | - | Start open (docs and screenshots). It closes on Escape or when the pointer or focus has been and gone. |
Tooltip.children | ReactNode | required | The single element that gets the tooltip. It must be focusable. |
TooltipProvider.children | ReactNode | required | Required. One focusable element. |
TooltipProvider.delay | number | 500 | Milliseconds before it opens on hover. Focus opens it at once. |
Accessibility
| Key | Does |
|---|---|
Tab | Focusing the control shows the tooltip |
Escape | Hides the tooltip |
Hover | Shows after a short delay |