tutorial()
The exported tutorial object lets you open, advance, rewind, close, and update the active tutorial from anywhere in your app.
Open a tutorial
import { useEffect } from 'react';import { TutorialOverlay, tutorial } from 'react-tutorial-overlay';function App() {useEffect(() => {async function runTutorial() {const result = await tutorial.open({steps: [{targetIds: ['target-id'],title: 'Welcome',content: 'This message is plain text.',infoBoxAlignment: 'center',},{targetIds: ['target-id'],title: 'Focused step styling',content: 'This step overrides the shared tutorial styling.',infoBoxAlignment: 'right',options: {infoBoxWidth: '28rem',infoBoxMargin: 16,highlightBorderColor: '#f97316',highlightBorderRadius: 20,labels: {done: 'Ship it',},},},],options: {highLightPadding: 12,infoBoxHeight: 220,infoBoxWidth: '24rem',infoBoxMargin: 24,overlayColor: 'rgba(15, 23, 42, 0.6)',highlightBorderColor: '#22c55e',highlightBorderRadius: 16,zIndex: 3000,labels: {prev: 'Back',next: 'Continue',skip: 'Dismiss',done: 'Finish',},keyboardNavigation: true,closeOnOverlayClick: true,},});console.log(result.reason);}runTutorial();}, []);return (<div><TutorialOverlay /></div>);}
Available methods
tutorial.open({ steps, options, startAt }): opens a tutorial and starts atstartAtwhen provided.startAtis clamped to the available step range. ReturnsPromise<{ reason: 'completed' | 'skipped' | 'closed' | 'replaced' }>when that tutorial ends.tutorial.next(): moves to the next step and closes the overlay after the last step.tutorial.prev(): moves back one step when possible.tutorial.goTo(index): moves the active tutorial to a specific step. The index is clamped to the available range, and calling it while closed is a no-op.tutorial.getState(): returns{ open, index, stepCount, currentStep }for external progress controls.tutorial.close(): closes the overlay and resolves the pendingtutorial.open()promise withreason: 'closed'.tutorial.update(index, step): replaces a step definition while the tutorial is active.
Promise result reasons
completed: the last step was completed throughtutorial.next()or the built-in완료button.skipped: the built-in건너뛰기button was clicked.closed: the tutorial was closed manually withtutorial.close(),Escape, or backdrop click.replaced: a newertutorial.open()call replaced a tutorial whose promise was still pending.
Step fields
targetIds: array of element ids to highlight for the current step.title: optional heading shown in the info box.content: optional plain text body.infoBoxAlignment: optionalcenter,left, orright.options: optional per-step overrides forinfoBoxHeight,infoBoxWidth,infoBoxMargin,highlightBorderColor,highlightBorderRadius, and partiallabels.onPrevStep: optional callback that runs when leaving the step withtutorial.prev().onNextStep: optional callback that runs when leaving the step withtutorial.next().
External progress control
await tutorial.open({steps,startAt: 1,});tutorial.goTo(0);const state = tutorial.getState();console.log(state.currentStep?.title);
tutorial.goTo() only updates the active index. It does not resolve the Promise returned by tutorial.open() and does not invoke onPrevStep or onNextStep.
Tutorial options
highLightPadding: expands the highlight frame around the target in pixels. Defaults to8.infoBoxHeight: sets the default info box height in pixels and can be overridden per step.infoBoxWidth: sets the default info box width with a CSS length such as360or'24rem'. Defaults to'20rem'and can be overridden per step.infoBoxMargin: controls the default vertical gap between the target and the info box and can be overridden per step.overlayColor: sets the backdrop color. Defaults torgba(0, 0, 0, 0.5).highlightBorderColor: sets the default highlight border color. Defaults to#ff0000and can be overridden per step.highlightBorderRadius: sets the default highlight border radius with a CSS length. Defaults to the current padding-based radius and can be overridden per step.zIndex: sets the overlay stack level. Defaults to9999.labels: overrides the built-inprev,next,skip, anddonebutton labels by default and can be partially overridden per step.keyboardNavigation: enablesEscape,ArrowLeft, andArrowRightshortcuts while the overlay is open. Defaults totrue.closeOnOverlayClick: closes the tutorial when the backdrop itself is clicked. Defaults tofalse.onClose: runs when the active tutorial is closed, including replacement by a newertutorial.open()call.
Keyboard shortcuts are ignored while an input, textarea, select, or contenteditable element has focus.
The info box automatically repositions itself to stay within the viewport when the target is close to an edge.
Step customization resolves in this order: step.options -> tutorial options -> built-in defaults. overlayColor, highLightPadding, keyboardNavigation, closeOnOverlayClick, zIndex, and onClose stay global for the whole run.
When a tutorial opens, focus moves into the labeled dialog UI and returns to the previously active element after close. The current overlay does not trap focus.
onClose remains available for side effects, while the Promise returned by tutorial.open() is the async completion hook.