Skip to content
Focsd homeFocsd homeFocsd
Forms

Tour

A guided walk through the page, one step at a time, each pointing at an element.

  • Tag: focsd-tour
  • Pattern: Non-modal dialog anchored to each step's target
  • Category: Overlays

Example

Take the tour Search Export
HTML
<div>
<focsd-button id="tour-demo-start">Take the tour</focsd-button>
<focsd-button id="tour-demo-search">Search</focsd-button>
<focsd-button id="tour-demo-export">Export</focsd-button>
</div>
<focsd-tour id="tour-demo"></focsd-tour>
<script type="module">
const tour = document.getElementById('tour-demo');
tour.steps = [
{ target: '#tour-demo-search', title: 'Search', body: 'Find any project by name or owner.' },
{ target: '#tour-demo-export', title: 'Export', body: 'Download the table as CSV.', placement: 'top' },
];
document.getElementById('tour-demo-start').addEventListener('click', () => tour.start());
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-tour.js';
</script>
<focsd-tour></focsd-tour>

API

Attributes

AttributePropertyTypeDefault
openopenbooleanfalse
stepstepnumber0
persistentpersistentbooleanfalse

Methods

MethodDescription
start(index, opener)Start the tour at step index, or the first step after it whose target is on the page (announcing the ones skipped). Does nothing when no such step exists.
next()Show the next step whose target is on the page, announcing skipped ones; on the last step, finish.
back()Show the previous step whose target is on the page, announcing skipped ones.
end(completed)End the tour: hide it, return focus to the opener, then fire close.

Events

EventDescription
closeFired when the tour ends. Read completed to tell finishing from dismissing.

CSS parts

Style the inside of the component with ::part(), for example focsd-tour::part(panel).

PartDescription
panelThe step's dialog.
progressThe "Step n of m" line.
titleThe step's heading.
bodyThe step's text.
actionsThe row of buttons.
backThe Back button.
nextThe Next (or Finish, on the last step) button.
skipThe Skip tour button.
spotlightThe box drawn around the target, dimming the rest of the page.

Accessibility

  • Each step is a non-modal dialog (aria-modal="false") named by its title and described by its body, so the page stays usable: the spotlight never takes pointer events.
  • Focus moves to each step's heading, so the title and body are read; the end of the tour returns focus to the element focused at start() (pass the opener as start(index, opener): Safari does not focus a clicked button, so opening with the open attribute has no opener there).
  • The progress ("Step 1 of 2") counts the steps whose targets are on the page when the tour starts. A step whose target is missing when reached is skipped and announced by its title ("Skipped “Filters”: it is not on this page."), or by its number when it has no title; a target removed while its step shows moves the tour on.
  • Escape ends the tour unless persistent is set, or unless something in the page already handled it (a popup inside the page closing first); Skip tour always does. close fires either way: read completed to tell Finish from a dismissal. focsd-step-change fires with detail.step on every step.
  • The target is scrolled into view, instantly under reduced motion.

Keyboard

KeyAction
Tab / Shift+TabMove between Back, Next (or Finish) and Skip tour, and on into the page
Enter / SpaceActivate the focused button
EscapeEnd the tour (unless persistent is set)