Todae

Todae

Product tour

A recipe, not a package namespace. A tour walks the person through a few controls one at a time: one Coachmark points at each in turn, and your product keeps the steps, their order and whether the tour has been seen. There is no Tour.* export.

On this page

Steps

Keep the steps in an array, each with its title, its text and a ref to its target, and the current step in state. Render one Coachmark.Root for the whole tour and hand it the current step's targetRef and text, so moving on keeps the popup open and only moves it and the hole to the next target. Closing the coachmark, by Escape or Done, ends the tour.

import { Button, Coachmark, Stack, Text } from '@tounsoo/todae';
import { useRef, useState, type RefObject } from 'react';

type Step = { title: string; text: string; target: RefObject<HTMLButtonElement | null> };

// A recipe, not a component: the steps, their order and whether the person
// has seen the tour are the product's. One Coachmark.Root shows every step,
// and the tour changes its target and text.
export default function ProductTour() {
  const searchRef = useRef<HTMLButtonElement>(null);
  const filterRef = useRef<HTMLButtonElement>(null);
  const shareRef = useRef<HTMLButtonElement>(null);
  const nextRef = useRef<HTMLButtonElement>(null);
  const [at, setAt] = useState<number | null>(null);
  const steps: Step[] = [
    { title: 'Search', text: 'Find any report by its name or owner.', target: searchRef },
    { title: 'Filter', text: 'Narrow the list to one team or quarter.', target: filterRef },
    { title: 'Share', text: 'Send a link to the reports you picked.', target: shareRef },
  ];
  const step = steps[at ?? 0]!;

Focus on each step

Pass the Next button as initialFocusRef, so focus lands there as the tour starts. Next is the same element on every step, Done included, so focus stays on it as the tour moves on. Back is only there after the first step: as it goes back to the first, it moves focus to Next before it unmounts. If the person presses the target itself and that moves the tour on, the old target turns inert, and the coachmark moves focus into the popup.

Since focus stays put, a screen reader doesn't read the new step by itself. Give Coachmark.Description aria-live="polite", so its new text is read as the step changes.

Remembering the tour

Store that the tour was seen where your product stores other settings, such as the person's account, and start it again only when they ask, such as from a help menu. A tour that opens by itself on every visit makes the page inert each time.

Accessible composition

Todae handles: Everything Coachmark does for one step: the named dialog, the inert page around the target, the Tab cycle, Escape, and focus back where it was when the tour ends. When targetRef changes, the anchor, the hole and the inert page move to the new target.

You supply: The steps and their order. Next, Back and Done buttons, and a step count in words, such as "2 of 3". The live region on the description. Where the tour's state is stored.

Watch for: A step whose target isn't on the page, such as one in a closed panel: open the panel first, or leave the step out. Steps that only repeat each control's name.

When to use

When: A few new or hard-to-find controls on one page, shown once, or again when the person asks.

When not: One control → Coachmark alone. A setup the person has to finish, with answers → Wizard. Help that should stay on the page → text beside the control or a Tooltip.