sp-coachmark

Overview API Changelog

Overview

Section titled Overview

<sp-coachmark> is a temporary message that educates users through new or unfamiliar product experiences. They can be chained into a sequence to form a tour.

Usage

Section titled Usage

See it on NPM! How big is this package in your project? Try it on Stackblitz

yarn add @spectrum-web-components/coachmark

Import the side effectful registration of <sp-coachmark> via:

import '@spectrum-web-components/coachmark/sp-coachmark.js';

When looking to leverage the Coachmark base class as a type and/or for extension purposes, do so via:

import { Coachmark } from '@spectrum-web-components/coachmark';

Anatomy

Section titled Anatomy

The coachmark consists of several key parts:

  • A title (via slot="title")
  • Content (via slot="content")
  • Optional action menu (via slot="actions")
  • Optional media content (via slot="asset" or src attribute)
  • Navigation controls (via primary-cta and secondary-cta attributes)
  • Tour progress indicators (via current-step and total-steps attributes)
  • Optional keyboard shortcuts (via modifierKeys and shortcutKey properties)

Here's a complete example showing the anatomy:

<sp-coachmark
    current-step="2"
    total-steps="8"
    open
    primary-cta="Next"
    secondary-cta="Previous"
>
    <!-- Title -->
    <div slot="title">Welcome to the Tour</div>

    <!-- Main content -->
    <div slot="content">
        This coachmark demonstrates the various parts that make up the
        component.
    </div>

    <!-- Media content -->
    <img
        slot="asset"
        src="https://picsum.photos/id/237/200/300"
        alt="Feature demonstration"
    />

    <!-- Action menu -->
    <sp-action-menu
        slot="actions"
        label="More Actions"
        placement="bottom-end"
        quiet
    >
        <sp-menu-item>Skip tour</sp-menu-item>
        <sp-menu-item>Restart tour</sp-menu-item>
    </sp-action-menu>
</sp-coachmark>

Options

Section titled Options
Navigation

The primary-cta and secondary-cta attributes are used to display navigation buttons.

<sp-coachmark
    id="coachmark-navigation"
    open
    primary-cta="Next"
    secondary-cta="Previous"
>
    <div slot="title">Coachmark with navigation</div>
    <div slot="content">
        This coachmark demonstrates the navigation buttons.
    </div>
    <!-- Action menu -->
    <sp-action-menu
        slot="actions"
        label="More Actions"
        placement="bottom-end"
        quiet
    >
        <sp-menu-item>Skip tour</sp-menu-item>
        <sp-menu-item>Restart tour</sp-menu-item>
    </sp-action-menu>
</sp-coachmark>
Progress Indicator Keyboard Shortcuts Modifier Keys

Behaviours

Section titled Behaviours

User action-dependent coachmarks are designed to guide users based on their interactions within your application. In such cases, there is no "Next Step" button, as the coachmark progresses when the user takes a specific action. This allows users to learn by doing, rather than simply reading instructions. The coachmark remains until the user performs the required action or takes an alternative route in the tour, such as skipping, restarting, or moving back to a previous step.

Inside the <sp-coachmark>, add the content and instructions for the coachmark in the <sp-coachmark>. You can also define primary and secondary CTA buttons for user interaction.

<sp-coachmark
    id="coachmark-action"
    open
    current-step="2"
    total-steps="8"
    primary-cta="Asset added"
    secondary-cta="Previous"
>
    <div slot="title">Coachmark with user action</div>
    <div slot="content">
        This coachmark waits for the user to complete a specific action.
    </div>
    <sp-action-menu
        label="More Actions"
        placement="bottom-end"
        quiet
        slot="actions"
    >
        <sp-menu-item>Skip tour</sp-menu-item>
        <sp-menu-item>Restart tour</sp-menu-item>
    </sp-action-menu>
</sp-coachmark>

Accessibility

Section titled Accessibility

Coachmarks should be designed with accessibility in mind:

  • Always provide clear, concise title and content text
  • Use descriptive labels for navigation buttons
  • Ensure keyboard navigation works for multi-step tours
  • Make sure images have appropriate alt text
  • Consider focus management during tour progression

For users that rely on screen readers, coachmarks announce their presence and content appropriately. The component manages focus to ensure users can navigate through the tour using only a keyboard.