Skip to content

Commit 27bed9f

Browse files
authored
feat: Adds an optional maxHeight prop to FillHeightBox (#968)
1 parent e891a5f commit 27bed9f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

.changeset/light-rats-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@autoguru/overdrive': minor
3+
---
4+
5+
FillHeightBox gets optional maxHeight prop

packages/overdrive/lib/components/FillHeightBox/FillHeightBox.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const FillHeightBox: FunctionComponent<Props> = ({
1515
serverVhFallback,
1616
observedElementRef,
1717
style,
18+
maxHeight,
1819
...scrollPaneProps
1920
}) => {
2021
const containerRef = React.useRef<HTMLDivElement>(null);
@@ -24,6 +25,7 @@ export const FillHeightBox: FunctionComponent<Props> = ({
2425
observedElementRef,
2526
bottomGap,
2627
serverVhFallback,
28+
maxHeight,
2729
});
2830

2931
return (

packages/overdrive/lib/hooks/useWindowHeightFill/useWindowHeightFill.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface UseWindowHeightFillProps {
1010
serverVhFallback?: number;
1111
includeMobile?: boolean;
1212
observeDomChanges?: boolean;
13+
maxHeight?: number;
1314
containerRef: RefObject<HTMLDivElement>;
1415
observedElementRef?: RefObject<HTMLDivElement>;
1516
}
@@ -20,6 +21,7 @@ export const useWindowHeightFill = ({
2021
serverVhFallback = 100,
2122
containerRef,
2223
observedElementRef,
24+
maxHeight,
2325
}: UseWindowHeightFillProps): string => {
2426
// Create an observer instance linked to the callback function
2527
const cappedHeight = useResponsiveValue([includeMobile, , true]);
@@ -39,10 +41,12 @@ export const useWindowHeightFill = ({
3941
themeClass,
4042
themeContractVars.space[bottomGap],
4143
) || '0px';
42-
const availableHeight =
44+
const availableHeight = Math.min(
45+
maxHeight ?? Number.POSITIVE_INFINITY,
4346
window.innerHeight -
44-
// @ts-ignore
45-
containerRef.current.getBoundingClientRect().top;
47+
// @ts-ignore
48+
containerRef.current.getBoundingClientRect().top,
49+
);
4650
const newHeight = gap
4751
? `calc(${availableHeight}px - ${gap})`
4852
: `${availableHeight}px`;
@@ -79,6 +83,7 @@ export const useWindowHeightFill = ({
7983
document?.body,
8084
themeClass,
8185
bottomGap,
86+
maxHeight,
8287
]);
8388

8489
return cappedHeight ? containerHeight : 'auto';

0 commit comments

Comments
 (0)