Skip to content

Commit f7b0861

Browse files
committed
fixup! front: Change display when description is too long
1 parent 6c7e493 commit f7b0861

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

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

+35-10
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,63 @@ const ScenarioDescription = ({
2626
const { t } = useTranslation('operationalStudies/scenario');
2727
const { openModal } = useModal();
2828
const [isOpenedDescription, setIsOpenedDescription] = useState<boolean>(false);
29-
const ref = useRef<HTMLInputElement | null>(null);
3029
const descriptionRef = useRef<HTMLDivElement | null>(null);
30+
const ref = useRef<HTMLDivElement | null>(null);
31+
const [isTooLongDescription, setIsTooLongDescription] = useState<boolean>(false);
3132

3233
const toggleDescription = () => {
3334
setIsOpenedDescription(!isOpenedDescription);
3435
};
3536

37+
const checkIfTooLong = () => {
38+
if (ref && ref.current) {
39+
ref.current.scrollHeight > 60
40+
? setIsTooLongDescription(true)
41+
: setIsTooLongDescription(false);
42+
}
43+
};
44+
3645
useOutsideClick(descriptionRef, () => setIsOpenedDescription(false));
3746

47+
useEffect(() => {
48+
checkIfTooLong();
49+
window.addEventListener('resize', checkIfTooLong);
50+
51+
return () => {
52+
window.removeEventListener('resize', checkIfTooLong);
53+
};
54+
}, []);
55+
56+
useEffect(checkIfTooLong, [scenario.description]);
57+
3858
return (
39-
<div ref={ref}>
59+
<div>
4060
<div className="scenario-details-name">
4161
<span className="flex-grow-1 scenario-name text-truncate" title={scenario.name}>
4262
{scenario.name}
4363
</span>
4464
</div>
45-
4665
<div className="scenario-description">
4766
{scenario.description && (
48-
<div
49-
ref={descriptionRef}
50-
title={isOpenedDescription ? '' : scenario.description}
51-
className={`scenario-details-description ${isOpenedDescription ? 'opened' : 'not-opened'}`}
52-
>
67+
<div ref={ref} className="scenario-details-description not-opened">
68+
{scenario.description}
69+
{isTooLongDescription && (
70+
<span role="button" onClick={toggleDescription} tabIndex={0}>
71+
(plus)
72+
</span>
73+
)}
74+
</div>
75+
)}
76+
{isOpenedDescription && (
77+
<div ref={descriptionRef} className="scenario-details-description opened">
5378
{scenario.description}
5479
<span
5580
onClick={toggleDescription}
5681
role="button"
5782
tabIndex={0}
58-
className={isOpenedDescription ? 'displayed-description' : 'display-description'}
83+
className="displayed-description"
5984
>
60-
{isOpenedDescription ? <X /> : '(plus)'}
85+
<X />
6186
</span>
6287
</div>
6388
)}

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
position: relative;
144144

145145
.scenario-details-description {
146+
position: relative;
146147
color: var(--grey50);
147148
font-size: 0.875rem;
148149
font-weight: 400;
@@ -154,21 +155,21 @@
154155
.not-opened {
155156
position: relative;
156157
overflow: hidden;
157-
display: -webkit-box;
158-
-webkit-line-clamp: 3;
159-
-webkit-box-orient: vertical;
160-
.display-description {
158+
max-height: 3.75rem;
159+
max-width: 100%;
160+
span {
161+
padding-inline: 0.2188rem;
161162
position: absolute;
162163
bottom: 0;
163164
right: 0;
164165
background: rgba(222, 221, 214, 1);
165166
color: var(--grey80);
166-
padding-inline: 0.2188rem;
167167
}
168168
}
169169

170170
.opened {
171171
position: absolute;
172+
top: 0;
172173
background-color: var(--white100);
173174
color: var(--grey80);
174175
padding: 3.375rem 3.5rem 3.125rem 3.5rem;

0 commit comments

Comments
 (0)