Tour
Tour guides the user through the interface, one step at a time: a spotlight highlights an element and a card next to it explains it, with a step counter and back and next buttons. It is an accessible dialog that follows its target when the page scrolls or the layout changes.
Import #
import { Tour } from '@exhaustive-ui/core/tour';Basic #
A tour is a list of steps. Each step highlights its target, a CSS selector, an element or a function that returns one, and explains it in a card with a title and a text. The visible property starts and stops the tour; the card has a step counter, progress dots, back, next and close buttons. The mask darkens the page around a spotlight that follows the target when the page scrolls or the layout changes.
Placement #
The card is displayed below the target by default. The placement of the tour, or of a step, puts it on another side: top, right, bottom, left, auto for the side with the most room, or center. When the card does not fit, it flips to the opposite side, then to the side with the most room, and it always stays inside the screen. In right-to-left documents, left and right are swapped.
Centered Step #
A step without target is displayed in the middle of the screen, for a welcome or a closing message. A step whose target is not found, an element that is not rendered yet for example, is centered too and a warning is logged; with missingTarget set to skip, the tour moves on to the following step instead.
Template #
The step template replaces the whole card. It receives the step, its index, the total, first and last flags, the next, prev, goTo and close functions, and the titleId and contentId to give to the title and the text so that they label and describe the dialog. The header, content and footer templates replace one part of the card only and receive the same context. Use the data of a step for anything else the template needs.
Controlled #
The current step is the two-way activeIndex property: set it to start the tour at a given step or to move it from outside. onStepChange is emitted on every new step, onFinish when the user completes the tour and onClose, with its reason, when the tour is closed before its end. The component also has start(index), next(), prev(), goTo(index), close(), finish() and refresh() methods.
Without Mask #
With mask set to false, the page stays usable while the tour runs: the target keeps its ring, the card is a non-modal dialog and the focus is not trapped in it. Use it for hints the user follows while working, here filling a field.
Spotlight #
spotlightPadding and spotlightRadius size the cut-out around the target, in pixels, for the whole tour or for one step. The highlighted target stays clickable unless disableInteraction is set. A click on the mask closes the tour with dismissableMask, and closeOnEscape controls the Escape key.
Labels #
Every text of the component, screen reader announcements included, can be replaced through labels. Missing keys keep their English default; the close button uses the aria.close text of the locale. Placeholders such as {0} receive the values. showCounter and showDots hide the counter and the dots.
Accessibility #
Screen Reader
The card is an element with the dialog role, labelled by the title of the step with aria-labelledby and described by its text with aria-describedby; a step without title is labelled by its counter, for example "Step 2 of 5". With the mask, the dialog is modal, aria-modal is true and the focus stays in the card; without mask, it is a non-modal dialog. The mask, the spotlight, the arrow and the progress dots are hidden from assistive technologies, and the visible "2 / 5" counter is read as "Step 2 of 5". A polite live region announces each new step with its title. Every text can be translated through labels.
When the tour starts, the focus moves into the card; when a step changes, it stays on the button the user pressed, or moves to the card. When the tour ends, the focus returns to the element that had it before, usually the button that started the tour. A custom step template gives titleId and contentId to its title and text to keep the dialog labelled.
The transitions of the spotlight and the card are disabled, and the target is scrolled into view without smooth scrolling, when the user prefers reduced motion.
<p-button label="Take the tour" (onClick)="visible = true" />
<p-tour [steps]="steps" [(visible)]="visible" [labels]="{ next: 'Suivant', prev: 'Retour', done: 'Terminer' }" />Keyboard Support
| Key | Function |
|---|---|
| tab | Moves focus to the next focusable element of the card. With the mask, the focus cycles inside the card. |
| shift + tab | Moves focus to the previous focusable element of the card. |
| enter / space | Activates the focused button: back, next, done or close. |
| right arrow | Goes to the next step while the card has the focus, the previous step in right-to-left documents. Disabled with keyboardNavigation set to false. |
| left arrow | Goes to the previous step while the card has the focus, the next step in right-to-left documents. |
| escape | Closes the tour, unless closeOnEscape is false. |