Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Tour for UI SDK

A product tour for React on UI SDK: steps that dim the page, outline one element at a time and can wait for a click, typing or data.

On this page9 sections

A tour walks people through a page one step at a time, on a first visit, a redesigned screen or a new feature. A typical step dims the page, outlines one element and explains it in a small panel with Back and Next. UI SDK has no tour component, so this one is built on its popup and focus behaviors.

For a single hint on one control, use a Tooltip or a Popover. An announcement with nothing to point at belongs in a Dialog.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Tour anatomy: spotlight, title, close, description, progress text, action trigger, content

Usage

import React from "react";
import { Button } from "@/components/ui/button";
import {
  Tour, TourContent, TourDescription, TourFooter, TourHeader,
  TourNextStep, TourPreviousStep, TourProgressText, type TourStepType,
  TourTitle, TourTrigger,
} from "@/components/ui/tour";
const TourDemo = () => {
  const installRef = React.useRef<HTMLButtonElement>(null);
  const usageRef = React.useRef<HTMLDivElement>(null);

  const steps = React.useMemo<TourStepType[]>(
    () => [
      {
        actions: [{ action: "next", label: "Start tour" }],
        description:
          "This walkthrough stays inside the preview. Next steps highlight pieces of this mini app.",
        id: "welcome",
        title: "Welcome",
        type: "dialog",
      },
      {
        actions: [
          { action: "prev", label: "Back" },
          { action: "next", label: "Next" },
        ],
        description: "Use the CLI or a manual install from this control.",
        id: "install",
        placement: "bottom",
        target: () => installRef.current,
        title: "Install",
        type: "tooltip",
      },
      {
        actions: [
          { action: "prev", label: "Back" },
          { action: "next", label: "Next" },
        ],
        description:
          "Usage notes live next to install so you can copy a snippet.",
        id: "usage",
        placement: "top",
        target: () => usageRef.current,
        title: "Usage",
        type: "tooltip",
      },
      {
        actions: [{ action: "dismiss", label: "Done" }],
        description:
          "The overlay, spotlight, and popover are clipped to this frame.",
        id: "done",
        title: "That’s it",
        type: "dialog",
      },
    ],
    []
  );

  return (
    <Tour steps={steps}>
      <div className="flex w-full max-w-lg flex-col overflow-hidden rounded-xl border bg-background shadow-sm">
        <header className="flex items-center justify-between gap-3 border-b px-3 py-2.5">
          <span className="font-semibold text-sm">Acme UI</span>
          <div className="flex items-center gap-1">
            <Button ref={installRef} size="sm" type="button" variant="ghost">
              Install
            </Button>
            <TourTrigger render={<Button size="sm" />}>Start tour</TourTrigger>
          </div>
        </header>

        <div className="grid gap-3 p-4 sm:grid-cols-2">
          <div className="rounded-lg border bg-muted/40 p-3">
            <p className="font-medium text-sm">Install</p>
            <p className="mt-1 text-muted-foreground text-xs">
              Add the component with the CLI, then import it.
            </p>
          </div>
          <div className="rounded-lg border bg-muted/40 p-3" ref={usageRef}>
            <p className="font-medium text-sm">Usage</p>
            <p className="mt-1 text-muted-foreground text-xs">
              Compose steps, then call start() from a trigger.
            </p>
          </div>
        </div>
      </div>

      <TourContent>
        <TourHeader>
          <TourProgressText />
          <TourTitle />
          <TourDescription />
        </TourHeader>
        <TourFooter>
          <TourPreviousStep />
          <TourNextStep />
        </TourFooter>
      </TourContent>
    </Tour>
  );
};

Accessibility

Each step is a dialog named by its title and described by its description. When the tour starts, focus moves to the step's first button, and when the step changes it stays on the button that moved it, or goes to the first one if that button is gone. The tour doesn't trap focus, so Tab can leave the step for the highlighted element and the rest of the page. The buttons that TourActions, TourPreviousStep and TourNextStep draw are named by the labels they show, and the close button in the corner is announced as Close. When the tour ends, focus goes back to the button that started it.

Arrow Right
Moves to the next step in the tour, while focus is in the step and not in a text field. In right-to-left text it moves to the previous step.
Arrow Left
Moves to the previous step in the tour, while focus is in the step and not in a text field. In right-to-left text it moves to the next step.
Escape
Closes the tour.
Tab
Moves focus through the step's buttons, then on to the page.
Shift+Tab
Moves focus back through the step's buttons, then on to the page.
Enter
Presses the focused button, such as Next, Back or Close.
Space
Presses the focused button, such as Next, Back or Close.

Demos

Async

The second step fetches a GitHub profile in its effect. The intro dialog stays up while the request runs, then update writes the name, public repo count and follower count into the step and show opens it on the profile card. A failed request shows an error the same way, while closing the tour mid-request aborts the fetch and leaves the tour closed.

Preview width

Custom spacing

Two dialog steps in a TourContent whose --space variable is set to --spacing(2), half its default of --spacing(4). The variable is the panel's padding, and the footer's inset follows it, so the whole panel tightens. Set it at one size, or per breakpoint for a roomier panel on wide screens.

Preview width

Events

Three boxes, a Start Tour button and an event log under them. onStepChange adds a line with the step's id each time the tour moves, and onStatusChange adds one when it starts and when it ends. Use these callbacks to remember who finished the tour or to count where people leave it.

Preview width

Keyboard navigation

keyboardNavigation is set, and a line under the button names the keys: the right arrow moves on, the left arrow goes back and Escape closes. Both are on in every tour unless you set keyboardNavigation or closeOnEscape to false on Tour. The arrows respond while focus is in the step panel.

Preview width

Progress

Four tooltip steps with a thin bar along the bottom of the panel, filled to getProgressPercent(): 25, 50, 75, then 100 percent. TourProgressText still prints 1 of 4 above the title. The bar is the demo's own element, reading the tour from useTourContext(), so copy it when a count alone feels too abstract for a longer tour.

Preview width

Skip

The first two steps offer Skip beside Next, and Skip is an action whose action is dismiss, so it closes the tour from wherever someone is. The last step says Finish and dismisses the same way, with Back beside it. Offer a skip when the walkthrough is optional, so nobody has to sit through it to reach the page.

Preview width

Step types

Two dialog steps, centered with no target, open and close the tour. Between them, a tooltip step points at the Target Element box, and a floating step set to bottom-end sits in that corner of the window without dimming the page or pointing at anything. Pick the type by what the step is about: the whole product, one control, or a passing note.

Preview width

Wait for click

Add Item, Edit and Delete each get a step with no Next button. Its effect shows the step, waits with waitForEvent for a click on the highlighted button, then calls next. Use this when the lesson is the click itself, and since the tour doesn't trap focus, keyboard users can Tab to the button and press Enter.

Preview width

Wait for element

Clicking Add Item appends a row, and the next step waits for it: its effect calls waitForElement for an element with data-item set to new and shows the step once the row exists. The previous step stays on screen in the meantime, and if no row appears within five seconds the step calls dismiss. Use this when the next target is created by the step before it.

Preview width

Wait for input

A short form where the name step moves on once the field holds two characters, and the email step once the value looks like an address. Each listens with waitForEvent for input and checks a predicate, and the terms step outlines the checkbox row until the box is checked. Use it when going on with an empty or invalid value would skip the lesson.

Preview width

FAQ

How do I build a product tour or onboarding walkthrough in React?

Describe the tour as an array of steps, each with a unique id, a title, a description, a type and the actions its buttons run, and pass it to Tour as steps. Wrap the button that starts it in a TourTrigger, and add a TourContent holding the title, description and buttons, as the Usage section does.

A step of type tooltip also needs a target. To start the tour without a click, on a first visit for example, call handleStart from useTourContext() in a component rendered inside Tour.

How do I highlight a specific element in a Tour step?

Set the step's type to tooltip and give it a target: a function that returns the element, from a ref or a querySelector call. The tour scrolls the element into view, dims the rest of the page around a cut-out, outlines it, and places the panel on the side placement names, which is bottom unless you choose another.

The element stays clickable through the cut-out, and clicking it doesn't close the tour, which is what the Wait for click demo relies on.

What step types does the Tour support?

Four. A dialog step is centered on the page with no target, which suits a welcome or a goodbye. A tooltip step points at its target and outlines it on a dimmed page.

A floating step points at nothing and leaves the page undimmed, as in the Step types demo. Its placement names the corner or edge of the window it sits in, bottom-end unless you choose another, such as top-start or bottom.

The last, wait, shows no panel at all and isn't counted in the progress. Its effect runs until it calls next, which makes it a pause between steps while the page catches up.

How do I wait for the user to click a button before the next Tour step?

Leave out the step's actions and do the waiting in its effect, which receives show, next and the step's target. Call show() to open the step, wait for a click on the target with waitForEvent from components/ui/tour, then call next(). Return the cancel function it gives you, so leaving the step removes the listener.

The Wait for click demo does this three times. waitForEvent also takes a predicate, which Wait for input uses to move on only once a field holds a valid value.

How do I load data before showing a Tour step?

Start the request in the step's effect and call show() once it settles. Until then the previous step stays on screen, so nobody stares at an empty panel. Call update() before show() to give the step a title and description built from the response, as the Async demo does with a GitHub profile.

Return a cleanup function that aborts the request, which runs if someone closes the tour or goes to another step before it settles. Once the step is left, its show() and update() do nothing, so a late failure can't reopen a tour that was just closed. For any other failure, update the step with its own message and call show(), or it never appears.

How do I let users skip or close the Tour?

Add an action whose action is dismiss to each step, labeled Skip, Done or Finish, as the Skip demo does. An action set to skip closes the tour too, and reports skipped rather than dismissed to onStatusChange.

Escape and a click outside the step and its target close the tour as well. To keep it open until someone picks one of its buttons, set closeOnEscape and closeOnInteractOutside to false on Tour.

How do I know when a Tour step changes or the Tour ends?

Pass onStepChange and onStatusChange to Tour, as the Events demo does. onStepChange reports the step's id, index and progress each time the tour moves, and starting again after an earlier run first reports a null id while the old step is cleared. onStatusChange reports started, completed, dismissed, skipped or not-found.

Save completed or dismissed to remember that someone has seen the tour, and don't start it for them again.

Why does my Tour close instead of showing the next step?

The step's target returned nothing. When a step's element isn't in the page, the tour watches for it for three seconds, then ends with the status not-found rather than pointing at empty space. Check that the ref or selector matches an element that is rendered at that moment, not one inside a closed menu or a route that hasn't loaded.

When the element appears only after something happens, wait for it in the step's effect with waitForElement and call show() once it's there, as the Wait for element demo does. Give every step its own id as well, since the tour finds steps by it.

API Reference

Tour

PropType
stepsTourStepDetails[]

The steps, read when the tour mounts. Change them later with the tour's setSteps, addStep, updateStep and removeStep.

Default
[]
onStepsChange?(details: { steps: TourStepDetails[] }) → void
Type
(details: { steps: TourStepDetails[] }) → void
Parameters

details – { steps: TourStepDetails[] }

Returns
void
closeOnEscape?boolean
closeOnInteractOutside?boolean
dir?"ltr" | "rtl"

The reading direction. Inherits the nearest DirectionProvider when unset.

Type
"ltr" | "rtl"
ids?object
Type
{ backdrop?: string; content?: string; description?: string; title?: string }
keyboardNavigation?boolean
lazyMount?boolean

Mount the step's parts only once the tour first opens.

Default
true
onFocusOutside?(event: TourOutsideEvent) → void

Called when focus moves outside it. Prevent its default to keep it open.

Parameters

event – TourOutsideEvent

Returns
void
onInteractOutside?(event: TourOutsideEvent) → void

Called on any pointer or focus interaction outside it. Prevent its default to keep it open.

Parameters

event – TourOutsideEvent

Returns
void
onPointerDownOutside?(event: TourOutsideEvent) → void

Called when a pointer goes down outside it. Prevent its default to keep it open.

Parameters

event – TourOutsideEvent

Returns
void
onStatusChange?(details: TourStatusChangeDetails) → void
Type
(details: TourStatusChangeDetails) → void
Parameters

details – { status: TourStatus; stepId: string | null; stepIndex: number }

Returns
void
onStepChange?(details: TourStepChangeDetails) → void
Type
(details: TourStepChangeDetails) → void
Parameters

details – { complete: boolean; progress: number; stepId: string | null; stepIndex: number; totalSteps: number }

Returns
void
preventInteraction?boolean
spotlightOffset?{ x: number; y: number }
spotlightRadius?number
stepId?string | null
Type
string | null
translations?object
Type
{ close?: string; nextStep?: string; prevStep?: string; progressText?: (details: { current: number; total: number }) → string; skip?: string }
unmountOnExit?boolean

Unmount the step's parts once the tour closes; otherwise they stay, hidden.

Default
true

TourTrigger

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourOverlay

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourPositioner

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourSpotlight

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourContent

<div> data-slot="scroll-area"

PropType
showCloseButton?boolean

Show close button at the top right corner.

Default
true
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-at-end?string

Present while the view is at the end: the bottom, or the inline end when only the horizontal axis overflows.

data-at-start?string

Present while the view is at the start: the top, or the inline start when only the horizontal axis overflows. Also when nothing overflows.

data-at-x-end?string

Present while the view is at the inline end, within a pixel.

data-at-x-start?string

Present while the view is at the inline start, within a pixel.

data-at-y-end?string

Present while the view is at the bottom, within a pixel.

data-at-y-start?string

Present while the view is at the top, within a pixel.

data-hovering?string

Present while a mouse or pen is over the scroll area.

data-overflow-x?string

Present while the content is wider than the viewport.

data-overflow-y?string

Present while the content is taller than the viewport.

data-scrolling?string

Present while the user scrolls, and for a moment after. Keeping the end in view doesn't count.

data-sticking?string

Present while the view follows the end as content grows, with stickToEnd.

CSS variableType
--fade-sizestring
--scroll-area-corner-heightstring

The horizontal scrollbar's height while both show, so the vertical one stops short of it. 0px otherwise.

--scroll-area-corner-widthstring

The vertical scrollbar's width while both scrollbars show, so the horizontal one stops short of it. 0px otherwise.

--scroll-area-overflow-x-endstring

How far the content reaches past the inline end, in pixels.

--scroll-area-overflow-x-startstring

How far the content reaches past the inline start, in pixels, left in LTR and right in RTL.

--scroll-area-overflow-y-endstring

How far the content reaches below the view, in pixels.

--scroll-area-overflow-y-startstring

How far the content reaches above the view, in pixels. Grow a top fade or shadow with it. Not inherited, like the other overflow and progress variables, so scrolling never restyles the content. A child of the root that reads it takes it with --scroll-area-overflow-y-start: inherit.

--scroll-area-progress-xstring

How far along the inline axis the view is, from 0 to 1.

--scroll-area-progress-ystring

How far down the view is, from 0 at the top to 1 at the bottom. A reading progress bar can scale with it.

--spacestring

TourBody

data-slot="tour-body"

PropType
scrollFade?boolean

Add a fade effect to the scroll area.

Default
false
className?string

Merged with the part's classes.

TourHeader

<div> data-slot="tour-header"

PropType
description?string

The description of the step.

title?string

The title of the step.

className?string

Merged with the part's classes.

TourTitle

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourDescription

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourProgressText

<div> data-slot="tour-progress-text"

PropType
className?string

Merged with the part's classes.

TourClose

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

TourActionTrigger

PropType
actionobject

The step's action this button runs.

Type
{ action?: | "next" | "prev" | "dismiss" | "skip" | ((actions: TourStepActionMap) → void); attrs?: Record<string, unknown>; label: string }
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--spacestring

TourFooter

<div> data-slot="tour-control"

PropType
className?string

Merged with the part's classes.

TourActions

<div> data-slot="tour-actions"

PropType
className?string

Merged with the part's classes.

TourPreviousStep

data-slot="tour-previous-step"

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)

TourNextStep

data-slot="tour-next-step"

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)