jaredLunde / masonic

🧱 High-performance masonry layouts for React
https://codesandbox.io/s/0oyxozv75v
MIT License
807 stars 50 forks source link

item width breaks with text wrap #172

Open proohit opened 1 day ago

proohit commented 1 day ago

Describe the bug It appears the width calculation of each item breaks if the layout gives the masonry smaller available space, and gives it back afterwards. I've detected this with animations using framer-motion, see sandbox below. The masonry container appears to get the correct width. Also, triggering a rerender seems to fix the issue, but i don't know when to rerender in order to fix that.

To Reproduce Hover over the nav bar, in order for it to grow. Then hover away and the masonry stays in the shrunk state https://codesandbox.io/p/sandbox/frosty-framework-kfksfg

Expected behavior The layout should adapt to wrapped/unwrapped text and calculate the width accordingly.

Screenshots

Before: image After: image

jaredLunde commented 1 day ago

Seems like you may want this instead: https://codesandbox.io/p/sandbox/masonic-inside-of-a-scrollable-div-example-k9l6c?file=%2Fsrc%2Findex.js

Or control the width prop on your own as seen here https://github.com/jaredLunde/masonic?tab=readme-ov-file#masonryscroller

proohit commented 1 day ago

Thanks for your quick response. Unfortunately, I do not quite get what the proposed solutions are. I thought that the Masonry components use the remaining width automatically, as the masonry container width is set to "100%".

jaredLunde commented 1 day ago

The default component only updates if the size of the window changes

jaredLunde commented 1 day ago

The default component only updates if the size of the window changes