Examples
Targeted steps
Open the tour to highlight the target and move through a short guide.
Targeted product tour
"use client";
import { useState } from "react";
import { Button } from "@phuctech/ui/components/button";
import { Tour } from "@phuctech/ui/components/tour";
const steps = [{ id: "create", title: "Create a project", description: "Start by adding a project name and owner.", target: "#tour-create-project" }, { id: "review", title: "Review activity", description: "The activity list shows recent changes." }];
export function Example() {
const [open, setOpen] = useState(false);
return <div className="grid gap-4"><Button id="tour-create-project" variant="outline" onClick={() => setOpen(true)}>Create project</Button><Tour steps={steps} open={open} onOpenChange={setOpen} /></div>;
}
Target not found
A missing selector shows a recovery message and keeps the next step available.
Tour with missing target fallback
"use client";
import { useState } from "react";
import { Button } from "@phuctech/ui/components/button";
import { Tour } from "@phuctech/ui/components/tour";
const steps = [{ id: "missing", title: "Invite a teammate", description: "This example target is intentionally absent.", target: "#missing-tour-target" }];
export function Example() {
const [open, setOpen] = useState(false);
return <div className="grid gap-4"><Button variant="outline" onClick={() => setOpen(true)}>Start guide</Button><Tour steps={steps} open={open} onOpenChange={setOpen} /></div>;
}
Try the tour
Inspect skip, previous, next, and completion actions.
Tour property playground
"use client";
import { useState } from "react";
import { Button } from "@phuctech/ui/components/button";
import { Tour } from "@phuctech/ui/components/tour";
const steps = [{ id: "overview", title: "Explore the overview", description: "A tour step can explain one screen at a time." }, { id: "finish", title: "Finish when ready", description: "Skip or complete the tour at any step." }];
export function Example() {
const [open, setOpen] = useState(false);
return <div className="grid gap-4"><Button variant="outline" onClick={() => setOpen(true)}>Open tour</Button><Tour steps={steps} open={open} onOpenChange={setOpen} /></div>;
}
Usage
import { Tour } from "@phuctech/ui/components/tour";
<Tour open={tourOpen} onOpenChange={setTourOpen} steps={steps} onComplete={saveCompletion} />Targets and fallback
Each optional target is a CSS selector. When found, Tour scrolls it into view, adds a temporary outline and data-tour-active marker, then restores the original inline outline when the step changes or closes. Invalid or missing selectors show a message and leave Next/Skip available. Tour uses the shared modal Dialog, so the guide itself remains the focused task while open.
API
Accessibility
The shared Dialog manages initial focus, focus containment, Escape handling, and focus restoration. The title and step count name the current task, and the footer exposes Skip, Previous, Next, or Finish as keyboard controls.