Skip to content

Commit a8cfaac

Browse files
committed
fixup! front: Change display when description is too long
1 parent 209217e commit a8cfaac

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

front/src/applications/operationalStudies/components/Scenario/ScenarioDescription.tsx

+14-15
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,33 @@ const ScenarioDescription = ({
2626
const { t } = useTranslation('operationalStudies/scenario');
2727
const { openModal } = useModal();
2828
const [isOpenedDescription, setIsOpenedDescription] = useState<boolean>(false);
29-
const descriptionRef = useRef<HTMLDivElement | null>(null);
30-
const ref = useRef<HTMLDivElement | null>(null);
29+
const expandedDescriptionRef = useRef<HTMLDivElement | null>(null);
30+
const collapsedDescriptionRef = useRef<HTMLDivElement | null>(null);
3131
const [isTooLongDescription, setIsTooLongDescription] = useState<boolean>(false);
3232

3333
const toggleDescription = () => {
3434
setIsOpenedDescription(!isOpenedDescription);
3535
};
3636

37-
const checkIfTooLong = () => {
38-
if (ref && ref.current) {
39-
ref.current.scrollHeight > 60
40-
? setIsTooLongDescription(true)
41-
: setIsTooLongDescription(false);
42-
}
37+
const checkIfDescriptionIsTooLong = () => {
38+
if (collapsedDescriptionRef.current)
39+
setIsTooLongDescription(
40+
collapsedDescriptionRef.current.scrollHeight > collapsedDescriptionRef.current.clientHeight
41+
);
4342
};
4443

45-
useOutsideClick(descriptionRef, () => setIsOpenedDescription(false));
44+
useOutsideClick(expandedDescriptionRef, () => setIsOpenedDescription(false));
4645

4746
useEffect(() => {
48-
checkIfTooLong();
49-
window.addEventListener('resize', checkIfTooLong);
47+
checkIfDescriptionIsTooLong();
48+
window.addEventListener('resize', checkIfDescriptionIsTooLong);
5049

5150
return () => {
52-
window.removeEventListener('resize', checkIfTooLong);
51+
window.removeEventListener('resize', checkIfDescriptionIsTooLong);
5352
};
5453
}, []);
5554

56-
useEffect(checkIfTooLong, [scenario.description]);
55+
useEffect(checkIfDescriptionIsTooLong, [scenario.description]);
5756

5857
return (
5958
<div>
@@ -64,7 +63,7 @@ const ScenarioDescription = ({
6463
</div>
6564
<div className="scenario-description">
6665
{scenario.description && (
67-
<div ref={ref} className="scenario-details-description not-opened">
66+
<div ref={collapsedDescriptionRef} className="scenario-details-description not-opened">
6867
{scenario.description}
6968
{isTooLongDescription && (
7069
<span role="button" onClick={toggleDescription} tabIndex={0}>
@@ -74,7 +73,7 @@ const ScenarioDescription = ({
7473
</div>
7574
)}
7675
{isOpenedDescription && (
77-
<div ref={descriptionRef} className="scenario-details-description opened">
76+
<div ref={expandedDescriptionRef} className="scenario-details-description opened">
7877
{scenario.description}
7978
<span
8079
onClick={toggleDescription}

front/src/styles/scss/applications/operationalStudies/_scenario.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@
153153
}
154154

155155
.not-opened {
156-
position: relative;
157156
overflow: hidden;
158157
max-height: 3.75rem;
159158
max-width: 100%;
@@ -170,6 +169,7 @@
170169
.opened {
171170
position: absolute;
172171
top: 0;
172+
left: -0.5rem;
173173
background-color: var(--white100);
174174
color: var(--grey80);
175175
padding: 3.375rem 3.5rem 3.125rem 3.5rem;
@@ -182,7 +182,6 @@
182182
0rem 0.375rem 1.3125rem -0.3125rem rgba(255, 171, 88, 0.31),
183183
0rem 1rem 1.875rem -0.3125rem rgba(0, 0, 0, 0.19),
184184
0rem 0.1875rem 0.3125rem -0.125rem rgba(0, 0, 0, 0.16);
185-
transform: translateX(-0.5rem);
186185
width: calc(100% + 7.5rem);
187186
.displayed-description {
188187
position: absolute;

0 commit comments

Comments
 (0)