kamrify commited on
Commit
7a8ce7c
·
1 Parent(s): 342d4d9

Add async tour example

Browse files
docs/src/content/guides/async-tour.mdx CHANGED
@@ -23,16 +23,16 @@ You can also have async steps in your tour. This is useful when you want to load
23
  element: '.line:nth-child(14)',
24
  popover: {
25
  title: 'Manually Handle Next',
26
- description: 'Here we are moving to the next step manually since driver.js does not know when the data is loaded from the server.',
27
  }
28
  },
29
  {
30
  popover: {
31
  title: 'Next Step is Async',
32
- description: 'This is the first step. Next element will be loaded from the server.',
33
  },
34
  },
35
- { element: '.dynamic-el', popover: { title: 'Async Element', description: 'This element is loaded from the server and will be removed as soon as we move away from this step' } },
36
  { popover: { title: 'Last Step', description: 'This is the last step.' } }
37
  ]}
38
  id={"tour-example"}
@@ -47,15 +47,30 @@ You can also have async steps in your tour. This is useful when you want to load
47
  {
48
  popover: {
49
  title: 'First Step',
50
- description: 'This is the first step. Next element will be loaded from the server.'
 
 
 
51
  onNextClick: () => {
52
- // .. load element from server
53
  // .. and then call
54
  driverObj.moveNext();
55
  },
56
  },
57
  },
58
- { element: '.dynamic-el', popover: { title: 'Async Element', description: 'This element is loaded from the server.' } },
 
 
 
 
 
 
 
 
 
 
 
 
59
  { popover: { title: 'Last Step', description: 'This is the last step.' } }
60
  ]
61
 
@@ -65,3 +80,9 @@ driver.drive();
65
 
66
  ```
67
  </CodeSample>
 
 
 
 
 
 
 
23
  element: '.line:nth-child(14)',
24
  popover: {
25
  title: 'Manually Handle Next',
26
+ description: 'Here we are moving to the next step manually since driver.js does not know when the data is loaded dynamically.',
27
  }
28
  },
29
  {
30
  popover: {
31
  title: 'Next Step is Async',
32
+ description: 'This is the first step. Next element will be loaded dynamically.',
33
  },
34
  },
35
+ { element: '.dynamic-el', popover: { title: 'Async Element', description: 'This element is loaded dynamically and will be removed as soon as we move away from this step' } },
36
  { popover: { title: 'Last Step', description: 'This is the last step.' } }
37
  ]}
38
  id={"tour-example"}
 
47
  {
48
  popover: {
49
  title: 'First Step',
50
+ description: 'This is the first step. Next element will be loaded dynamically.'
51
+ // By passing onNextClick, you can override the default behavior of the next button.
52
+ // This will prevent the driver from moving to the next step automatically.
53
+ // You can then manually call driverObj.moveNext() to move to the next step.
54
  onNextClick: () => {
55
+ // .. load element dynamically
56
  // .. and then call
57
  driverObj.moveNext();
58
  },
59
  },
60
  },
61
+ {
62
+ element: '.dynamic-el',
63
+ popover: {
64
+ title: 'Async Element',
65
+ description: 'This element is loaded dynamically.'
66
+ },
67
+ // onDeselected is called when the element is deselected.
68
+ // Here we are simply removing the element from the DOM.
69
+ onDeselected: () => {
70
+ // .. remove element
71
+ document.querySelector(".dynamic-el")?.remove();
72
+ }
73
+ },
74
  { popover: { title: 'Last Step', description: 'This is the last step.' } }
75
  ]
76
 
 
80
 
81
  ```
82
  </CodeSample>
83
+
84
+ > **Note**: By overriding `onNextClick`, and `onPrevClick` hooks you control the navigation of the driver. This means that user won't be able to navigate using the buttons and you will have to either call `driverObj.moveNext()` or `driverObj.movePrevious()` to navigate to the next/previous step.
85
+ >
86
+ > You can use this to implement custom logic for navigating between steps. This is also useful when you are dealing with dynamic content and want to highlight the next/previous element based on some logic.
87
+ >
88
+ > `onNextClick` and `onPrevClick` hooks can be configured at driver level as well as step level. When configured at the driver level, you control the navigation for all the steps. When configured at the step level, you control the navigation for that particular step only.