Skip to content

Commit dd537cc

Browse files
committed
fix menu overflow
1 parent 99efc58 commit dd537cc

File tree

7 files changed

+55
-35
lines changed

7 files changed

+55
-35
lines changed

ui-manchette-with-spacetimechart/src/stories/base.stories.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useRef } from 'react';
22

3-
import Manchette from '@osrd-project/ui-manchette';
4-
import type { ProjectPathTrainResult, Waypoint } from '@osrd-project/ui-manchette/dist/types';
3+
import Manchette, { type ProjectPathTrainResult, type Waypoint } from '@osrd-project/ui-manchette';
54
import { PathLayer, SpaceTimeChart } from '@osrd-project/ui-spacetimechart';
65
import type { Meta } from '@storybook/react';
76

ui-manchette-with-spacetimechart/src/styles/menu.css

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
.menu {
2-
position: absolute;
3-
z-index: 12;
42
@apply bg-grey-5;
53
width: 305px;
6-
top: 30px;
7-
left: 0;
84
border: 0.0625rem solid #b6b2af;
95
border-radius: 0.5rem;
106
box-shadow:

ui-manchette/src/components/Waypoint.tsx

+40-24
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,53 @@ const Waypoint = ({
2323
scrollableParentRef,
2424
}: WaypointProps) => {
2525
const waypointRef = useRef<HTMLDivElement>(null);
26+
const menuRef = useRef<HTMLDivElement>(null);
2627

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;
3140

3241
if (!display) return null;
3342

3443
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>
4757

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>
5262

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+
</>
5773
);
5874
};
5975

ui-manchette/src/components/WaypointList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const WaypointList = ({ waypoints, waypointMenuData }: WaypointListProps) => (
1313
{waypoints.map((waypoint) => (
1414
<div
1515
key={waypoint.id}
16-
className="waypoint-wrapper flex flex-col justify-start"
16+
className="waypoint-wrapper flex justify-start"
1717
style={waypoint.styles}
1818
>
1919
<Waypoint

ui-manchette/src/hooks/useElementInView.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const useElementInView = <T extends HTMLElement>(
3939
}
4040
);
4141

42-
observer.observe(currentRef.parentElement!);
42+
observer.observe(currentRef);
4343

4444
return () => observer.disconnect();
4545
}, [ref, containerRef, options]);

ui-manchette/src/styles/waypoint-list.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.waypoint-list {
22
width: 349px;
33
border-bottom-left-radius: 0.25rem;
4-
padding-inline: 0.5rem 1.625rem;
4+
padding-left: 0.5rem;
55

66
@apply bg-white-100;
77

ui-manchette/src/styles/waypoint.css

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
line-height: 1.5rem;
55
padding-block: 3px 5px;
66
width: 315px;
7-
position: relative;
87
&-separator {
98
position: relative;
109
opacity: 0.6;
@@ -81,12 +80,22 @@
8180
}
8281
}
8382

83+
.menu-wrapper {
84+
position: absolute;
85+
z-index: 12;
86+
}
87+
}
88+
89+
.last-separator {
90+
width: 26px;
91+
height: 2rem;
92+
93+
position: relative;
8494
&::after {
8595
content: '';
8696
position: absolute;
8797
display: inline-block;
8898
bottom: 16px;
89-
right: -1.625rem;
9099
width: 1.625rem;
91100
height: 0.5px;
92101
opacity: 0.6;

0 commit comments

Comments
 (0)