A React library for step-by-step product tutorials with an imperative overlay API.
(This is an open source library that is still under development.)
- ✨ step-by-step tutorial overlay
- 🎯 highlight one or more DOM targets per step
- 🕹 imperative controls via
tutorial.open(),next(),prev(), andclose() - ⏳ await tutorial completion with a small Promise result payload
- 📦 minimal setup with a single
<TutorialOverlay />mount
install with npm
npm install react-tutorial-overlayinstall with yarn
yarn add react-tutorial-overlayimport { TutorialOverlay, tutorial } from 'react-tutorial-overlay';
const App = () => {
const handleClick = async () => {
const result = await tutorial.open({
steps: [
{
targetIds: ['target1'],
title: 'Welcome',
content: 'Click next to move through the tutorial.',
},
{
targetIds: ['target2'],
title: 'Second step',
content: 'Each step can highlight one or more element ids.',
infoBoxAlignment: 'right',
},
],
options: {
highLightPadding: 12,
infoBoxHeight: 220,
infoBoxMargin: 24,
keyboardNavigation: true,
closeOnOverlayClick: true,
onClose: () => {
console.log('tutorial closed');
},
},
});
if (result.reason === 'completed') {
console.log('continue onboarding flow');
}
};
return (
<div>
<button onClick={handleClick}>open</button>
<div id="target1">target</div>
<div id="target2">another target</div>
<TutorialOverlay />
</div>
);
};tutorial.open() returns Promise<{ reason: 'completed' | 'skipped' | 'closed' }>:
completed: the user finished the last step.skipped: the user clicked the built-in건너뛰기button.closed: the tutorial was closed externally, such astutorial.close(),Escape, backdrop click, or opening a new tutorial while another promise is still pending.
content is rendered as a plain string. HTML markup in the string is not interpreted.
highLightPadding expands the highlight frame around the target element. It defaults to 8 pixels and applies to the rendered highlight box as well as the info box anchor position.
Keyboard navigation is enabled by default while the overlay is open:
Escapecloses the tutorial.ArrowRightmoves to the next step and completes the tutorial on the last step.ArrowLeftmoves to the previous step and is a no-op on the first step.
Set options.keyboardNavigation to false to disable those shortcuts. Shortcuts are ignored while an input, textarea, select, or contenteditable element has focus.
Set options.closeOnOverlayClick to true to close the tutorial when the dimmed backdrop itself is clicked. Clicks on the highlight frame and info box do not trigger close.
The info box automatically flips and clamps itself to stay inside the viewport when the target sits close to an edge.
For accessibility, the info box is exposed as a labeled dialog. When the tutorial opens, focus moves into the info box controls, and when it closes, focus returns to the element that was active before open. The library does not currently trap focus inside the overlay.
options.onClose still runs whenever the tutorial closes. Use the returned Promise when you need async flow control after the tutorial ends.
Mount <TutorialOverlay /> once near the root of your app, then trigger tutorial.open({ steps, options }) from any event handler or effect.