[ Overlays ]
Tooltip
A small label with an arrow that appears on hover or keyboard focus to describe an element. Four placements, three sizes, any color, an optional arrow, and an open prop to pin it. Dark bubble on light pages, light bubble on dark pages.
Import#
import { Tooltip } from 'reusify-ui';When to use#
- Labelling icon-only buttons and logo tiles.
- Short, supplementary hints ("Copied to clipboard", "Last edited 2h ago").
- Never put essential information or interactive content in a tooltip. Touch users can't hover.
Examples#
[ Basics ]
Placement#
The arrow always points at the trigger.
<Tooltip content="Top" placement="top"><Button variant="secondary">Top</Button></Tooltip>
<Tooltip content="Bottom" placement="bottom"><Button variant="secondary">Bottom</Button></Tooltip>
<Tooltip content="Left" placement="left"><Button variant="secondary">Left</Button></Tooltip>
<Tooltip content="Right" placement="right"><Button variant="secondary">Right</Button></Tooltip>Auto placement#
placement="auto" picks the side for you: top, then bottom, right and left, preferring one where the tooltip stays centered on the trigger. In a corner, where no side can center it, it slides instead. Drag the button around (or focus it and use the arrow keys), then compare with a fixed side.
<Tooltip content="I pick my own side" placement="auto">
<Button>Hover me</Button>
</Tooltip>
// Want to know where it landed?
<Tooltip content="…" placement="auto" onPlacementChange={(side) => console.log(side)}>
<Button>Hover me</Button>
</Tooltip>Stays on screen#
placement is a preference. With no room there, the tooltip flips to the other side, then slides along the edge to stay fully visible, and the arrow keeps pointing at the trigger. It also respects parents that clip their overflow, like this box. Hover the corners.
// Nothing to set up: all four ask for placement="top".
<div style={{ position: 'relative', overflow: 'hidden' }}>
<Tooltip content="A long tooltip right at the edge of the box">
<Button variant="secondary" size="sm">Corner</Button>
</Tooltip>
</div>[ Styling ]
These are pinned open with open, so you can compare them at a glance.
Sizes & arrow#
size is sm, md (default) or lg. arrow={false} removes the arrow and tucks the bubble closer.
<Tooltip content="Small" size="sm"><Button variant="raised">sm</Button></Tooltip>
<Tooltip content="Medium"><Button variant="raised">md</Button></Tooltip>
<Tooltip content="Large tooltip" size="lg"><Button variant="raised">lg</Button></Tooltip>
<Tooltip content="No arrow" arrow={false}><Button variant="raised">No arrow</Button></Tooltip>Colors#
color and textColor take any CSS color; the arrow follows automatically. To restyle every tooltip at once, set --ru-tooltip-bg and --ru-tooltip-text instead.
<Tooltip content="Saved" color="#16a34a" textColor="#fff"><Button>Save</Button></Tooltip>
<Tooltip content="Can't undo" color="#dc2626" textColor="#fff"><Button color="danger">Delete</Button></Tooltip>
<Tooltip content="Pro feature" color="#facc15" textColor="#1c1917"><Button variant="soft">Upgrade</Button></Tooltip>
/* Global */
:root { --ru-tooltip-bg: #0a0a0a; --ru-tooltip-text: #fff; }
.dark { --ru-tooltip-bg: #fafafa; --ru-tooltip-text: #0a0a0a; }Light & dark#
The bubble inverts with the theme: near-black on light pages, near-white on dark pages, so it always stands out. Both themes are pinned here with className="light" and className="dark".
<div className="light">
<Tooltip content="Reusify UI" size="lg"><Button variant="raised">Hover me</Button></Tooltip>
</div>
<div className="dark">
<Tooltip content="Reusify UI" size="lg"><Button variant="raised">Hover me</Button></Tooltip>
</div>[ In context ]
App header#
A logo tile with a large bottom tooltip, next to dashed and raised buttons.
<Tooltip content="Reusify UI" placement="bottom" size="lg">
<Button variant="raised" iconOnly size="lg" radius="xl" aria-label="Reusify UI">
<Logo />
</Button>
</Tooltip>
<Button variant="dashed" iconOnly size="lg" radius="xl" aria-label="Add workspace"><FiPlus /></Button>
<Button variant="raised" size="lg" radius="xl">Latest</Button>Pinned & delayed#
open={true} keeps a tooltip visible (onboarding tours, docs); open={false} keeps it hidden. Leave it undefined for normal hover and focus. delay sets how long to wait before showing.
<Tooltip content="Start here" open placement="right">
<Button variant="glossy">New project</Button>
</Tooltip>
<Tooltip content="Press ⌘K anywhere to search" delay={400}>
<Button variant="ghost" iconOnly aria-label="Help"><FiHelpCircle /></Button>
</Tooltip>Used in designs#
Tooltip in real layouts: these 4 designs use it. Open one to try it and copy the code.
- Transaction stepsTasks & workflow
- Total projectDashboard widgets
- Order cardsE-commerce
- Contact cardSocial & fitness
API reference#
<Tooltip />
| Prop | Type | Default | Description |
|---|---|---|---|
content* | ReactNode | - | Tooltip text or element. |
children* | ReactNode | - | The element that triggers the tooltip. |
placement | 'top' | 'bottom' | 'left' | 'right' | 'auto' | 'top' | Preferred side; flips and shifts if it does not fit. auto picks a side where it stays centered on the trigger. |
onPlacementChange | (side) => void | - | Called with the side the tooltip actually landed on. |
size | 'sm' | 'md' | 'lg' | 'md' | Padding, font size and radius. |
arrow | boolean | true | Show the arrow pointing at the trigger. |
color | CSS color | - | Bubble and arrow color for this tooltip. |
textColor | CSS color | - | Text color for this tooltip. |
open | boolean | - | true pins it open, false keeps it hidden; undefined means hover/focus. |
delay | number | 100 | Milliseconds before showing on hover/focus. |
disabled | boolean | false | Prevents the tooltip from showing. |
content*-ReactNodeTooltip text or element.
children*-ReactNodeThe element that triggers the tooltip.
placement'top''top' | 'bottom' | 'left' | 'right' | 'auto'Preferred side; flips and shifts if it does not fit. auto picks a side where it stays centered on the trigger.
onPlacementChange-(side) => voidCalled with the side the tooltip actually landed on.
size'md''sm' | 'md' | 'lg'Padding, font size and radius.
arrowtruebooleanShow the arrow pointing at the trigger.
color-CSS colorBubble and arrow color for this tooltip.
textColor-CSS colorText color for this tooltip.
open-booleantrue pins it open, false keeps it hidden; undefined means hover/focus.
delay100numberMilliseconds before showing on hover/focus.
disabledfalsebooleanPrevents the tooltip from showing.
Tooltip tokens
Set on :root and .dark (or any wrapper) to restyle every tooltip.
| Prop | Type | Default | Description |
|---|---|---|---|
--ru-tooltip-bg | color | #131316 / #f4f4f5 | Bubble and arrow background (light / dark). |
--ru-tooltip-text | color | #fafafa / #111113 | Text color (light / dark). |
--ru-tooltip-bg#131316 / #f4f4f5colorBubble and arrow background (light / dark).
--ru-tooltip-text#fafafa / #111113colorText color (light / dark).
Accessibility#
- Shows on keyboard focus as well as hover; Escape hides it.
- The trigger gets aria-describedby pointing at the tooltip (role="tooltip") while visible.
- When you set custom colors, keep at least 4.5:1 contrast between color and textColor.