-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Masonry] Incorrect number of columns behaviour when items have dynamic height #29692
Comments
@@ -266,14 +269,14 @@ const Masonry = React.forwardRef(function Masonry(inProps, ref) {
}
const container = masonryRef.current;
if (container && resizeObserver) {
// only the masonry container and its first child are observed for resizing;
// this might cause unforeseen problems in some use cases;
resizeObserver.observe(container);
if (container.firstChild) {
resizeObserver.observe(container.firstChild);
}
}
return () => (resizeObserver ? resizeObserver.disconnect() : {});
}, [columns, spacing, children]); Thanks for the report. When an item's height changes, new computation should run (for new height of @siriwatknp @mnajdova any thoughts? |
@hbjORbj What if you also observe the line-break elements. If any of the line-break is pushed more than the Masonry's height, then recalculate the height to maintain the columns. |
@siriwatknp I've tried that too, but event was still not firing. I think it's because the masonry is set to a fixed height after every computation.. |
@jpmtrabbold Hi, I opened a PR for this issue! Feel free to have a look. Here is a fork of your codesandbox with the build of the PR. You can see that the error is gone! |
you are brilliant man! solved the problem, with less code :) |
I am experiencing a similar issue as well. From reading this issue and the PR, it might actually be the same issue. My masonry layout is breaking as well. I only have this problem after deploying to production. My tiles have images in there, so the delayed loading might cause the masonry to compute the wrong height before the images are loaded. I have worked around it by changing some state of the masonry parent on image load to trigger the re-render. It would be awesome if this could happen automatically with this PR. |
@agoblet Hi, can you replace |
@hbjORbj yes that seems to resolve the issue :) removed the workaround and added that branch, and cannot reproduce the issue on production. |
@agoblet @jpmtrabbold |
Thx for picking this up so quickly again after a period of staleness! @hbjORbj |
Thank you so much @hbjORbj - legend! |
Duplicates
Latest version
Current behavior 😯
If any of the items of the masonry can grow in height, instead of re-accommodate all items to preserve the number of columns, it is creating new columns. Please refer to this sandbox:
Sandbox
In the sandbox demo, if you start opening the accordions, you'll see the undesired columns being created.
Expected behavior 🤔
The masonry should always stick to the number of columns passed in the
columns
prop.Steps to reproduce 🕹
columns
Context 🔦
Trying to use the masonry to displays different cards and controls in a dashboard that could have different (and possibly growing) heights.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: