@@ -6,27 +6,31 @@ import { getTestId } from "../../tests/test-ids-utils";
6
6
import { ComponentDefaultTestId } from "../../tests/constants" ;
7
7
import styles from "./TransitionView.module.scss" ;
8
8
import SlideTransition from "../SlideTransition/SlideTransition" ;
9
+ import useMergeRef from "../../hooks/useMergeRef" ;
9
10
10
11
const TransitionView = forwardRef (
11
12
(
12
13
{ activeStep, direction, height, id, className, "data-testid" : dataTestId , children } : TransitionViewProps ,
13
14
ref : React . ForwardedRef < HTMLDivElement >
14
15
) => {
16
+ const componentRef = useRef < HTMLDivElement > ( null ) ;
17
+ const mergedRef = useMergeRef ( ref , componentRef ) ;
15
18
const slideTransitionRef = useRef < HTMLDivElement > ( null ) ;
16
- const [ contentHeight , setContentHeight ] = useState < number > ( height ) ;
17
- const slideTransitionHeight = height || contentHeight > 0 ? "100%" : "auto" ;
19
+ const [ contentHeight , setContentHeight ] = useState < number | "100%" > ( height ) ;
20
+ const slideTransitionHeight = height || contentHeight === "100%" || contentHeight > 0 ? "100%" : "auto" ;
18
21
19
22
useEffect ( ( ) => {
20
23
if ( ! slideTransitionRef . current ) return ;
21
- setContentHeight ( slideTransitionRef . current . scrollHeight ) ;
24
+ // if parent has definite height, stretch component to fill it, otherwise use content height
25
+ setContentHeight ( componentRef . current . clientHeight > 0 ? "100%" : slideTransitionRef . current . scrollHeight ) ;
22
26
} , [ height , slideTransitionRef ] ) ;
23
27
24
28
return (
25
29
< div
26
30
id = { id }
27
31
className = { cx ( styles . slideshow , className ) }
28
32
data-testid = { dataTestId || getTestId ( ComponentDefaultTestId . TRANSITION_VIEW , id ) }
29
- ref = { ref }
33
+ ref = { mergedRef }
30
34
style = { { height : height ?? contentHeight } }
31
35
>
32
36
< AnimatePresence initial = { false } custom = { direction } >
0 commit comments