Tour
A guided walk through the page, one step at a time, each pointing at an element.
Example
<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>import { Tour } from '@focsd-dev/react';
export function Example() { return <Tour onClose={(e) => console.log(e.target)}></Tour>;}<script setup>import '@focsd-dev/components/focsd-tour.js';</script>
<template> <focsd-tour @close="onChange"></focsd-tour></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-tour.js';
// template<focsd-tour (close)="onChange($event)"></focsd-tour><script> import '@focsd-dev/components/focsd-tour.js';</script>
<focsd-tour onclose={(e) => console.log(e.target)}></focsd-tour>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
open | open | boolean | false |
step | step | number | 0 |
persistent | persistent | boolean | false |
Methods
| Method | Description |
|---|---|
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
| Event | Description |
|---|---|
close | Fired 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).
| Part | Description |
|---|---|
panel | The step's dialog. |
progress | The "Step n of m" line. |
title | The step's heading. |
body | The step's text. |
actions | The row of buttons. |
back | The Back button. |
next | The Next (or Finish, on the last step) button. |
skip | The Skip tour button. |
spotlight | The 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 asstart(index, opener): Safari does not focus a clicked button, so opening with theopenattribute 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
persistentis set, or unless something in the page already handled it (a popup inside the page closing first); Skip tour always does.closefires either way: readcompletedto tell Finish from a dismissal.focsd-step-changefires withdetail.stepon every step. - The target is scrolled into view, instantly under reduced motion.
Keyboard
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move between Back, Next (or Finish) and Skip tour, and on into the page |
| Enter / Space | Activate the focused button |
| Escape | End the tour (unless persistent is set) |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.