Skip to content

Commit

Permalink
feat: Adds an optional maxHeight prop to FillHeightBox (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-zahedi authored Jan 31, 2024
1 parent e891a5f commit 27bed9f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-rats-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@autoguru/overdrive': minor
---

FillHeightBox gets optional maxHeight prop
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const FillHeightBox: FunctionComponent<Props> = ({
serverVhFallback,
observedElementRef,
style,
maxHeight,
...scrollPaneProps
}) => {
const containerRef = React.useRef<HTMLDivElement>(null);
Expand All @@ -24,6 +25,7 @@ export const FillHeightBox: FunctionComponent<Props> = ({
observedElementRef,
bottomGap,
serverVhFallback,
maxHeight,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface UseWindowHeightFillProps {
serverVhFallback?: number;
includeMobile?: boolean;
observeDomChanges?: boolean;
maxHeight?: number;
containerRef: RefObject<HTMLDivElement>;
observedElementRef?: RefObject<HTMLDivElement>;
}
Expand All @@ -20,6 +21,7 @@ export const useWindowHeightFill = ({
serverVhFallback = 100,
containerRef,
observedElementRef,
maxHeight,
}: UseWindowHeightFillProps): string => {
// Create an observer instance linked to the callback function
const cappedHeight = useResponsiveValue([includeMobile, , true]);
Expand All @@ -39,10 +41,12 @@ export const useWindowHeightFill = ({
themeClass,
themeContractVars.space[bottomGap],
) || '0px';
const availableHeight =
const availableHeight = Math.min(
maxHeight ?? Number.POSITIVE_INFINITY,
window.innerHeight -
// @ts-ignore
containerRef.current.getBoundingClientRect().top;
// @ts-ignore
containerRef.current.getBoundingClientRect().top,
);
const newHeight = gap
? `calc(${availableHeight}px - ${gap})`
: `${availableHeight}px`;
Expand Down Expand Up @@ -79,6 +83,7 @@ export const useWindowHeightFill = ({
document?.body,
themeClass,
bottomGap,
maxHeight,
]);

return cappedHeight ? containerHeight : 'auto';
Expand Down

0 comments on commit 27bed9f

Please sign in to comment.