@@ -26,34 +26,33 @@ const ScenarioDescription = ({
26
26
const { t } = useTranslation ( 'operationalStudies/scenario' ) ;
27
27
const { openModal } = useModal ( ) ;
28
28
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 ) ;
31
31
const [ isTooLongDescription , setIsTooLongDescription ] = useState < boolean > ( false ) ;
32
32
33
33
const toggleDescription = ( ) => {
34
34
setIsOpenedDescription ( ! isOpenedDescription ) ;
35
35
} ;
36
36
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
+ ) ;
43
42
} ;
44
43
45
- useOutsideClick ( descriptionRef , ( ) => setIsOpenedDescription ( false ) ) ;
44
+ useOutsideClick ( expandedDescriptionRef , ( ) => setIsOpenedDescription ( false ) ) ;
46
45
47
46
useEffect ( ( ) => {
48
- checkIfTooLong ( ) ;
49
- window . addEventListener ( 'resize' , checkIfTooLong ) ;
47
+ checkIfDescriptionIsTooLong ( ) ;
48
+ window . addEventListener ( 'resize' , checkIfDescriptionIsTooLong ) ;
50
49
51
50
return ( ) => {
52
- window . removeEventListener ( 'resize' , checkIfTooLong ) ;
51
+ window . removeEventListener ( 'resize' , checkIfDescriptionIsTooLong ) ;
53
52
} ;
54
53
} , [ ] ) ;
55
54
56
- useEffect ( checkIfTooLong , [ scenario . description ] ) ;
55
+ useEffect ( checkIfDescriptionIsTooLong , [ scenario . description ] ) ;
57
56
58
57
return (
59
58
< div >
@@ -64,7 +63,7 @@ const ScenarioDescription = ({
64
63
</ div >
65
64
< div className = "scenario-description" >
66
65
{ scenario . description && (
67
- < div ref = { ref } className = "scenario-details-description not-opened" >
66
+ < div ref = { collapsedDescriptionRef } className = "scenario-details-description not-opened" >
68
67
{ scenario . description }
69
68
{ isTooLongDescription && (
70
69
< span role = "button" onClick = { toggleDescription } tabIndex = { 0 } >
@@ -74,7 +73,7 @@ const ScenarioDescription = ({
74
73
</ div >
75
74
) }
76
75
{ isOpenedDescription && (
77
- < div ref = { descriptionRef } className = "scenario-details-description opened" >
76
+ < div ref = { expandedDescriptionRef } className = "scenario-details-description opened" >
78
77
{ scenario . description }
79
78
< span
80
79
onClick = { toggleDescription }
0 commit comments