Skip to content

Commit da5e3b3

Browse files
authored
feat(TransitionView): fill parent if parent has definite height (#2629)
1 parent 638b19f commit da5e3b3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/core/src/components/TransitionView/TransitionView.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,31 @@ import { getTestId } from "../../tests/test-ids-utils";
66
import { ComponentDefaultTestId } from "../../tests/constants";
77
import styles from "./TransitionView.module.scss";
88
import SlideTransition from "../SlideTransition/SlideTransition";
9+
import useMergeRef from "../../hooks/useMergeRef";
910

1011
const TransitionView = forwardRef(
1112
(
1213
{ activeStep, direction, height, id, className, "data-testid": dataTestId, children }: TransitionViewProps,
1314
ref: React.ForwardedRef<HTMLDivElement>
1415
) => {
16+
const componentRef = useRef<HTMLDivElement>(null);
17+
const mergedRef = useMergeRef(ref, componentRef);
1518
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";
1821

1922
useEffect(() => {
2023
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);
2226
}, [height, slideTransitionRef]);
2327

2428
return (
2529
<div
2630
id={id}
2731
className={cx(styles.slideshow, className)}
2832
data-testid={dataTestId || getTestId(ComponentDefaultTestId.TRANSITION_VIEW, id)}
29-
ref={ref}
33+
ref={mergedRef}
3034
style={{ height: height ?? contentHeight }}
3135
>
3236
<AnimatePresence initial={false} custom={direction}>

0 commit comments

Comments
 (0)