Web · Components
Tour
Product tour (onboarding): highlights elements on the page in order and shows an explanation card next to them.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Product tour (onboarding): highlights elements on the page in order and shows an explanation card next to them. Steps are given with the steps array; each step has a target (target), title and description.
- Highlight: The target's surroundings are dimmed; when the step changes the highlight slides to the new target. If the target isn't on screen it is scrolled into view; when the page scrolls or the element resizes, the highlight and card follow together.
- Placement: The card goes to the side where it fits (
side, default"auto") and draws an arrow pointing to the target. On mobile the card docks to the bottom of the screen. - Persistence: With
storageKeya finished tour doesn't open again, an interrupted one continues. The state is read and reset withgetTourStateandresetTour. - Flexible steps: With
onEntera menu can be opened or data awaited before the step; a target rendered later is waited for. WithadvanceOnClick"press this" steps are written. - Accessibility: The card is a
dialog; focus stays inside the card and returns to its old place when the tour ends. ← → and Esc work. The mobile back button closes the tour. - The tour opens in the top layer; no z-index needed. Renders nothing on the server; no hydration mismatch.
Examples
resolveTarget
functionLooks for the target in the DOM; returns null if not found.
TOUR_AUTO
constant"auto" order of the Tour card: below first, then above, then the sides.
placeCard
functionComputes the card position. Picks the first of the tried positions that fits on screen; if none fits, picks the one that overflows least and clamps it into the screen. Without a target the card is centered.
getTourState
functionReads the state of a tour saved with storageKey. Use it to show a "Restart tour" option in a "Help" menu or to start the tour only for new users.
Examples
resetTour
functionDeletes the saved tour; the tour starts over on the next load (or when a Tour rendered with storageKey mounts again). Changing the key is also enough to version the tour ("welcome-v2").
Examples
TourRect
interfaceA rectangle on screen (relative to the viewport).
| Name | Type | Description |
|---|---|---|
x | number | Left edge. |
y | number | Top edge. |
width | number | Width. |
height | number | Height. |
TourViewport
interfaceSize of the viewport.
| Name | Type | Description |
|---|---|---|
width | number | Width. |
height | number | Height. |
TourTarget
typeElement highlighted by the step:
- A CSS selector:
"#save","[data-tour='search']". - The element itself or a ref obtained with
useRef. - A function returning the element (called on every attempt if the element renders later).
If omitted, the step shows as a card in the center of the screen without a highlight (for welcome and closing steps).
CardPosition
interfaceComputed position of the card.
| Name | Type | Description |
|---|---|---|
x | number | Left edge of the card. |
y | number | Top edge of the card. |
side | TourSide | null | Side of the target the card sits on; null when centered. |
arrow | number | null | Distance of the arrow along the card edge. null when no arrow is drawn (when the card had to overlap the target or there is no target). |
TourStatus
typeSaved state of a tour.
"new": never shown."active": left halfway (the app closed or the user navigated away)."completed": went through to the last step."dismissed": the user skipped or closed the tour.
TourState
interfaceSaved state and, if left halfway, the step reached.
| Name | Type | Description |
|---|---|---|
status | TourStatus | Status. See TourStatus. |
step | number | Index of the step reached (starts at 0). |
TourStepContext
interfaceValues received when the step content is given as a function.
| Name | Type | Description |
|---|---|---|
index | number | Index of the shown step (starts at 0). |
total | number | Total number of steps. |
next | () => void | Moves to the next step; finishes the tour on the last step. |
back | () => void | Returns to the previous step. |
goTo | (index: number) => void | Goes to the step at the given index. |
close | () => void | Closes the tour (counts as skipped). |
TourStep
interfaceA step of Tour.
| Name | Type | Default | Description |
|---|---|---|---|
id? | string | Id of the step; for onStepChange and logs. | |
target? | TourTarget | Element to highlight: a CSS selector ("#save"), an element, a ref or a function returning the element. If omitted, the card shows in the center of the screen without a highlight (welcome and closing steps). See TourTarget. | |
title? | ReactNode | Title; screen readers announce the card by this name. | |
content? | ReactNode | ((context: TourStepContext) => ReactNode) | Description. If a function is given it receives TourStepContext; you can use your own buttons (e.g. "Try it now") in the content. | |
media? | ReactNode | Image or video shown edge to edge at the top of the card. | |
icon? | IconProp | Icon next to the title: name or element. | |
side? | Placement | the Tour's `side` value | Position of the card relative to the target. See Placement. |
padding? | number | the Tour's `padding` value | Space the highlight leaves around the element (px). |
radius? | number | the Tour's `radius` value | Corner radius of the highlight (px). |
interactive? | boolean | false` (`true` when `advanceOnClick` is given) | Whether the highlighted element is clickable. When off, the whole screen is closed to clicks. |
advanceOnClick? | boolean | false | Whether clicking the highlighted element moves to the next step. For "press this button" steps. The Next button stays visible, and the keyboard can advance too. |
nextLabel? | ReactNode | Text of the Next button in this step (e.g. "Let's start"). | |
hideBack? | boolean | false | Hides the Back button in this step. |
onEnter? | () => void | Promise<void> | Called before the step is shown: to open a menu, switch a tab or load data. If it returns a Promise, the Next button shows loading until it ends and the step is shown afterwards. | |
onLeave? | () => void | Called when leaving the step (moving to another step or closing the tour). | |
scroll? | boolean | true | Whether the target is scrolled into view if it isn't on screen. |
className? | string | Classes added to this step's card. |
Reason the tour closed.
"close": Close (×) or the "Skip" button on the first step."escape": The Esc key."overlay": Clicking the dimmed area (closeOnOverlayClick)."back": The browser's or phone's back button.
TourProgress
typeProgress indicator: "dots" dots, "count" "2 / 5", "bar" a thin bar at the top of the card, "none" none. "auto" shows dots up to 7 steps, a count beyond that.
TourLabels
interfaceButton and screen reader texts of Tour. Defaults come from the dictionary's ui texts (tourNext, tourBack…); the labels prop overrides them.
| Name | Type | Default | Description |
|---|---|---|---|
next | string | Defaults to the UIProvider text ("İleri" in Turkish). | |
back | string | Defaults to the UIProvider text ("Geri" in Turkish). | |
done | string | Button on the last step. Defaults to the UIProvider text ("Bitir" in Turkish). | |
skip | string | Button in place of Back on the first step. Defaults to the UIProvider text ("Geç" in Turkish). | |
close | string | Name of the close (×) button. Defaults to the UIProvider text ("Turu kapat" in Turkish). | |
progress | (step: number, total: number) => string | (step, total) => "2 / 5" | Progress text. |
TourClassNames
interfaceClasses that can be passed to the inner parts of Tour.
| Name | Type | Description |
|---|---|---|
spotlight? | string | Highlight (the hole with dimmed surroundings). |
media? | string | Media area of the card. |
title? | string | Title. |
content? | string | Description. |
footer? | string | Bottom row holding the buttons. |
TourProps
interfaceProps of the Tour component.
| Name | Type | Default | Description |
|---|---|---|---|
steps | readonly TourStep[] | Steps. See TourStep. | |
open? | boolean | Whether the tour is open in controlled use. | |
defaultOpen? | boolean | true` if `storageKey` is set, otherwise `false | Whether the tour starts automatically when the page opens. Defaults to true when storageKey is given: the tour starts only if it wasn't finished or skipped before. |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
step? | number | Index of the shown step in controlled use (starts at 0). | |
defaultStep? | number | 0 | Initial step in uncontrolled use. |
onStepChange? | (index: number, step: TourStep) => void | Called with the new index and step when the step changes. | |
onComplete? | () => void | Called when Finish is pressed on the last step. | |
onDismiss? | (index: number, reason: TourDismissReason) => void | Called with the step where it stopped and the reason when the tour closes before finishing. | |
storageKey? | string | Name under which the tour is remembered in the browser. If given, a finished or skipped tour doesn't open by itself again; an interrupted tour (on page reload) continues from where it stopped. Change the name to version it ("welcome-v2"). See getTourState, resetTour. | |
resume? | boolean | true | Whether a tour interrupted with storageKey continues from where it stopped. |
side? | Placement | "auto" | Default position of the card relative to the target. See Placement. |
padding? | number | 8 | Space of the highlight around the element (px). |
radius? | number | 10 | Corner radius of the highlight (px). |
mask? | boolean | true | Whether the surroundings of the target are dimmed. When off, only a colored frame shows around the target. |
progress? | TourProgress | "auto" | Progress indicator. See TourProgress. |
dismissible? | boolean | true | Can the user close the tour (×, Esc, "Skip", back button)? When off, the tour closes only by finishing it. |
closeOnOverlayClick? | boolean | false | Whether clicking the dimmed area closes the tour. |
closeOnBackButton? | boolean | true | Whether the back button closes the tour. |
keyboard? | boolean | true | Keyboard: ← → move between steps (directions flip in right-to-left writing), Esc closes. |
missingTarget? | "center" | "skip" | "center" | What to do if the target isn't found? "center" shows the card in the center and moves to the target if it renders later; "skip" skips the step. |
targetTimeout? | number | 1500 | If the target isn't on the page yet (e.g. a menu opened in onEnter), how long to wait at most (ms)? |
mobileDock? | boolean | true | Whether on small screens (below 640 px) the card docks to the bottom of the screen (to the top if the target is low). The card can be swiped left/right with a finger to change steps. |
labels? | Partial<TourLabels> | Texts. See TourLabels. | |
className? | string | Classes added to the card (e.g. w-96 for width). | |
classNames? | TourClassNames | Classes added to the inner parts. |