- Fix bug where in vertical Mode, the lanes would be as large as the largest lane.
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -1,40 +1,56 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const heightMap = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Height Memory Wrapper
|
* Height Memory Wrapper
|
||||||
* @param children
|
* @param children
|
||||||
* @param maxHeight
|
* @param maxHeight
|
||||||
* @param setMaxHeight
|
* @param setMaxHeight
|
||||||
* @param override - Override the minHeight style from being set
|
* @param override - Override the minHeight style from being set
|
||||||
|
* @param key - Unique key to preserve height for items with the same key
|
||||||
* @returns {Element}
|
* @returns {Element}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
const HeightMemoryWrapper = ({ children, maxHeight, setMaxHeight, override }) => {
|
const HeightMemoryWrapper = ({ children, maxHeight, setMaxHeight, override, itemKey }) => {
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
|
const [localMaxHeight, setLocalMaxHeight] = useState(maxHeight);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const currentRef = ref.current; // Step 1: Capture the current ref value
|
const currentRef = ref.current; // Step 1: Capture the current ref value
|
||||||
const updateHeight = () => {
|
const updateHeight = () => {
|
||||||
const currentHeight = currentRef?.firstChild?.clientHeight || 0;
|
const currentHeight = currentRef?.firstChild?.clientHeight || 0;
|
||||||
|
if (itemKey) {
|
||||||
|
const keyHeight = heightMap.get(itemKey) || 0;
|
||||||
|
const newHeight = Math.max(keyHeight, currentHeight);
|
||||||
|
heightMap.set(itemKey, newHeight);
|
||||||
|
setLocalMaxHeight(newHeight);
|
||||||
|
} else {
|
||||||
|
setLocalMaxHeight((prevHeight) => Math.max(prevHeight, currentHeight));
|
||||||
|
}
|
||||||
setMaxHeight((prevHeight) => Math.max(prevHeight, currentHeight));
|
setMaxHeight((prevHeight) => Math.max(prevHeight, currentHeight));
|
||||||
};
|
};
|
||||||
|
|
||||||
const resizeObserver = new ResizeObserver(updateHeight);
|
const resizeObserver = new ResizeObserver(updateHeight);
|
||||||
if (currentRef?.firstChild) {
|
if (currentRef?.firstChild) {
|
||||||
// Step 2: Use the captured ref for observing
|
|
||||||
resizeObserver.observe(currentRef.firstChild);
|
resizeObserver.observe(currentRef.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (currentRef?.firstChild) {
|
if (currentRef?.firstChild) {
|
||||||
// Step 2: Use the captured ref for observing
|
|
||||||
resizeObserver.unobserve(currentRef.firstChild);
|
resizeObserver.unobserve(currentRef.firstChild);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [setMaxHeight]);
|
}, [itemKey, setMaxHeight]);
|
||||||
|
|
||||||
const style = override ? {} : { minHeight: maxHeight };
|
useEffect(() => {
|
||||||
|
if (itemKey && heightMap.has(itemKey)) {
|
||||||
|
setLocalMaxHeight(heightMap.get(itemKey));
|
||||||
|
}
|
||||||
|
}, [itemKey]);
|
||||||
|
|
||||||
|
const style = override ? {} : { minHeight: localMaxHeight };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ref} style={style}>
|
<div ref={ref} style={style}>
|
||||||
@@ -47,7 +63,8 @@ HeightMemoryWrapper.propTypes = {
|
|||||||
children: PropTypes.node.isRequired,
|
children: PropTypes.node.isRequired,
|
||||||
maxHeight: PropTypes.number.isRequired,
|
maxHeight: PropTypes.number.isRequired,
|
||||||
setMaxHeight: PropTypes.func.isRequired,
|
setMaxHeight: PropTypes.func.isRequired,
|
||||||
override: PropTypes.bool
|
override: PropTypes.bool,
|
||||||
|
itemKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
||||||
};
|
};
|
||||||
|
|
||||||
export default HeightMemoryWrapper;
|
export default HeightMemoryWrapper;
|
||||||
|
|||||||
@@ -183,8 +183,20 @@ const Lane = ({
|
|||||||
const shouldOverride = orientation !== "horizontal" && (collapsed || !renderedCards.length);
|
const shouldOverride = orientation !== "horizontal" && (collapsed || !renderedCards.length);
|
||||||
const shouldRenderPlaceholder = orientation !== "horizontal" && (collapsed || renderedCards.length === 0);
|
const shouldRenderPlaceholder = orientation !== "horizontal" && (collapsed || renderedCards.length === 0);
|
||||||
|
|
||||||
|
const hasKey =
|
||||||
|
orientation === "vertical"
|
||||||
|
? {
|
||||||
|
key: id
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HeightMemoryWrapper maxHeight={maxLaneHeight} setMaxHeight={setMaxLaneHeight} override={shouldOverride}>
|
<HeightMemoryWrapper
|
||||||
|
{...hasKey}
|
||||||
|
maxHeight={maxLaneHeight}
|
||||||
|
setMaxHeight={setMaxLaneHeight}
|
||||||
|
override={shouldOverride}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
{...provided.droppableProps}
|
{...provided.droppableProps}
|
||||||
ref={provided.innerRef}
|
ref={provided.innerRef}
|
||||||
@@ -197,7 +209,7 @@ const Lane = ({
|
|||||||
</HeightMemoryWrapper>
|
</HeightMemoryWrapper>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[orientation, collapsed, isVisible, renderDraggable, maxLaneHeight, setMaxLaneHeight, maxCardWidth]
|
[orientation, collapsed, isVisible, renderDraggable, maxLaneHeight, setMaxLaneHeight, maxCardWidth, id]
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderDragContainer = useCallback(
|
const renderDragContainer = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user