Tour Steps
At the core of every Cue.js tour is an array of step objects. Each object in this array defines a single point in your guided experience: what element to highlight, what message to show, and how it behaves.
Understanding these step properties is crucial for building effective and dynamic tours.
The Anatomy of a Tour Step
A basic tour step is a JavaScript object that you pass within an array to the cue.setSteps()
method.
1. target
(Required)
target
(Required)The most fundamental property. This tells Cue.js what element on your page this step is about.
Type:
string
(CSS Selector) orHTMLElement
Description:
If an
HTMLElement
, you can pass a direct reference to a DOM element you've already obtained (e.g.,document.getElementById('myId')
).
Technical Consideration: When using a string selector, Cue.js re-queries the DOM for the
target
element before displaying each step. This is powerful for dynamic content, as the element doesn't need to exist when you initially callsetSteps()
, but it must be present in the DOM by the time its step is about to be shown.
Tip: For reliable targeting, especially when elements might load asynchronously or appear later, use unique IDs. If IDs aren't feasible, ensure your CSS selectors are robust and don't match unintended elements.
2. title
(Optional)
title
(Optional)Type:
string
Description: A concise heading that appears at the top of the tour step's tooltip. Use it to quickly summarize the purpose of the step.
3. content
(Optional)
content
(Optional)Type:
string
Description: The main body text of the tour step's tooltip. Use this to provide detailed instructions, explanations, or context. Basic HTML (like
<strong>
,<em>
,<br>
) can be included to format your text.
4. position
(Optional)
position
(Optional)Controls where the tooltip appears relative to its target
element.
Type:
string
Default:
'auto'
(or the globaltooltipPosition
option)Values:
'top'
: Tooltip appears above the target.'bottom'
: Tooltip appears below the target.'left'
: Tooltip appears to the left of the target.'right'
: Tooltip appears to the right of the target.'center'
: Tooltip appears in the center of the viewport (useful for general announcements, not tied to a specific element).'auto'
: Cue.js will intelligently try to find the best available position (prioritizingbottom
, thentop
, thenright
, thenleft
) to ensure the tooltip is fully visible within the current viewport.
5. padding
(Optional)
padding
(Optional)Adjusts the space around the highlighted target element.
Type:
number
Default:
10
(pixels) (or the globalpadding
option)Description: Controls the padding between the
target
element and the highlight border. A larger number increases the space.
6. scrollToElement
(Optional)
scrollToElement
(Optional)Determines if the page should automatically scroll to make the target visible.
Type:
boolean
Default:
true
(or the globalscrollToElement
option)Description: If
true
, Cue.js will smoothly scroll the page to ensure thetarget
element is in the viewport and properly centered (vertically). Set tofalse
if you want to manage scrolling yourself or if the element is always visible.
7. disableInteraction
(Optional)
disableInteraction
(Optional)Prevents user interaction with the highlighted element during the step.
Type:
boolean
Default:
false
Description: If
true
, thetarget
element will become non-interactive (clicks, hovers, inputs will be disabled). This is useful for "read-only" steps where you want the user to absorb information without accidentally activating the element. The overlay click-to-exit functionality remains active unless disabled globally.
8. showButtons
(Optional)
showButtons
(Optional)Overrides the global setting for displaying navigation buttons on a specific step.
Type:
boolean
Default:
true
(or the globalshowButtons
option)Description: If
false
, the "Next", "Back", "Skip", and "Done" buttons will not appear in the tooltip for this step. You would typically use this if you want to implement custom navigation logic or require a specific user action on thetarget
to proceed.
9. preStep
(Optional)
preStep
(Optional)A callback function executed before a step is displayed.
Type:
Function
(async
function supported)Description: This function runs just before the highlight and tooltip for the step appear. It's incredibly powerful for:
Showing/Hiding elements: Making a hidden element visible.
Opening/Closing menus: Navigating to a different state of your UI.
Fetching data: Waiting for asynchronous operations to complete.
Animations: Starting an animation that prepares the target.
Arguments: Receives the
step
object as an argument.Asynchronous Support: You can define
preStep
as anasync
function. Cue.js will wait for thePromise
to resolve before displaying the step.
10. postStep
(Optional)
postStep
(Optional)A callback function executed after a step is hidden.
Type:
Function
(async
function supported)Description: This function runs after the user has left the current step (either by navigating to the next/previous step, skipping the tour, or completing it). It's useful for:
Cleaning up UI: Hiding elements revealed by
preStep
.Resetting state: Closing open menus or modals.
Tracking: Logging that a user passed this specific step.
Arguments: Receives the
step
object as an argument.Asynchronous Support: Can also be an
async
function.
11. onTargetNotFound
(Optional)
onTargetNotFound
(Optional)A callback function for handling cases where a step's target
element is missing.
Type:
Function
Description: If Cue.js cannot find the element specified by
target
for a step, this function will be called. This prevents the tour from abruptly stopping if an element is missing (e.g., due to dynamic content not loading, or a user permission preventing its display).Arguments: Receives the
step
object as an argument.Return Value:
Return
'skip'
to automatically skip the current step and proceed to the next one.Return
'stop'
to stop the tour gracefully at this point.If nothing is returned, the tour will stop by default (equivalent to
'stop'
).
Putting It All Together: A Comprehensive Step Example
Here's an example combining several properties for a more complex tour step:
Next Steps
Now that you're familiar with defining individual tour steps, let's explore how to customize the visual appearance of your tours.
Last updated