@@ -23,37 +23,53 @@ const Waypoint = ({
23
23
scrollableParentRef,
24
24
} : WaypointProps ) => {
25
25
const waypointRef = useRef < HTMLDivElement > ( null ) ;
26
+ const menuRef = useRef < HTMLDivElement > ( null ) ;
26
27
27
- const isWaypointInView = useElementInView ( waypointRef , scrollableParentRef , {
28
- threshold : 1 ,
29
- rootMargin : `0px 0px ${ MANCHETTE_ACTIONS_HEIGHT } 0px` ,
30
- } ) ;
28
+ const isWaypointInView = useElementInView (
29
+ isActive ? waypointRef : undefined ,
30
+ scrollableParentRef ,
31
+ {
32
+ threshold : 1 ,
33
+ rootMargin : `0px 0px ${ MANCHETTE_ACTIONS_HEIGHT } 0px` ,
34
+ }
35
+ ) ;
36
+
37
+ const menuPositionTop = waypointRef . current
38
+ ? waypointRef . current ?. getBoundingClientRect ( ) . top + 25
39
+ : 0 ;
31
40
32
41
if ( ! display ) return null ;
33
42
34
43
return (
35
- < div
36
- className = { cx ( 'flex waypoint items-baseline' , {
37
- 'menu-active' : isActive ,
38
- } ) }
39
- id = { id }
40
- onClick = { ( ) => {
41
- if ( onClick ) onClick ( id ) ;
42
- } }
43
- >
44
- < div ref = { waypointRef } className = "waypoint-position justify-self-start text-end" >
45
- { positionMmToKm ( position ) }
46
- </ div >
44
+ < >
45
+ < div
46
+ className = { cx ( 'flex waypoint items-baseline' , {
47
+ 'menu-active' : isActive ,
48
+ } ) }
49
+ id = { id }
50
+ onClick = { ( ) => {
51
+ if ( onClick ) onClick ( id ) ;
52
+ } }
53
+ >
54
+ < div ref = { waypointRef } className = "waypoint-position justify-self-start text-end" >
55
+ { positionMmToKm ( position ) }
56
+ </ div >
47
57
48
- < div className = "waypoint-name mx-2 justify-self-start" > { name } </ div >
49
- < div className = "waypoint-separator" > </ div >
50
- < div className = "waypoint-ch font-mono justify-self-end" > { secondaryCode } </ div >
51
- < div className = "waypoint-separator" > </ div >
58
+ < div className = "waypoint-name mx-2 justify-self-start" > { name } </ div >
59
+ < div className = "waypoint-separator" > </ div >
60
+ < div className = "waypoint-ch font-mono justify-self-end" > { secondaryCode } </ div >
61
+ < div className = "waypoint-separator" > </ div >
52
62
53
- < div className = "waypoint-type" > </ div >
54
- < div className = "waypoint-separator" > </ div >
55
- { waypointMenu && isActive && isWaypointInView && waypointMenu }
56
- </ div >
63
+ < div className = "waypoint-type" > </ div >
64
+ < div className = "waypoint-separator" > </ div >
65
+ { waypointMenu && isActive && isWaypointInView && (
66
+ < div className = "menu-wrapper" ref = { menuRef } style = { { top : menuPositionTop } } >
67
+ { waypointMenu }
68
+ </ div >
69
+ ) }
70
+ </ div >
71
+ < div className = "last-separator" > </ div >
72
+ </ >
57
73
) ;
58
74
} ;
59
75
0 commit comments