From 9bcc82e11e9fd1a7c9717217da247800c0f4e3a5 Mon Sep 17 00:00:00 2001 From: Yossi Saadi Date: Wed, 13 Nov 2024 15:00:04 +0200 Subject: [PATCH] refactor(TransitionView): separate to variable --- .../src/components/TransitionView/TransitionView.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/src/components/TransitionView/TransitionView.tsx b/packages/core/src/components/TransitionView/TransitionView.tsx index 2594f08571..e67a525603 100644 --- a/packages/core/src/components/TransitionView/TransitionView.tsx +++ b/packages/core/src/components/TransitionView/TransitionView.tsx @@ -13,11 +13,12 @@ const TransitionView = forwardRef( ref: React.ForwardedRef ) => { const slideTransitionRef = useRef(null); - const [slideHeight, setSlideHeight] = useState(height); + const [contentHeight, setContentHeight] = useState(height); + const slideTransitionHeight = height || contentHeight > 0 ? "100%" : "auto" useEffect(() => { if (!slideTransitionRef.current) return; - setSlideHeight(slideTransitionRef.current.scrollHeight); + setContentHeight(slideTransitionRef.current.scrollHeight); }, [height, slideTransitionRef]); return ( @@ -26,14 +27,14 @@ const TransitionView = forwardRef( className={cx(styles.slideshow, className)} data-testid={dataTestId || getTestId(ComponentDefaultTestId.TRANSITION_VIEW, id)} ref={ref} - style={{ height: height ?? slideHeight }} + style={{ height: height ?? contentHeight }} > 0 ? "100%" : "auto" }} + // it must be "auto" on initial load to consider scrollable content in contentHeight calculation + style={{ height: slideTransitionHeight }} ref={slideTransitionRef} > {children[activeStep]}