@@ -79,11 +79,27 @@ export const VisualTour = ({
7979 const [ currentStepComponent , setCurrentStepComponent ] = React . useState < React . JSX . Element | null > ( null ) ;
8080
8181 React . useEffect ( ( ) => {
82+ const closeTour = ( ) => {
83+ // clear observer and disconnect
84+ if ( lastObserver ) {
85+ lastObserver . takeRecords ( ) ;
86+ lastObserver . disconnect ( ) ;
87+ }
88+ // empty step
89+ setCurrentStepComponent ( null ) ;
90+ // remove highleight classes
91+ document . querySelector ( `.${ highlightElementBaseClass } ` ) ?. classList . remove ( highlightElementBaseClass ) ;
92+ document
93+ . querySelector ( `.${ highlightElementBaseClass } --useable` )
94+ ?. classList . remove ( `${ highlightElementBaseClass } --useable` ) ;
95+ // call callback function from outside
96+ onClose ( ) ;
97+ } ;
98+
8299 const step = steps [ currentStepIndex ] ;
83100 if ( ! step ) {
84101 // This should not happen
85- setCurrentStepComponent ( null ) ;
86- onClose ( ) ;
102+ closeTour ( ) ;
87103 return ;
88104 }
89105 const highlightElementClass = (
@@ -102,7 +118,7 @@ export const VisualTour = ({
102118 { ` ${ currentStepIndex + 1 } /${ steps . length } ` }
103119 </ Badge >
104120 ) ;
105- const closeButton = < IconButton name = "navigation-close" text = { closeLabel } onClick = { onClose } /> ;
121+ const closeButton = < IconButton name = "navigation-close" text = { closeLabel } onClick = { closeTour } /> ;
106122 const titleOptions = (
107123 < >
108124 { stepDisplay }
@@ -126,7 +142,7 @@ export const VisualTour = ({
126142 < Button
127143 key = { "close" }
128144 text = { closeLabel }
129- onClick = { onClose }
145+ onClick = { closeTour }
130146 variant = "outlined"
131147 intent = { "primary" }
132148 rightIcon = { "navigation-close" }
@@ -159,7 +175,12 @@ export const VisualTour = ({
159175 ) ;
160176 } else {
161177 setCurrentStepComponent (
162- < StepModal titleOption = { titleOptions } actionButtons = { actionButtons } step = { step } onClose = { onClose } />
178+ < StepModal
179+ titleOption = { titleOptions }
180+ actionButtons = { actionButtons }
181+ step = { step }
182+ onClose = { closeTour }
183+ />
163184 ) ;
164185 }
165186 } ;
0 commit comments