Tour
Introduces new features by highlighting page elements one step at a time. A mask covers the page, leaving a highlighted target area. A nearby card displays a title, description and Previous/Next buttons.
Import
import { HuiTour } from '@nscode/handy-ui'
Basic Usage
Steps describes each step: target identifies the highlighted element, and title and description supply the card content. v-model:open controls visibility, and v-model:current identifies the current step, starting at 0.
Target accepts a CSS selector, element, component instance (using its root element), ref, or a function returning one of these. A function such as () => buttonRef.value is recommended: the target is resolved only when its step opens, after rendering. Offscreen targets are scrolled into view first.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const current = ref(0)
const uploadRef = ref()
const saveRef = ref()
const moreRef = ref()
const steps: TourStep[] = [
{
target: () => uploadRef.value,
title: 'Upload Files',
description: 'Choose local files to upload here. Multiple selection is supported.'
},
{
target: () => saveRef.value,
title: 'Save',
description: 'Save your changes so other members can see them.'
},
{
target: () => moreRef.value,
title: 'More Actions',
description: 'Less frequent actions such as export, share and delete are collected here.'
}
]
const start = () => {
current.value = 0
open.value = true
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace wrap>
<HuiButton type="primary" @click="start">Start tour</HuiButton>
<span>open:{{ open }},current:{{ current }}</span>
</HuiSpace>
<HuiSpace>
<HuiButton ref="uploadRef" icon="upload">Upload</HuiButton>
<HuiButton ref="saveRef" icon="save">Save</HuiButton>
<HuiButton ref="moreRef" icon="more-horizontal" aria-label="More" />
</HuiSpace>
</HuiSpace>
<HuiTour v-model:open="open" v-model:current="current" :steps="steps" />
</div>
</template>
Steps Without a Target
Without target, the card appears in the center of the screen and the mask covers the whole page without a highlighted opening. Use this for a welcome or final message.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const publishRef = ref()
const steps: TourStep[] = [
{
title: 'Welcome to the new editor',
description:
'Take a minute to explore the changes. This step has no target, so its card is centered.'
},
{
target: () => publishRef.value,
title: 'Publish',
description: 'Publish here when finished. Your work is saved automatically first.'
},
{
title: 'All done',
description: 'You can reopen this tour from the Help menu later.'
}
]
</script>
<template>
<div>
<HuiSpace wrap>
<HuiButton @click="open = true">Start tour</HuiButton>
<HuiButton ref="publishRef" type="primary" icon="upload">Publish</HuiButton>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" />
</div>
</template>
Placement
Placement controls the card position relative to the target. It defaults to bottom and supports 12 positions, flipping when space is insufficient. Arrow controls the target-pointing arrow, shown by default and hidden when there is no target.
This example disables the mask so you can change placement and toggle the arrow while it is open:
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiButton, HuiCheckbox, HuiSelect, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { PopperPlacement, SelectOption, TourStep } from '@nscode/handy-ui'
const placements: PopperPlacement[] = [
'top',
'top-start',
'top-end',
'bottom',
'bottom-start',
'bottom-end',
'left',
'left-start',
'left-end',
'right',
'right-start',
'right-end'
]
const options: SelectOption[] = placements.map((value) => ({ label: value, value }))
const open = ref(false)
const placement = ref<PopperPlacement>('bottom')
const arrow = ref(true)
const targetRef = ref<HTMLElement>()
const steps = computed<TourStep[]>(() => [
{
target: () => targetRef.value,
title: `placement:${placement.value}`,
description: 'Change the placement using the selector above.'
}
])
</script>
<template>
<div>
<HuiSpace direction="vertical" fill size="large">
<HuiSpace wrap>
<HuiSelect v-model="placement" :options="options" style="width: 160px" />
<HuiCheckbox v-model="arrow">Show arrow (arrow)</HuiCheckbox>
<HuiButton type="primary" @click="open = true">Open</HuiButton>
</HuiSpace>
<div class="stage">
<div ref="targetRef" class="target">Target element</div>
</div>
</HuiSpace>
<HuiTour
v-model:open="open"
:steps="steps"
:placement="placement"
:arrow="arrow"
:mask="false"
/>
</div>
</template>
<style scoped>
.stage {
display: flex;
justify-content: center;
padding: 160px 0;
}
.target {
padding: var(--hui-spacing-4) var(--hui-spacing-8);
color: var(--hui-text-color-secondary);
border: 1px dashed var(--hui-border-color);
border-radius: var(--hui-border-radius);
}
</style>
Mask
Mask defaults to true and uses --hui-mask-color. False hides it; an object with color customizes it.
With a mask, the whole page, including the highlighted target, is noninteractive and focus stays inside the card. Without a mask, the page remains interactive and the highlight opening disappears; only the card's arrow identifies the target.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourMask, TourStep } from '@nscode/handy-ui'
const open = ref(false)
const mask = ref<TourMask>(true)
const searchRef = ref()
const filterRef = ref()
const steps: TourStep[] = [
{
target: () => searchRef.value,
title: 'Search',
description: 'Search by name or identifier.'
},
{
target: () => filterRef.value,
title: 'Filter',
description: 'Filter by status, time and other criteria.'
}
]
const show = (value: TourMask) => {
mask.value = value
open.value = true
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace wrap>
<HuiButton @click="show(true)">Default mask (true)</HuiButton>
<HuiButton @click="show(false)">No mask (false)</HuiButton>
<HuiButton @click="show({ color: 'rgba(22, 119, 255, 0.25)' })">Blue mask</HuiButton>
<HuiButton @click="show({ color: 'rgba(0, 0, 0, 0.75)' })">Darker mask</HuiButton>
</HuiSpace>
<HuiSpace>
<HuiButton ref="searchRef" icon="search">Search</HuiButton>
<HuiButton ref="filterRef" icon="filter">Filter</HuiButton>
</HuiSpace>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" :mask="mask" />
</div>
</template>
Highlight Area
Gap sets offset, the distance extending beyond each target edge, and radius, the corner radius, in pixels. Both default to 6.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourGap, TourStep } from '@nscode/handy-ui'
const open = ref(false)
const gap = ref<TourGap>({})
const cardRef = ref<HTMLElement>()
const steps: TourStep[] = [
{
target: () => cardRef.value,
title: 'Data Overview',
description: 'Visits and order counts for today are summarized here.'
}
]
const show = (value: TourGap) => {
gap.value = value
open.value = true
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace wrap>
<HuiButton @click="show({})">Default (offset 6, radius 6)</HuiButton>
<HuiButton @click="show({ offset: 0, radius: 0 })"
>Flush square corners (offset 0, radius 0)</HuiButton
>
<HuiButton @click="show({ offset: 12, radius: 20 })"
>Wide rounded gap (offset 12, radius 20)</HuiButton
>
</HuiSpace>
<div ref="cardRef" class="overview">
<div>
<div class="overview__label">Visits</div>
<div class="overview__value">12,846</div>
</div>
<div>
<div class="overview__label">Orders</div>
<div class="overview__value">326</div>
</div>
</div>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" :gap="gap" />
</div>
</template>
<style scoped>
.overview {
display: flex;
gap: var(--hui-spacing-8);
padding: var(--hui-spacing-4) var(--hui-spacing-6);
background: var(--hui-bg-color-secondary);
border-radius: var(--hui-border-radius);
}
.overview__label {
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.overview__value {
font-size: var(--hui-font-size-xl);
font-weight: var(--hui-font-weight-semibold);
}
</style>
Card Type
Type controls the card appearance: default is a regular card; primary uses the primary background, white text and white buttons.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep, TourType } from '@nscode/handy-ui'
const open = ref(false)
const type = ref<TourType>('default')
const shareRef = ref()
const starRef = ref()
const steps: TourStep[] = [
{
target: () => shareRef.value,
title: 'Share',
description: 'Generate a link to share with colleagues.'
},
{
target: () => starRef.value,
title: 'Favorite',
description: 'Find favorites quickly from the home page.'
}
]
const show = (value: TourType) => {
type.value = value
open.value = true
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace wrap>
<HuiButton @click="show('default')">Regular card (default)</HuiButton>
<HuiButton type="primary" @click="show('primary')">Primary card (primary)</HuiButton>
</HuiSpace>
<HuiSpace>
<HuiButton ref="shareRef" icon="share">Share</HuiButton>
<HuiButton ref="starRef" icon="star">Favorite</HuiButton>
</HuiSpace>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" :type="type" />
</div>
</template>
Step Indicator
Indicator controls the card's bottom-left step display: text (default, such as 2 / 4), dots (highlighting the current step), or none.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourIndicator, TourStep } from '@nscode/handy-ui'
const open = ref(false)
const indicator = ref<TourIndicator>('text')
const aRef = ref()
const bRef = ref()
const cRef = ref()
const dRef = ref()
const steps: TourStep[] = [
{ target: () => aRef.value, title: 'Create', description: 'Create a document.' },
{ target: () => bRef.value, title: 'Edit', description: 'Edit the document content.' },
{ target: () => cRef.value, title: 'Copy', description: 'Make a copy.' },
{
target: () => dRef.value,
title: 'Delete',
description: 'Deleted items can be recovered from the recycle bin.'
}
]
const show = (value: TourIndicator) => {
indicator.value = value
open.value = true
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace wrap>
<HuiButton @click="show('text')">Text (text)</HuiButton>
<HuiButton @click="show('dots')">Dots (dots)</HuiButton>
<HuiButton @click="show('none')">Hidden (none)</HuiButton>
</HuiSpace>
<HuiSpace>
<HuiButton ref="aRef" icon="plus">Create</HuiButton>
<HuiButton ref="bRef" icon="edit">Edit</HuiButton>
<HuiButton ref="cRef" icon="copy">Copy</HuiButton>
<HuiButton ref="dRef" icon="trash" type="danger" plain>Delete</HuiButton>
</HuiSpace>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" :indicator="indicator" />
</div>
</template>
Button Text
Buttons use the active locale's Previous, Next and Finish labels. An English application needs no additional overrides. For one tour's custom wording, use prev-button-text, next-button-text and finish-button-text:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const inboxRef = ref()
const settingRef = ref()
const steps: TourStep[] = [
{ title: 'Welcome', description: 'Take a quick look at what is new.' },
{ target: () => inboxRef.value, title: 'Inbox', description: 'All your messages are here.' },
{ target: () => settingRef.value, title: 'Settings', description: 'Change your preferences.' }
]
</script>
<template>
<div>
<HuiSpace wrap>
<HuiButton type="primary" @click="open = true">Start tour</HuiButton>
<HuiButton ref="inboxRef" icon="mail">Inbox</HuiButton>
<HuiButton ref="settingRef" icon="setting">Settings</HuiButton>
</HuiSpace>
<HuiTour
v-model:open="open"
:steps="steps"
prev-button-text="Back"
next-button-text="Continue"
finish-button-text="Got it"
/>
</div>
</template>
Closing
By default, the top-right close button and Esc close the tour. Show-close=false hides the button. Keyboard=false disables Esc and arrow-key navigation. With both disabled, users must complete all steps.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const showClose = ref(true)
const keyboard = ref(true)
const helpRef = ref()
const steps: TourStep[] = [
{
target: () => helpRef.value,
title: 'Help',
description: 'Find help here when you have a question.'
},
{ title: 'Finish', description: 'Click Finish to end the tour.' }
]
const show = (close: boolean, key: boolean) => {
showClose.value = close
keyboard.value = key
open.value = true
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiSpace wrap>
<HuiButton @click="show(true, true)">Default</HuiButton>
<HuiButton @click="show(false, true)">Hide close button (show-close=false)</HuiButton>
<HuiButton @click="show(true, false)">Disable keyboard (keyboard=false)</HuiButton>
<HuiButton @click="show(false, false)">Disable both</HuiButton>
</HuiSpace>
<HuiButton ref="helpRef" icon="info">Help</HuiButton>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" :show-close="showClose" :keyboard="keyboard" />
</div>
</template>
Per-Step Options
Each step can override placement, mask and type. Below, step 1 places its card on the right, step 2 uses the primary type, and step 3 has no mask:
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const homeRef = ref()
const appsRef = ref()
const userRef = ref()
const steps: TourStep[] = [
{
target: () => homeRef.value,
title: 'Home',
description: 'This step uses placement: right.',
placement: 'right'
},
{
target: () => appsRef.value,
title: 'Apps',
description: 'This step uses type: primary.',
type: 'primary'
},
{
target: () => userRef.value,
title: 'Profile',
description: 'This step uses mask: false, keeping the page interactive.',
mask: false
}
]
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiButton type="primary" @click="open = true">Start tour</HuiButton>
<HuiSpace>
<HuiButton ref="homeRef" icon="home">Home</HuiButton>
<HuiButton ref="appsRef" icon="apps">Apps</HuiButton>
<HuiButton ref="userRef" icon="user">Profile</HuiButton>
</HuiSpace>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" />
</div>
</template>
Slots
- Title and default slots customize heading and body, with { step, current, total }.
- Indicator customizes the step indicator, with { current, total }.
- Actions customizes footer buttons. Its scope also contains isFirst, isLast and the methods prev, next and close. On the last step, next is equivalent to Finish.
Width controls the card width and defaults to 320px. Increase it for more content.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTag, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const exportRef = ref()
const chartRef = ref()
const steps: TourStep[] = [
{
target: () => exportRef.value,
title: 'Batch Export',
description: 'Select multiple rows and export them together.'
},
{
target: () => chartRef.value,
title: 'Chart View',
description: 'Switch table data to a chart view.'
}
]
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiButton type="primary" @click="open = true">Explore new features</HuiButton>
<HuiSpace>
<HuiButton ref="exportRef" icon="download">Export</HuiButton>
<HuiButton ref="chartRef" icon="eye">Chart</HuiButton>
</HuiSpace>
</HuiSpace>
<HuiTour v-model:open="open" :steps="steps" :width="360">
<template #title="{ step }">
<HuiSpace size="small">
<span>{{ step.title }}</span>
<HuiTag size="small" type="success">New feature</HuiTag>
</HuiSpace>
</template>
<template #default="{ step, current }">
<p class="tour-text">{{ step.description }}</p>
<p class="tour-tip">
Tip: ← and → also switch steps. This is new feature {{ current + 1 }}.
</p>
</template>
<template #indicator="{ current, total }">
<span class="tour-tip">Remaining: {{ total - current - 1 }} features</span>
</template>
<template #actions="{ isLast, next, close }">
<HuiButton size="small" variant="text" @click="close">Skip</HuiButton>
<HuiButton size="small" type="primary" @click="next">
{{ isLast ? 'Get started' : 'Continue' }}
</HuiButton>
</template>
</HuiTour>
</div>
</template>
<style scoped>
.tour-text {
margin: 0;
}
.tour-tip {
margin: var(--hui-spacing-2) 0 0;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
span.tour-tip {
margin: 0;
}
</style>
Events
- Change reports a new step reached through Previous, Next or arrow keys. External changes to current do not emit it.
- Finish reports clicking Finish on the last step.
- Close reports the close button or Esc, with the step index at closing. Finish does not emit close.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
const open = ref(false)
const logs = ref<string[]>([])
const undoRef = ref()
const redoRef = ref()
const refreshRef = ref()
const steps: TourStep[] = [
{ target: () => undoRef.value, title: 'Undo', description: 'Undo the last change.' },
{
target: () => redoRef.value,
title: 'Redo',
description: 'Restore the change you just undid.'
},
{ target: () => refreshRef.value, title: 'Refresh', description: 'Reload the data.' }
]
const log = (text: string) => {
logs.value = [text, ...logs.value].slice(0, 5)
}
</script>
<template>
<div>
<HuiSpace direction="vertical" align="start" size="large">
<HuiButton type="primary" @click="open = true">Start tour</HuiButton>
<HuiSpace>
<HuiButton ref="undoRef" icon="rotate-left">Undo</HuiButton>
<HuiButton ref="redoRef" icon="rotate-right">Redo</HuiButton>
<HuiButton ref="refreshRef" icon="refresh">Refresh</HuiButton>
</HuiSpace>
<div>
<div v-for="(item, index) in logs" :key="index">{{ item }}</div>
<div v-if="!logs.length">Open the tour to see its events here</div>
</div>
</HuiSpace>
<HuiTour
v-model:open="open"
:steps="steps"
@change="(current) => log(`change: moved to step ${current + 1}`)"
@finish="log('finish: tour completed')"
@close="(current) => log(`close: closed at step ${current + 1}`)"
/>
</div>
</template>
Repositioning
Scrolling, window resizing and size changes in the card, target or page automatically update positioning. If the target moves without resizing, such as through a margin change or transform animation, call updatePosition() manually.
This example disables the mask. Open it, then click Move target:
<script setup lang="ts">
import { nextTick, ref } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
import type { TourExpose, TourStep } from '@nscode/handy-ui'
const open = ref(false)
const moved = ref(false)
const tourRef = ref<TourExpose>()
const boxRef = ref<HTMLElement>()
const steps: TourStep[] = [
{
target: () => boxRef.value,
title: 'Moving Target',
description: 'Click Move target; the highlight and card follow it.'
}
]
const move = async () => {
moved.value = !moved.value
await nextTick()
tourRef.value?.updatePosition()
}
</script>
<template>
<div>
<HuiSpace direction="vertical" fill size="large">
<HuiSpace wrap>
<HuiButton type="primary" @click="open = true">Open</HuiButton>
<HuiButton @click="move">Move target</HuiButton>
</HuiSpace>
<div class="track">
<div ref="boxRef" class="box" :class="{ 'box--moved': moved }">Target</div>
</div>
</HuiSpace>
<HuiTour ref="tourRef" v-model:open="open" :steps="steps" :mask="false" />
</div>
</template>
<style scoped>
.track {
padding-bottom: 160px;
}
.box {
width: 80px;
padding: var(--hui-spacing-3) 0;
text-align: center;
color: var(--hui-color-white);
background: var(--hui-color-primary);
border-radius: var(--hui-border-radius);
}
.box--moved {
margin-left: 240px;
}
</style>
Keyboard Interaction
| Key | Action |
|---|---|
| Esc | Closes and emits close |
| → | Goes to the next step. Does nothing on the last step rather than finishing |
| ← | Goes to the previous step. Does nothing on the first step |
| Tab | Cycles within the card when masked; otherwise may move onto the page |
Opening moves focus to the card. Closing restores the previously focused element. Arrow keys do not switch steps while an input is focused, or when the tour is unmasked and focus is elsewhere on the page. Keyboard=false disables Esc and arrow-key handling.
Internal and Controlled Steps
Without current, or with only an update listener, the component stores the step internally. Providing it makes it controlled; explicit undefined displays step 0. Previous, Next and arrow-key requests are calculated from the actual step. If the parent rejects a request, the heading, indicator and slots retain the actual state. Reopening an uncontrolled tour starts at step 0 without emitting an additional step update for that reset.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiButton, HuiTour, HuiSpace } from '@nscode/handy-ui'
import type { TourStep } from '@nscode/handy-ui'
type CurrentMode = 'local' | 'listener' | 'empty' | 'fixed' | 'bound'
const currentMode = ref<CurrentMode>('local')
const currentOpen = ref(false)
const currentBound = ref(1)
const currentRedraw = ref(0)
const currentLast = ref<number | string>('None yet')
const currentSteps: TourStep[] = [
{ title: 'Step A', description: 'First step' },
{ title: 'Step B', description: 'Second step' },
{ title: 'Step C', description: 'Third step' }
]
const recordCurrent = (value: number) => {
currentLast.value = value
}
const currentBinding = computed(() =>
currentMode.value === 'empty'
? { current: undefined }
: currentMode.value === 'fixed'
? { current: 1 }
: currentMode.value === 'bound'
? {
current: currentBound.value,
'onUpdate:current': (value: number) => {
currentBound.value = value
}
}
: currentMode.value === 'listener'
? { 'onUpdate:current': recordCurrent }
: {}
)
const launchCurrent = (mode: CurrentMode) => {
currentMode.value = mode
currentBound.value = 1
currentLast.value = 'None yet'
currentOpen.value = true
}
</script>
<template>
<HuiSpace class="tour-current-q1-demo" direction="vertical" fill>
<HuiSpace wrap>
<HuiButton class="current-local" @click="launchCurrent('local')"
>Current prop omitted</HuiButton
>
<HuiButton class="current-listener" @click="launchCurrent('listener')"
>Update listener only</HuiButton
>
<HuiButton class="current-empty" @click="launchCurrent('empty')"
>Explicit undefined</HuiButton
>
<HuiButton class="current-fixed" @click="launchCurrent('fixed')"
>Fixed second step; parent rejects updates</HuiButton
>
<HuiButton class="current-bound" @click="launchCurrent('bound')">Two-way binding</HuiButton>
</HuiSpace>
<span class="current-status"
>Mode: {{ currentMode }}; observed request: {{ currentLast }}; bound step: {{ currentBound }};
parent redraw: {{ currentRedraw }}</span
>
<HuiTour
v-if="currentOpen"
v-model:open="currentOpen"
v-bind="currentBinding"
:steps="currentSteps"
:data-parent="currentRedraw"
>
<template #default="{ step, current }">
<HuiSpace direction="vertical">
<span>{{ step.description }}; actual step: {{ current }}</span>
<HuiButton class="current-redraw" @click="currentRedraw++"
>Parent redraw {{ currentRedraw }}</HuiButton
>
</HuiSpace>
</template>
</HuiTour>
</HuiSpace>
</template>
Native Attributes and Card Semantics
class and style belong to the outer tour container. id, data-*, tabindex, aria-*, and undeclared DOM listeners belong to the actual role="dialog" card. Explicit aria-labelledby wins; otherwise an aria-label, including an empty string, supplies the name. Removing that attribute restores the step-title association. User aria-describedby IDs are merged with the step-description ID.
<script setup lang="ts">
import { ref, useId } from 'vue'
import { HuiButton, HuiSpace, HuiTour } from '@nscode/handy-ui'
const open = ref(false)
const customName = ref<string | undefined>('Account setup tour')
const helpId = useId()
const dialogId = useId()
const clicks = ref(0)
const target = ref('No click')
const steps = [
{ title: 'Settings entry', description: 'Review account settings.' },
{ title: 'Finish setup', description: 'Check and confirm the settings.' }
]
const record = (event: MouseEvent) => {
clicks.value++
target.value = (event.currentTarget as HTMLElement).getAttribute('role') ?? ''
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiSpace
><HuiButton @click="open = true">Open tour</HuiButton
><HuiButton @click="customName = customName === undefined ? 'Account setup tour' : undefined"
>Toggle custom name</HuiButton
></HuiSpace
>
<p :id="helpId">The external help and current step description both describe the card.</p>
<span>Native clicks: {{ clicks }}; listener target: {{ target }}</span>
<HuiTour
:id="dialogId"
v-model:open="open"
:steps="steps"
:mask="false"
:aria-label="customName"
:aria-describedby="helpId"
tabindex="0"
data-guide="account"
class="tour-semantics"
@click="record"
/>
</HuiSpace>
</template>
Card buttons retain their normal behavior and notify the native listener once per click. event.currentTarget is the card; event.target remains the clicked descendant. Attributes can be updated or removed dynamically.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | false | Visibility, supporting v-model:open |
| current | number | — | Zero-based step. Controlled when provided, including undefined as 0. Otherwise internal, including listener-only usage; restarts at the first step on opening |
| steps | TourStep[] | [] | Step definitions; see TourStep |
| type | 'default' | 'primary' | 'default' | Card appearance |
| mask | boolean | { color?: string } | true | Mask visibility and optional color |
| gap | { offset?: number; radius?: number } | { offset: 6, radius: 6 } | Highlight expansion beyond each target edge and radius in pixels |
| placement | PopperPlacement | 'bottom' | Card position relative to the target, with 12 values and automatic flipping |
| arrow | boolean | true | Whether to show the target-pointing arrow, hidden without a target |
| width | number | string | 320 | Card width; numbers use pixels. Maximum is viewport width minus 16px |
| indicator | 'text' | 'dots' | 'none' | 'text' | Text such as 2 / 4, dots, or no indicator |
| showClose | boolean | true | Whether to show the top-right close button |
| keyboard | boolean | true | Whether Esc closes and left/right arrows switch steps |
| prevButtonText | string | Localized Previous | Previous button label |
| nextButtonText | string | Localized Next | Next button label |
| finishButtonText | string | Localized Finish | Final-step Finish label |
TourStep
| Property | Type | Description |
|---|---|---|
| target | TourTarget | Selector, element, component instance, ref or a function returning one. Omitting it centers the card on screen |
| title | string | Title |
| description | string | Description |
| placement | PopperPlacement | Step position, overriding the component prop |
| mask | boolean | { color?: string } | Step mask, overriding the component prop |
| type | 'default' | 'primary' | Step card appearance, overriding the component prop |
Events
| Event | Callback Arguments | Description |
|---|---|---|
| update:open | (value: boolean) | Emits false on the close button, Esc or Finish |
| update:current | (value: number) | Step changes |
| change | (current: number) | Previous, Next or arrow-key navigation. External current changes do not emit it |
| finish | — | Finish is clicked on the last step |
| close | (current: number) | Close button or Esc, with the current step. Finish and external open changes do not emit it |
Slots
| Slot | Scope Arguments | Description |
|---|---|---|
| title | { step, current, total } | Title |
| default | { step, current, total } | Body, replacing the step's description |
| indicator | { current, total } | Step indicator |
| actions | { step, current, total, isFirst, isLast, prev, next, close } | Footer actions, replacing Previous/Next |
Methods
| Method | Description |
|---|---|
| updatePosition | Recalculates the highlight and card positions after target movement not caused by scrolling or resizing |
Types
import type {
TourProps,
TourEmits,
TourStep,
TourTarget,
TourTargetElement,
TourType,
TourMask,
TourGap,
TourIndicator,
TourStepSlotProps,
TourIndicatorSlotProps,
TourActionsSlotProps,
TourSlots,
TourExpose
} from '@nscode/handy-ui'