Skip to content

Commit

Permalink
Fixed height computation issue in Pane component
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmathew900 committed Jan 20, 2025
1 parent 9c08318 commit 2fa6009
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
22 changes: 14 additions & 8 deletions src/components/Pane/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import Button from "components/Button";
import { useOverlay, useOverlayManager } from "hooks";

import Body from "./Body";
import { DEFAULT_PANE_HEADER_HEIGHT } from "./constants";
import Footer from "./Footer";
import Header from "./Header";
import { getHeaderHeight } from "./utils";
import { getHeader, updateHeaderHeight } from "./utils";

const SIZES = { small: "small", large: "large" };

Expand All @@ -36,6 +35,7 @@ const Pane = ({

const paneWrapper = useRef(null);
const backdropRef = useRef(null);
const observerRef = useRef(null);

useOverlayManager(paneWrapper, isOpen);

Expand All @@ -52,14 +52,20 @@ const Pane = ({
});

useEffect(() => {
if (!hasTransitionCompleted) return;
const headerHeight = getHeaderHeight(paneWrapper);
if (headerHeight > DEFAULT_PANE_HEADER_HEIGHT) {
paneWrapper.current.style.setProperty(
"--neeto-ui-pane-header-height",
`${headerHeight}px`
if (!hasTransitionCompleted) return undefined;

const header = getHeader(paneWrapper);
if (!header) return undefined;

if (!observerRef.current) {
observerRef.current = new ResizeObserver(() =>
updateHeaderHeight(paneWrapper, header)
);
}

observerRef.current.observe(header);

return () => observerRef.current?.disconnect();
}, [hasTransitionCompleted]);

return (
Expand Down
16 changes: 13 additions & 3 deletions src/components/Pane/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { DEFAULT_PANE_HEADER_HEIGHT } from "./constants";

export const getHeaderHeight = paneWrapper => {
const header = paneWrapper.current.querySelector(".neeto-ui-pane__header");
export const getHeader = paneWrapper =>
paneWrapper.current.querySelector(".neeto-ui-pane__header");

return header ? header.offsetHeight : DEFAULT_PANE_HEADER_HEIGHT;
export const updateHeaderHeight = (paneWrapper, header) => {
const headerHeight = header.offsetHeight;

if (headerHeight > DEFAULT_PANE_HEADER_HEIGHT) {
paneWrapper.current.style.setProperty(
"--neeto-ui-pane-header-height",
`${headerHeight}px`
);
} else {
paneWrapper.current.style.removeProperty("--neeto-ui-pane-header-height");
}
};

0 comments on commit 2fa6009

Please sign in to comment.