Vitral 0.2.18
Overlay

Tour

A guided tour over the page, driven from props or from code, with steps that wait, skip, move on by themselves and remember where the reader got to.

Import

main.ts
import { Tour } from '@vitral/vue';

Basic

`v-model:open` starts and ends it. The arrow keys move between steps, Escape ends it, and each popover is a dialog a screen reader reads as it arrives.

<script setup lang="ts">import { share as shareIcon } from '@vitral/icons';import { Button, InputText, Tour, type TourStep } from '@vitral/vue';import { ref } from 'vue'; const open = ref(false);const create = ref<{ $el: HTMLElement } | null>(null);const search = ref<{ $el: HTMLElement } | null>(null);const share = ref<{ $el: HTMLElement } | null>(null); const steps: TourStep[] = [    { popover: { title: 'Welcome', description: 'A quick look at the three things you will use most. It takes a minute.' } },    { element: () => create.value, popover: { title: 'Create', description: 'Starts a new document from scratch or from a template.' } },    { element: () => search.value, popover: { title: 'Search', description: 'Finds documents, people and settings.', side: 'bottom', align: 'center' } },    { element: () => share.value, popover: { title: 'Share', description: 'Invites people, with the access you choose.', side: 'left', align: 'center' } }];</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center">            <Button ref="create" label="New" icon="plus" />            <InputText ref="search" placeholder="Search" aria-label="Search" style="flex: 1 1 12rem" />            <Button ref="share" label="Share" :icon="shareIcon" variant="outlined" severity="secondary" />        </div>        <Button label="Start the tour" icon="play" variant="text" style="align-self: flex-start" @click="open = true" />        <Tour v-model:open="open" :steps="steps" show-progress />    </div></template>

Progress, sides and the overlay

`progressStyle` draws the progress as text, dots or a bar; `side` and `align` place the popover; `overlayClickBehavior="nextStep"` makes a press on the dimmed page move on.

top
right
bottom
left
<script setup lang="ts">import { Button, SelectButton, Tour, type TourStep } from '@vitral/vue';import { ref } from 'vue'; const open = ref(false);const style = ref<'text' | 'dots' | 'bar'>('dots');const boxes = ref<HTMLElement[]>([]); const sides = ['top', 'right', 'bottom', 'left'] as const;const steps: TourStep[] = sides.map((side, i) => ({    element: () => boxes.value[i],    popover: { title: `side: '${side}'`, description: `align: 'center'. A press on the dimmed page moves on.`, side, align: 'center' }}));</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center">            <SelectButton v-model="style" :options="['text', 'dots', 'bar']" aria-label="Progress style" :allow-empty="false" />            <Button label="Start" icon="play" @click="open = true" />        </div>        <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; padding: 3rem 0">            <div v-for="side in sides" :key="side" ref="boxes" style="padding: 1rem; text-align: center; border: 1px dashed var(--vt-content-border-color); border-radius: 0.5rem">{{ side }}</div>        </div>        <Tour v-model:open="open" :steps="steps" show-progress :progress-style="style" overlay-click-behavior="nextStep" />    </div></template>

Steps that wait and move on by themselves

`advanceOn` moves on when the reader does what the step asks, `beforeShow` is waited for before a step shows, `waitFor` waits for an element that is not there yet, and `when` leaves out a step that does not apply.

<script setup lang="ts">import { settings as settingsIcon } from '@vitral/icons';import { Button, Checkbox, Tour, type TourStep } from '@vitral/vue';import { ref } from 'vue'; const open = ref(false);const loaded = ref(false);const admin = ref(false);const load = ref<{ $el: HTMLElement } | null>(null);const report = ref<HTMLElement | null>(null);const settings = ref<{ $el: HTMLElement } | null>(null); const steps: TourStep[] = [    {        element: () => load.value,        popover: { title: 'Load a report', description: 'Press the button — the tour moves on when you do.', showButtons: ['close'] },        advanceOn: { event: 'click' }    },    {        // Not on the page until the report has loaded: the step waits for it.        element: () => report.value,        waitFor: 3000,        popover: { title: 'Your report', description: 'It arrived a moment after the press, and this step waited for it.' }    },    {        // Only for someone who can change the settings.        when: () => admin.value,        element: () => settings.value,        popover: { title: 'Settings', description: 'Shown only because “I am an admin” is ticked.' }    },    { popover: { title: 'Done', description: 'Steps that do not apply were left out of the count too.' } }]; function start() {    loaded.value = false;    open.value = true;} function loadReport() {    setTimeout(() => (loaded.value = true), 400);}</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 1rem; align-items: center">            <Button label="Start" icon="play" @click="start" />            <label style="display: inline-flex; gap: 0.5rem; align-items: center"><Checkbox v-model="admin" binary /> I am an admin</label>        </div>        <div style="display: flex; flex-wrap: wrap; gap: 0.5rem">            <Button ref="load" label="Load report" icon="download" variant="outlined" @click="loadReport" />            <Button ref="settings" label="Settings" :icon="settingsIcon" variant="text" severity="secondary" />        </div>        <div v-if="loaded" ref="report" style="padding: 1rem; border: 1px solid var(--vt-content-border-color); border-radius: 0.5rem">Q3 report: revenue up 12%.</div>        <Tour v-model:open="open" :steps="steps" show-progress />    </div></template>

Motion, placement and scrolling

Off by default: `animate` moves the highlight from step to step and fades each popover in, over `animation-duration` milliseconds. `side: 'auto'` puts the popover wherever there is room, and with `arrow` the pointer follows. `scroll-into-view` brings each element into view — `smooth-scroll` for a smooth ride — and off, the page stays put while the popover stays on the screen.

First
Second
<script setup lang="ts">import { Button, Checkbox, Slider, Tour, type TourStep } from '@vitral/vue';import { ref } from 'vue'; const open = ref(false);const animate = ref(true);const duration = ref(400);const arrow = ref(true);const smooth = ref(true);const scroll = ref(true); // `side: 'auto'` takes whichever side has room, and the arrow follows it.// With `scroll-into-view` off the page stays where it is; the popover stays// on the screen anyway, beside wherever its element went.const steps: TourStep[] = [    { element: '#demo-motion-a', popover: { title: 'Top of the section', description: 'The highlight moves to the next step instead of jumping.', side: 'auto' } },    { element: '#demo-motion-b', popover: { title: 'Far below', description: 'Reached by scrolling, smoothly when asked.', side: 'auto', align: 'center' } },    { element: '#demo-motion-a', popover: { title: 'And back', description: 'Placed on whichever side has room.', side: 'auto' } }];</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.75rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 1rem; align-items: center">            <label style="display: inline-flex; gap: 0.4rem; align-items: center"><Checkbox v-model="animate" binary /> animate</label>            <label style="display: inline-flex; gap: 0.5rem; align-items: center">duration <Slider v-model="duration" :min="0" :max="1200" :step="100" style="width: 8rem" aria-label="Duration" /> {{ duration }} ms</label>            <label style="display: inline-flex; gap: 0.4rem; align-items: center"><Checkbox v-model="arrow" binary /> arrow</label>            <label style="display: inline-flex; gap: 0.4rem; align-items: center"><Checkbox v-model="scroll" binary /> scroll into view</label>            <label style="display: inline-flex; gap: 0.4rem; align-items: center"><Checkbox v-model="smooth" binary :disabled="!scroll" /> smooth</label>            <Button label="Start" icon="play" @click="open = true" />        </div>        <div id="demo-motion-a" style="padding: 0.75rem; border: 1px dashed var(--vt-content-border-color); border-radius: 0.5rem; align-self: flex-start">First</div>        <div style="height: 70vh" aria-hidden="true" />        <div id="demo-motion-b" style="padding: 0.75rem; border: 1px dashed var(--vt-content-border-color); border-radius: 0.5rem; align-self: flex-end">Second</div>        <Tour            v-model:open="open"            :steps="steps"            :animate="animate"            :animation-duration="duration"            :arrow="arrow"            :scroll-into-view="scroll"            :smooth-scroll="smooth"            show-progress            progress-style="dots"        />    </div></template>

Across pages

A step can name its `page`. Reaching one on another page goes there first: through `navigate` when there is a router (here a stand-in for one), or by loading the page, a `<Tour>` there picking the tour up by itself (`resume()` without Vue).

Inbox — 3 new
<script setup lang="ts">import { barChart, inbox, settings } from '@vitral/icons';import { Button, Icon, SelectButton, Tour, type TourStep } from '@vitral/vue';import { nextTick, ref } from 'vue'; // A stand-in for a router: three pages, one on show. With vue-router the two// options below are `navigate: (page) => router.push(page)` and// `currentPage: () => router.currentRoute.value.path`. Without a router,// leave `navigate` out: the tour loads the page, and a <Tour> there picks up.const page = ref('/inbox');const pages = ['/inbox', '/reports', '/settings'];const open = ref(false); async function navigate(to: string) {    page.value = to;    await nextTick();} const steps: TourStep[] = [    { element: '#demo-page-inbox', page: '/inbox', popover: { title: 'Inbox', description: 'Everything addressed to you. Next, the tour goes to Reports by itself.' } },    { element: '#demo-page-reports', page: '/reports', popover: { title: 'Reports', description: 'This step is on another page: the tour went there first, then found it.' } },    { element: '#demo-page-settings', page: '/settings', popover: { title: 'Settings', description: 'And one more page. Previous goes back the same way.' } }];</script> <template>    <div style="display: flex; flex-direction: column; gap: 0.75rem; width: 100%">        <div style="display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center">            <SelectButton v-model="page" :options="pages" :allow-empty="false" aria-label="Page" />            <Button label="Start the tour" icon="play" @click="open = true" />        </div>        <div style="padding: 1rem; border: 1px solid var(--vt-content-border-color); border-radius: 0.5rem; min-height: 6rem">            <div v-if="page === '/inbox'" id="demo-page-inbox" style="display: inline-flex; gap: 0.5rem; align-items: center; padding: 0.5rem 0.75rem"><Icon :icon="inbox" />Inbox — 3 new</div>            <div v-else-if="page === '/reports'" id="demo-page-reports" style="display: inline-flex; gap: 0.5rem; align-items: center; padding: 0.5rem 0.75rem"><Icon :icon="barChart" />Reports — Q3</div>            <div v-else id="demo-page-settings" style="display: inline-flex; gap: 0.5rem; align-items: center; padding: 0.5rem 0.75rem"><Icon :icon="settings" />Settings</div>        </div>        <Tour v-model:open="open" :steps="steps" :navigate="navigate" :options="{ currentPage: () => page }" show-progress />    </div></template>

One tour for the whole app

`useGlobalTour()` returns the application's own tour, the same one from any component: it belongs to the app rather than to the page that started it, so an onboarding that walks through several screens carries on across route changes. The plugin's `tour` option sets what every tour starts from — `<Tour>`, `useTour()` and this one — and each tour's own props go over it.

<script setup lang="ts">import { Button, useGlobalTour } from '@vitral/vue'; // In an application this sits where the tour is started — a help menu, a// first visit — and every page reaches the same tour with `useGlobalTour()`.// Defaults for every tour go in the plugin://   app.use(Vitral, { tour: { showProgress: true, progressStyle: 'dots', dismissableMask: false } })const tour = useGlobalTour(); function start() {    tour.setSteps([        { element: '#vt-app-tour-inbox', popover: { title: 'Inbox', description: 'Everything addressed to you. On another page, the same tour would carry on.' } },        { element: '#vt-app-tour-reports', popover: { title: 'Reports', description: 'The tour is the app’s, not this component’s: it ends when it is finished or the app goes away.' } }    ]);    tour.drive();}</script> <template>    <div style="display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center">        <Button id="vt-app-tour-inbox" label="Inbox" icon="bell" variant="outlined" severity="secondary" />        <Button id="vt-app-tour-reports" label="Reports" icon="file" variant="outlined" severity="secondary" />        <Button label="Start the app tour" icon="play" variant="text" @click="start" />    </div></template>

From code

`useTour()` returns the tour itself — `drive()`, `moveNext()`, `highlight()`, `destroy()` — and here `highlight()` shows one element on its own.

<script setup lang="ts">import { Button, useTour } from '@vitral/vue';import { ref } from 'vue'; const help = ref<{ $el: HTMLElement } | null>(null);const tour = useTour(); function explain() {    tour.highlight({        element: help.value,        popover: { title: 'Help', description: 'Opens the help centre, and the chat with support.', side: 'right', align: 'center' }    });}</script> <template>    <div style="display: flex; flex-wrap: wrap; gap: 1rem; align-items: center">        <Button ref="help" icon="info" aria-label="Help" rounded variant="outlined" severity="secondary" />        <Button label="What is this button?" variant="text" @click="explain" />    </div></template>

API

Read from packages/vue/src/components/Tour/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
steps TourStep[]—
animate booleanMove the highlight from step to step and fade each popover in. Off by default.
animationDuration numberHow long a move takes when `animate` is on, in milliseconds. Defaults to 300.
overlayColor string—
overlayOpacity number—
smoothScroll boolean—
scrollIntoView booleanBring each step's element into view. Defaults to true; off, the page stays put and the popover stays on screen.
scrollBlock 'start' | 'center' | 'end' | 'nearest'Where a scrolled-to element ends up. Defaults to `'center'`.
keepInView booleanKeep the popover on the screen even when its element is not. Defaults to true.
navigate (page: string) => void | Promise<unknown>Goes to another page for a step whose `page` is not this one — a router's `push`: `(page) => router.push(page)`. Without it, the page is loaded, and a `<Tour>` there picks the tour up by itself.
allowClose booleanEscape, the close button and a press on the overlay end the tour. Defaults to true.
overlayClickBehavior 'close' | 'nextStep'—
dismissableMask boolean`false` keeps a press on the overlay from ending the tour, as on a dialog's mask. Defaults to true.
arrow booleanA pointer from the popover to the element. Off by default.
stagePadding numberThe gap around the element, in pixels. Defaults to 2, so the highlight hugs it.
stageRadius numberThe corner of the gap. Defaults to the element's own corner, grown by the padding.
disableActiveInteraction boolean—
allowKeyboardControl booleanDefaults to true.
popoverClass string—
popoverOffset number—
showButtons TourButton[]—
disableButtons TourButton[]—
showProgress boolean—
progressText string`'{current} of {total}'`; the locale's otherwise.
progressStyle TourProgressStyle—
nextBtnText string—
prevBtnText string—
doneBtnText string—
allowHtml booleanTitles and descriptions are HTML. Only for text you wrote.
elementTimeout numberHow long a step waits for its element to appear, in milliseconds.
missingElement 'center' | 'skip'—
storageKey stringRemembers where the reader got to, and whether they finished, under this key.
options TourConfigEverything else `createTour` takes: the hooks, `storage`, `dir`.
appendTo string | HTMLElement—

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
content (context: TourStepContext)Drawn in the popover below the description, for every step.