diff --git a/lib/Resizable/index.tsx b/lib/Resizable/index.tsx index a86c7de65..a228f9f2f 100644 --- a/lib/Resizable/index.tsx +++ b/lib/Resizable/index.tsx @@ -40,14 +40,14 @@ export function Resizable(props: PropsWithChildren) { initialWidth ); - const containerWidth = () => + const getContainerWidth = () => toPixels(props.containerWidth ?? document.body.offsetWidth); - const minWidth = () => - toPixels(props.minResizableWidth ?? 0, containerWidth()); + const getMinWidth = () => + toPixels(props.minResizableWidth ?? 0, getContainerWidth()); - const maxWidth = () => - toPixels(props.maxResizableWidth ?? "100%", containerWidth()); + const getMaxWidth = () => + toPixels(props.maxResizableWidth ?? "100%", getContainerWidth()); const getWrapperWidth = () => toPixels(resizeWrapperRef.current?.style.width ?? 0); @@ -56,7 +56,7 @@ export function Resizable(props: PropsWithChildren) { if (resizeWrapperRef.current === null) return; const newWidth = - keepValueWithinRange(value, minWidth(), maxWidth()) - gutterSize; + keepValueWithinRange(value, getMinWidth(), getMaxWidth()) - gutterSize; resizeWrapperRef.current.style.width = `${newWidth}px`; setLastPosition(newWidth); @@ -111,11 +111,18 @@ export function Resizable(props: PropsWithChildren) { useEffect(() => { doResize(rememberPosition ? lastPosition : initialWidth); - - // remember to remove global listeners on dismount + // remember to remove global listeners on unmounting return () => stopDrag(); }, []); + useEffect(() => { + const handeWindowResize = () => doResize(getWrapperWidth() + gutterSize); + window.addEventListener("resize", handeWindowResize); + return () => { + window.removeEventListener("resize", handeWindowResize); + }; + }, []); + return (