You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The latest versions of Rollup and Webpack support ES6 imports. Shepherd ships as an ES module
8
-
which should allow you to import using standard ES import syntax.
7
+
The latest versions of Rollup and Webpack support ES6 imports. Shepherd ships as
8
+
an ES module which should allow you to import using standard ES import syntax.
9
9
10
10
i.e.
11
11
@@ -25,8 +25,8 @@ const tour = new Shepherd.Tour({
25
25
});
26
26
```
27
27
28
-
The `defaultStepOptions` option allows you to specify any options which should be applied
29
-
to all this tour's steps by default.
28
+
The `defaultStepOptions` option allows you to specify any options which should
29
+
be applied to all this tour's steps by default.
30
30
31
31
Next, add your steps:
32
32
@@ -54,7 +54,10 @@ Finally, to start the tour, just call `start` on your `Tour` instance:
54
54
tour.start();
55
55
```
56
56
57
-
If you need to remove a step from your tour, call `removeStep` on your `Tour` instance. If the step currently being displayed is the one you're removing, and there are steps left in the tour, then the first one will be shown, otherwise, the tour will be cancelled.
57
+
If you need to remove a step from your tour, call `removeStep` on your `Tour`
58
+
instance. If the step currently being displayed is the one you're removing, and
59
+
there are steps left in the tour, then the first one will be shown, otherwise,
60
+
the tour will be cancelled.
58
61
59
62
```javascript
60
63
tour.removeStep('example-step');
@@ -73,12 +76,14 @@ occurring in _any_ tour:
73
76
74
77
-`Shepherd.on(eventName, handler, [context])`: Bind an event
75
78
-`Shepherd.off(eventName, [handler])`: Unbind an event
76
-
-`Shepherd.once(eventName, handler, [context])`: Bind just the next instance of an event
79
+
-`Shepherd.once(eventName, handler, [context])`: Bind just the next instance of
80
+
an event
77
81
78
82
##### Events
79
83
80
-
The global Shepherd fires the following events whenever a `Tour` instance fires them. It adds to the object passed to the
81
-
event handlers a `tour` key pointing to the instance which fired the event:
84
+
The global Shepherd fires the following events whenever a `Tour` instance fires
85
+
them. It adds to the object passed to the event handlers a `tour` key pointing
86
+
to the instance which fired the event:
82
87
83
88
-`complete`
84
89
-`cancel`
@@ -100,7 +105,8 @@ For multiple events, you can use something like:
100
105
101
106
##### Current Tour
102
107
103
-
The global `Shepherd` includes a property which is always set to the currently active tour, or null if there is no active tour:
108
+
The global `Shepherd` includes a property which is always set to the currently
109
+
active tour, or null if there is no active tour:
104
110
105
111
-`Shepherd.activeTour`
106
112
@@ -118,25 +124,37 @@ const myTour = new Shepherd.Tour(options);
118
124
119
125
##### Tour Options
120
126
121
-
-`classPrefix`: The prefix to add to the `shepherd-enabled` and `shepherd-target` class names as well as the `data-shepherd-step-id`.
127
+
-`classPrefix`: The prefix to add to the `shepherd-enabled` and
128
+
`shepherd-target` class names as well as the `data-shepherd-step-id`.
122
129
-`confirmCancel`:
123
130
- If true, will issue a `window.confirm` before cancelling
124
-
- If it is a function(support Async Function), it will be called and wait for the return value, and will only be cancelled if the value returned is true
131
+
- If it is a function(support Async Function), it will be called and wait for
132
+
the return value, and will only be cancelled if the value returned is true
125
133
-`confirmCancelMessage`: The message to display in the confirm dialog
126
134
-`defaultStepOptions`: Default options for Steps created through `addStep`
127
-
-`exitOnEsc`: Exiting the tour with the escape key will be enabled unless this is explicitly set to `false`.
128
-
-`keyboardNavigation`: Navigating the tour via left and right arrow keys will be enabled unless this is explicitly set to `false`.
129
-
-`stepsContainer` An optional container element for the steps. If not set, the steps will be appended to `document.body`.
130
-
-`modalContainer` An optional container element for the modal. If not set, the modal will be appended to `document.body`.
131
-
-`steps`: An array of step options objects or Step instances to initialize the tour with.
132
-
-`tourName`: An optional "name" for the tour. This will be appended to the the tour's
133
-
dynamically generated `id` property.
134
-
-`useModalOverlay`: Whether or not steps should be placed above a darkened modal overlay. If true, the overlay will create an opening around the target element so that it can remain interactive.
135
+
-`exitOnEsc`: Exiting the tour with the escape key will be enabled unless this
136
+
is explicitly set to `false`.
137
+
-`keyboardNavigation`: Navigating the tour via left and right arrow keys will
138
+
be enabled unless this is explicitly set to `false`.
139
+
-`stepsContainer` An optional container element for the steps. If not set, the
140
+
steps will be appended to `document.body`.
141
+
-`modalContainer` An optional container element for the modal. If not set, the
142
+
modal will be appended to `document.body`.
143
+
-`steps`: An array of step options objects or Step instances to initialize the
144
+
tour with.
145
+
-`tourName`: An optional "name" for the tour. This will be appended to the the
146
+
tour's dynamically generated `id` property.
147
+
-`useModalOverlay`: Whether or not steps should be placed above a darkened
148
+
modal overlay. If true, the overlay will create an opening around the target
149
+
element so that it can remain interactive.
135
150
136
151
##### Tour Methods
137
152
138
-
-`addStep(options)`: Creates a new Step object with options, and returns the `Step` instance it created. If the options hash doesn't include an `id`, one will be generated.
139
-
You can also pass an existing `Step` instance rather than `options`, but note that Shepherd does not support a Step being attached to multiple Tours.
153
+
-`addStep(options)`: Creates a new Step object with options, and returns the
154
+
`Step` instance it created. If the options hash doesn't include an `id`, one
155
+
will be generated. You can also pass an existing `Step` instance rather than
156
+
`options`, but note that Shepherd does not support a Step being attached to
157
+
multiple Tours.
140
158
-`addSteps([Steps])`: Add multiple steps to the tour
141
159
-`getById(id)`: Return a step with a specific id
142
160
-`isActive()`: Check if the tour is active
@@ -145,7 +163,8 @@ const myTour = new Shepherd.Tour(options);
145
163
-`cancel()`: Trigger cancel on the current step, hiding it without advancing
146
164
-`complete()`: Calls \_done() triggering the `complete` event
147
165
-`hide()`: Hide the current step
148
-
-`show([id])`: Show the step specified by id (if it's a string), or index (if it's a number) provided. Defaults to the first step.
166
+
-`show([id])`: Show the step specified by id (if it's a string), or index (if
167
+
it's a number) provided. Defaults to the first step.
149
168
-`start()`: Show the first step and begin the tour
150
169
-`getCurrentStep()`: Returns the currently shown step
151
170
-`removeStep(id)`: Removes the step from the tour
@@ -161,8 +180,8 @@ const myTour = new Shepherd.Tour(options);
161
180
-`show`: Triggered with a hash of the `step` and the `previous` step
162
181
-`start`
163
182
164
-
Steps are instances of the Step object. They are generally created by the`Tour::addStep` method, which returns the `Step` instance it
165
-
created.
183
+
Steps are instances of the Step object. They are generally created by the
184
+
`Tour::addStep` method, which returns the `Step` instance it created.
166
185
167
186
#### Steps
168
187
@@ -171,12 +190,18 @@ created.
171
190
-`text`: The text in the body of the step. It can be one of three types:
172
191
- HTML string
173
192
-`HTMLElement` object
174
-
-`Function` to be executed when the step is built. It must return one the two options above.
193
+
-`Function` to be executed when the step is built. It must return one the two
194
+
options above.
175
195
-`title`: The step's title. It becomes an `h3` at the top of the step.
176
-
-`attachTo`: The element the step should be attached to on the page. An object with properties `element` and `on`.
177
-
-`element`: An element selector string, a DOM element, or a function (returning a selector, a DOM element, `null` or `undefined`).
178
-
-`on`: The optional direction to place the Floating UI tooltip relative to the element.
If you don’t specify an `attachTo` the element will appear in the middle of the screen. The same will happen if your
189
-
`attachTo.element` callback returns `null`, `undefined`, or a selector that does not exist in the DOM.
213
+
If you don’t specify an `attachTo` the element will appear in the middle of the
214
+
screen. The same will happen if your `attachTo.element` callback returns `null`,
215
+
`undefined`, or a selector that does not exist in the DOM.
190
216
191
-
If you omit the `on` portion of `attachTo`, the element will still be highlighted, but the tooltip will appear
192
-
in the middle of the screen, without an arrow pointing to the target.
217
+
If you omit the `on` portion of `attachTo`, the element will still be
218
+
highlighted, but the tooltip will appear in the middle of the screen, without an
219
+
arrow pointing to the target.
193
220
194
-
If the element to highlight does not yet exist while instantiating tour steps, you may use lazy evaluation by supplying a function to `attachTo.element`. The function will be called in the `before-show` phase.
221
+
If the element to highlight does not yet exist while instantiating tour steps,
222
+
you may use lazy evaluation by supplying a function to `attachTo.element`. The
223
+
function will be called in the `before-show` phase.
195
224
196
-
-`beforeShowPromise`: A function that returns a promise. When the promise resolves, the rest of the `show` code for
197
-
the step will execute. For example:
225
+
-`beforeShowPromise`: A function that returns a promise. When the promise
226
+
resolves, the rest of the `show` code for the step will execute. For example:
198
227
```javascript
199
228
beforeShowPromise:function() {
200
229
returnnewPromise(function(resolve) {
@@ -204,38 +233,81 @@ If the element to highlight does not yet exist while instantiating tour steps, y
204
233
});
205
234
},
206
235
```
207
-
-`canClickTarget` A boolean, that when set to false, will set `pointer-events: none` on the target
236
+
-`canClickTarget` A boolean, that when set to false, will set
237
+
`pointer-events: none` on the target
208
238
-`cancelIcon` Options for the cancel icon
209
-
-`enabled` Should a cancel “✕” be shown in the header of the step?
239
+
-`attrs` Additional HTML attributes to apply to the cancel icon button
240
+
element. This is useful for adding data attributes for testing or analytics.
241
+
Note: These attributes cannot override critical properties like `type`,
242
+
`onclick`, `class`, or `aria-label`.
243
+
244
+
```javascript
245
+
cancelIcon: {
246
+
enabled:true,
247
+
label:'Close Tour',
248
+
attrs: {
249
+
'data-test':'close-tour-button',
250
+
'data-analytics-id':'tour-close'
251
+
}
252
+
}
253
+
```
254
+
255
+
-`enabled` Should a cancel "✕" be shown in the header of the step?
210
256
-`label` The label to add for `aria-label`
257
+
211
258
-`classes`: A string of extra classes to add to the step's content element.
212
-
-`buttons`: An array of buttons to add to the step. These will be rendered in a footer below the main body text. Each button in the array is an object of the format:
213
-
-`label`: The label to add for `aria-label`. It can also be a function that returns a string (useful with i18n solutions).
214
-
-`disabled`: A boolean that controls the `disabled` attribute. It can also be a function that returns a boolean.
259
+
-`buttons`: An array of buttons to add to the step. These will be rendered in a
260
+
footer below the main body text. Each button in the array is an object of the
261
+
format:
262
+
-`attrs`: Additional HTML attributes to apply to the button element. Useful
263
+
for adding data attributes for testing or analytics.
264
+
-`label`: The label to add for `aria-label`. It can also be a function that
265
+
returns a string (useful with i18n solutions).
266
+
-`disabled`: A boolean that controls the `disabled` attribute. It can also be
267
+
a function that returns a boolean.
215
268
-`classes`: Extra classes to apply to the `<a>`
216
-
-`secondary`: A boolean, that when true, adds a `shepherd-button-secondary` class to the button
217
-
-`text`: The HTML text of the button. It can also be a function that returns a string (useful with i18n solutions).
218
-
-`action`: A function executed when the button is clicked on.
219
-
It is automatically bound to the `tour` the step is associated with, so things like `this.next` will
220
-
work inside the action. You can use action to skip steps or navigate to specific steps, with something like:
269
+
-`secondary`: A boolean, that when true, adds a `shepherd-button-secondary`
270
+
class to the button
271
+
-`text`: The HTML text of the button. It can also be a function that returns
272
+
a string (useful with i18n solutions).
273
+
-`action`: A function executed when the button is clicked on. It is
274
+
automatically bound to the `tour` the step is associated with, so things
275
+
like `this.next` will work inside the action. You can use action to skip
276
+
steps or navigate to specific steps, with something like:
221
277
```javascript
222
278
action() {
223
279
returnthis.show('some_step_name');
224
280
}
225
281
```
226
-
-`extraHighlights`: An array of extra element selectors to highlight when the overlay is shown The tooltip won’t be fixed to these elements, but they will be highlighted just like the attachTo element.
227
-
-`advanceOn`: An action on the page which should advance shepherd to the next step. It should be an object with a string `selector` and an `event` name.
228
-
For example: `{selector: '.some-element', event: 'click'}`. It doesn't have to be an event inside the tour, it can be any event fired on any element on the page.
229
-
You can also always manually advance the Tour by calling `myTour.next()`.
230
-
-`highlightClass`: An extra class to apply to the `attachTo` element when it is highlighted (that is, when its step is active). You can then target that selector in your CSS.
231
-
-`id`: The string to use as the `id` for the step. If an id is not passed one will be generated.
232
-
-`modalOverlayOpeningPadding`: An amount of padding to add around the modal overlay opening
233
-
-`modalOverlayOpeningRadius`: An amount of border radius to add around the modal overlay opening. It can be either a number or an object with properties `{ topLeft, bottomLeft, bottomRight, topRight }`
234
-
-`floatingUIOptions`: Extra options to pass to [Floating UI](https://floating-ui.com/docs/getting-started)
235
-
-`showOn`: A function that, when it returns true, will show the step. If it returns false, the step will be skipped.
236
-
-`scrollTo`: Should the element be scrolled to when this step is shown? If true, uses the default `scrollIntoView`, if an object, passes that object as the params to `scrollIntoView` i.e. `{behavior: 'smooth', block: 'center'}`
237
-
-`scrollToHandler`: A function that lets you override the default `scrollTo` behavior and define a custom action to do the scrolling,
238
-
and possibly other logic.
282
+
-`extraHighlights`: An array of extra element selectors to highlight when the
283
+
overlay is shown The tooltip won’t be fixed to these elements, but they will
284
+
be highlighted just like the attachTo element.
285
+
-`advanceOn`: An action on the page which should advance shepherd to the next
286
+
step. It should be an object with a string `selector` and an `event` name. For
287
+
example: `{selector: '.some-element', event: 'click'}`. It doesn't have to be
288
+
an event inside the tour, it can be any event fired on any element on the
289
+
page. You can also always manually advance the Tour by calling
290
+
`myTour.next()`.
291
+
-`highlightClass`: An extra class to apply to the `attachTo` element when it is
292
+
highlighted (that is, when its step is active). You can then target that
293
+
selector in your CSS.
294
+
-`id`: The string to use as the `id` for the step. If an id is not passed one
295
+
will be generated.
296
+
-`modalOverlayOpeningPadding`: An amount of padding to add around the modal
297
+
overlay opening
298
+
-`modalOverlayOpeningRadius`: An amount of border radius to add around the
299
+
modal overlay opening. It can be either a number or an object with properties
By default, Shepherd will generate and position an "arrow" element that points to the target
292
-
of a step. This is done by setting the `arrow` option to `true` on each ``Step.options` — but you can disable the arrow manually by setting it to false:
365
+
By default, Shepherd will generate and position an "arrow" element that points
366
+
to the target of a step. This is done by setting the `arrow` option to `true` on
367
+
each ``Step.options` — but you can disable the arrow manually by setting
368
+
it to false:
293
369
294
370
```js
295
371
myTour.addStep({
@@ -298,7 +374,9 @@ myTour.addStep({
298
374
});
299
375
```
300
376
301
-
You can also provide an options object, to configure the arrow's [padding](https://floating-ui.com/docs/arrow#padding). The padding is the closest the arrow will get to the edge of the step.
377
+
You can also provide an options object, to configure the arrow's
378
+
[padding](https://floating-ui.com/docs/arrow#padding). The padding is the
379
+
closest the arrow will get to the edge of the step.
302
380
303
381
```js
304
382
myTour.addStep({
@@ -307,5 +385,5 @@ myTour.addStep({
307
385
});
308
386
```
309
387
310
-
311
-
Furthermore, while Shepherd provides some basic arrow styling, you can style it as you wish by targeting the `.shepherd-arrow` element.
388
+
Furthermore, while Shepherd provides some basic arrow styling, you can style it
389
+
as you wish by targeting the `.shepherd-arrow` element.
0 commit comments