1- import { type FC , useState } from 'react' ;
1+ import { type FC , useRef , useState } from 'react' ;
22
33import { Button , Icon , Typography } from '@equinor/eds-core-react' ;
44import { chevron_down , chevron_up } from '@equinor/eds-icons' ;
55import { type FaqDto , FaqService } from '@equinor/subsurface-app-management' ;
6+ import { useLocation } from '@tanstack/react-router' ;
67
78import {
89 Container ,
@@ -24,10 +25,15 @@ export const Question: FC<FaqDto> = ({ id, question, createdDate, answer }) => {
2425 onImageRead : ( path ) => FaqService . getFaqImage ( path ) ,
2526 /* v8 ignore end */
2627 } ) ;
27- const [ expanded , setExpanded ] = useState ( false ) ;
28+ const { hash } = useLocation ( ) ;
29+ const initialExpanded = useRef ( hash === `faq-${ id } ` ) ;
30+ const [ expanded , setExpanded ] = useState ( initialExpanded . current ) ;
2831
2932 const handleOnToggleExpanded = ( ) => {
3033 setExpanded ( ( prev ) => ! prev ) ;
34+ if ( initialExpanded . current ) {
35+ initialExpanded . current = false ;
36+ }
3137 } ;
3238
3339 return (
@@ -56,7 +62,7 @@ export const Question: FC<FaqDto> = ({ id, question, createdDate, answer }) => {
5662 < AnimatePresence >
5763 { expanded && (
5864 < ExpandWrapper
59- initial = { { height : 0 } }
65+ initial = { { height : initialExpanded . current ? 'auto' : 0 } }
6066 exit = { { height : 0 } }
6167 animate = { { height : 'auto' } }
6268 >
0 commit comments