File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { style } from "../../../util/style" ;
2
2
import dom , { State } from "../../dom" ;
3
3
import { helperLayerClassName } from "../classNames" ;
4
- import { setPositionRelativeToStep } from "../position" ;
4
+ import { waitAndSetPositionRelativeToStep } from "../position" ;
5
5
import { TourStep } from "../steps" ;
6
6
7
7
const { div } = dom . tags ;
@@ -64,7 +64,8 @@ export const HelperLayer = ({
64
64
// set the new position if the step or refreshes change
65
65
if ( ! step . val || refreshes . val === undefined ) return ;
66
66
67
- setPositionRelativeToStep (
67
+
68
+ waitAndSetPositionRelativeToStep (
68
69
targetElement ,
69
70
helperLayer ,
70
71
step . val ,
Original file line number Diff line number Diff line change @@ -18,3 +18,37 @@ export const setPositionRelativeToStep = (
18
18
step . position === "floating" ? 0 : padding
19
19
) ;
20
20
} ;
21
+
22
+ /**
23
+ * Waits for the target element to be visible in viewport, then sets tooltip position.
24
+ */
25
+ export const waitAndSetPositionRelativeToStep = (
26
+ relativeElement : HTMLElement ,
27
+ tooltipLayer : HTMLElement ,
28
+ step : TourStep ,
29
+ padding : number
30
+ ) => {
31
+ const target = step . element as HTMLElement ;
32
+
33
+ const observer = new IntersectionObserver (
34
+ ( entries ) => {
35
+ const entry = entries [ 0 ] ;
36
+
37
+ if ( entry . isIntersecting ) {
38
+ observer . disconnect ( ) ;
39
+
40
+ setPositionRelativeToStep (
41
+ relativeElement ,
42
+ tooltipLayer ,
43
+ step ,
44
+ padding
45
+ ) ;
46
+ }
47
+ } ,
48
+ {
49
+ threshold : 0.1 ,
50
+ }
51
+ ) ;
52
+
53
+ observer . observe ( target ) ;
54
+ } ;
You can’t perform that action at this time.
0 commit comments