A thoughtfully crafted tooltip library for React—simple to use, delightful to experience.
Tooltips seem simple, but getting them right takes care. They should appear when needed, stay out of the way when not, and feel natural as users navigate your interface.
React Tip Magic handles the details so you don't have to—positioning, transitions, accessibility, keyboard support—all with a clean, declarative API.
npm install @galangel/react-tip-magicimport { TipMagicProvider } from '@galangel/react-tip-magic';
import '@galangel/react-tip-magic/styles.css';
function App() {
return (
<TipMagicProvider>
<YourApp />
</TipMagicProvider>
);
}That's it. Now add data-tip to any element:
<button data-tip="Save your changes">Save</button>The core of React Tip Magic. One tooltip instance that gracefully moves between elements, providing a smooth, cohesive experience.
<button data-tip="Click to save">Save</button>
<button data-tip="Undo last action">Undo</button>Display shortcuts alongside your tooltips using the data-tip-shortcut attribute:
<button data-tip="Copy" data-tip-shortcut="⌘C">Copy</button>
<button data-tip="Paste" data-tip-shortcut="⌘V">Paste</button>
<button data-tip="Save" data-tip-shortcut="⌘S">Save</button>{
/* Position control */
}
<button data-tip="Below the button" data-tip-placement="bottom">
Hover me
</button>;
{
/* Smooth transitions between grouped elements */
}
<nav>
<a data-tip="Home" data-tip-move data-tip-group="nav">
Home
</a>
<a data-tip="About" data-tip-move data-tip-group="nav">
About
</a>
<a data-tip="Contact" data-tip-move data-tip-group="nav">
Contact
</a>
</nav>;
{
/* Interactive tooltips that stay visible on hover */
}
<span data-tip="Click <a href='#'>here</a> to learn more" data-tip-html data-tip-interactive>
More info
</span>;Walk users through your interface with step-by-step tours. Helpful for onboarding, feature introductions, or contextual guidance.
import { useTour } from '@galangel/react-tip-magic';
function App() {
const tour = useTour({
steps: [
{ target: 'dashboard', title: 'Welcome', content: 'This is your dashboard.' },
{ target: 'create-btn', title: 'Create', content: 'Click here to get started.' },
],
// Built-in Back/Next controls are off by default—turn them on for multi-step tours
navigation: { showControls: true },
progress: { show: true },
});
return (
<div>
<nav data-tip-id="dashboard">Dashboard</nav>
<button data-tip-id="create-btn" onClick={tour.start}>
New Project
</button>
</div>
);
}useTour is headless by default: leave navigation.showControls unset and render your own controls from the returned next, prev, end and progress.
const tour = useTour({ steps });
{
tour.isActive && (
<div>
<span>
{tour.progress.current} of {tour.progress.total}
</span>
<button onClick={tour.prev} disabled={tour.currentStep?.isFirst}>
Back
</button>
<button onClick={tour.next}>{tour.currentStep?.isLast ? 'Finish' : 'Next'}</button>
</div>
);
}Each step takes at most one of them, and a step with none must have an image or video — a step with nothing to show, or with two bodies, won't compile.
// Plain text, rendered as text
{ target: 'profile', text: `Signed in as ${user.name}` }
// Any React node (or a function of the current step returning one)
{ target: 'whats-new', title: "What's new", body: <Markdown source={releaseNotes} /> }
// Raw HTML, injected as-is - escape interpolations
import { escapeHtml } from '@galangel/react-tip-magic';
{ target: 'profile', content: `Signed in as <b>${escapeHtml(user.name)}</b>` }The panel itself is rendered by React, so titles, button labels and text are escaped for you. Only content is injected as HTML: escape any interpolated value with the exported escapeHtml.
A body renders inside TipMagicProvider, not inside the component that called useTour, so it sees only the context providers above TipMagicProvider. Re-render with new steps while the tour runs — data that arrived after start() — and the panel on screen updates in place. The step on screen is found again by its id, or by its target when no other step shares it — so give steps an id (or unique targets) if steps can change while the tour runs. If it is removed, or cannot be told apart, the tour moves on to the step now at its place, or ends. A long body scrolls once it reaches --tip-magic-tour-body-max-height (60vh by default), and the panel keeps itself within the viewport.
A step without a target opens centered in the viewport, with no arrow and the focus backdrop on (focus: false turns it off). It is the same panel as any other step, so a one-step announcement is just:
const announcement = useTour({
steps: [{ title: "What's new", body: <Markdown source={releaseNotes} /> }],
navigation: { showControls: true, finishLabel: 'Got it' },
});A centered panel is at most 80% of the viewport's height (--tip-magic-tour-centered-max-height), and its image (or native video) sets its width: the media's natural width, capped at 70% of the viewport (--tip-magic-tour-centered-max-width, and an explicit tooltipOptions.maxWidth), never cropped and scaled down uniformly when it would crowd out the text. The panel is never narrower than 280px (--tip-magic-tour-min-width); a smaller image is centered at its natural size.
A step can be only its media — { video: { src, title } } — in which case the panel is named by video.title. Pass navigation.autoFocus: 'primary' to put focus on a "Got it" button so Enter dismisses the announcement.
Centered and anchored steps mix in one tour. With no target there is nothing to highlight, scroll to or watch, and onTargetMissing never fires for it.
mediaPlacement: 'left' | 'right' (tour-level, overridable per step) puts a step's image or video in a column beside its text, instead of above it ('top', the default). The text column is 280–400px, its body scrolls, and its buttons sit at the bottom; the media keeps its aspect ratio. Below a 640px viewport it falls back to 'top'.
start() returns false and changes nothing—no onStart, no onStepChange—if no step's target is in the DOM, so a tour that can't render never reports itself as shown. Supply onTargetMissing to handle it yourself (and to keep the library off console.warn):
const tour = useTour({
steps,
onTargetMissing: (step) => {
logger.warn('tour target missing', { target: step.target });
return 'skip'; // or end the tour, which is the default
},
});
if (tour.start()) {
markTourAsSeen();
}Recovery depends on the direction of travel: next() skips or ends the tour, while prev() and goTo() leave it where it is — the step on screen is still fine. goTo() never skips, so it lands on the step you asked for or returns false.
A tour panel is a dialog, so focus moves into it when a step opens. autoFocus picks which element inside it:
const tour = useTour({
steps,
// 'panel' (default) | 'primary' — Next/Finish, so Enter advances | false — leave focus alone
navigation: { showControls: true, autoFocus: 'primary' },
});'primary' falls back to the panel when a step renders no Next/Finish button — never to the close button. Overridable per step via step.navigation.autoFocus.
Tours also support progress indicators, keyboard support, and backdrop highlighting (focus: true, or focus: { dismissOnClick: true } to let a click on the backdrop end the tour)—all configurable to fit your needs.
The tour panel is now rendered by React instead of injected as an HTML string. Things you can observe:
useTipMagic().tooltip.contentisnullwhile a tour panel is showing. It used to hold the panel's HTML; it still returns string content for plain tooltips.- A custom
progress.renderis wrapped in a<div style="display: contents">inside.tip-magic-tour-footer, so a.tip-magic-tour-footer > .your-classselector no longer matches. Layout is unchanged. - A step whose only feature is a
titlenow renders the panel (arole="dialog") instead of dropping the title. - A
contentstep with no panel features is injected as HTML, as documented, withouttooltipOptions.html: true. An explicithtml: false(tour or step) still shows it as text. textis rendered once-escaped everywhere, and button labels as text rather than markup.- Unmounting the component that called
useTourtakes a running tour down without callingonEnd. CurrentTourStep.content(incurrentStep,onStepChange,onTargetMissing) is''for abodystep: React content has no HTML form.- A panel without a
titleis labelled by its message, soaria-labelledbyis now always set on a tour dialog. start()also returnsfalsewhen the first step has nothing to show (an empty body and no panel features).- A step may be only its
imageorvideo, with notext,bodyorcontent; the video's type is exported asTourVideo, andvideo.titlenow names native videos too. mediaPlacement(TourOptionsandTourStep, typeTourMediaPlacement) is new and defaults to'top', the existing layout.- An anchored panel's height cap never drops below
--tip-magic-tour-min-height(240px): with less room beside its target it flips to another side. TourStep.targetis optional: a step without one opens centered.CurrentTourStep.targetisundefinedfor such a step, so code that reads it as astringmust handle that.
Type changes, for code that uses the exported context (useTipMagicContext, TipMagicState, TipMagicAction):
TooltipState.contentand theSHOW_TOOLTIP/MOVE_TOOLTIPpayloads'contentwidened fromstringtoReactNode. Writing a string still works; code that reads one and annotates it asstringmust widen or narrow withtypeof.UPDATE_TOOLTIP_CONTENTandtooltip.updateContentstill take astring. Called while a tour runs, they replace the tour panel with that string.HIDE_TOOLTIPandEND_FLOWaccept an optionalpayload(onlyIfOwner,onlyIfSteps), andTooltipShowOptionsgainsownerandcentered; all additive.TooltipShowOptions.maxWidthandParsedTooltipData.maxWidthalso accept'none'(let the content decide), which a centered step with an image uses. Code that readsparsedData.maxWidthas anumbermust handle it.
A keyboard shortcut discovery menu. Press a key (F1 by default) to reveal all available shortcuts in your interface, with fuzzy search to quickly find what you need.
import { TipAdvisor } from '@galangel/react-tip-magic';
function App() {
return (
<TipMagicProvider>
<div className="toolbar">
<button data-tip="Copy" data-tip-shortcut="⌘C">
Copy
</button>
<button data-tip="Paste" data-tip-shortcut="⌘V">
Paste
</button>
<button data-tip="Save" data-tip-shortcut="⌘S">
Save
</button>
</div>
{/* Press F1 to open the advisor */}
<TipAdvisor />
</TipMagicProvider>
);
}Features:
- Fuzzy search with highlighted matches
- Keyboard navigation (arrow keys + Enter)
- Hover to preview tooltip locations
- Click to trigger the associated element
| Attribute | Description | Example |
|---|---|---|
data-tip |
Tooltip content | data-tip="Hello" |
data-tip-shortcut |
Keyboard shortcut badge | data-tip-shortcut="⌘S" |
data-tip-id |
Element identifier for tours | data-tip-id="welcome" |
data-tip-placement |
Position (top, bottom, left, right) | data-tip-placement="bottom" |
data-tip-delay |
Show delay in ms | data-tip-delay="500" |
data-tip-hide-delay |
Hide delay in ms | data-tip-hide-delay="100" |
data-tip-disabled |
Disable tooltip | data-tip-disabled |
data-tip-html |
Parse content as HTML | data-tip-html |
data-tip-interactive |
Keep tooltip on hover | data-tip-interactive |
data-tip-move |
Smooth move transition | data-tip-move |
data-tip-group |
Group for transitions | data-tip-group="nav" |
data-tip-no-arrow |
Hide tooltip arrow | data-tip-no-arrow |
For more control, use the useTipMagic hook:
import { useTipMagic } from '@galangel/react-tip-magic';
function MyComponent() {
const { tooltip } = useTipMagic();
const handleClick = () => {
tooltip.show('#my-element', 'Dynamic content');
};
return (
<button id="my-element" onClick={handleClick}>
Click me
</button>
);
}- React 18+ with modern hooks
- TypeScript for type safety
- Floating UI for positioning
- Storybook for documentation
Apache-2.0
Made with care for the React community
