Magic-Grid
Magic-Grid copied to clipboard
Detect parent element resize?
Currently it listens to window resize, but I think its better to listen to parent element resize instead with ways like https://github.com/sdecima/javascript-detect-element-resize
I think that should be left to the user. It's a really specific use case and adds a lot of extra code to the project. Better for the user to listen for changes to the container size and call positionItems
when there's a change.
Maybe i will add an extra prop in react version for that, will close it when implemented.
Done
Cool. Don't forget to add it to your docs
I agree on the usefulness of listening to the container size instead of window (or at least introducing an option to do so).
Actually, use of https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver on this.container
may be perfect for this. Some users may need to polyfill, but there are plenty available.
I agree on the usefulness of listening to the container size instead of window (or at least introducing an option to do so).
Actually, use of developer.mozilla.org/en-US/docs/Web/API/ResizeObserver on
this.container
may be perfect for this. Some users may need to polyfill, but there are plenty available.
Yes this is also what used in my react version :)
I'll have to play around with the ResizeObserver
but I definitely prefer it to javascript-detect-element-resize
which would double the size of Magic-Grid. I'll reopen this issue and try to get this sorted by the weekend.
Agreed on parent element resize detection vs browser width. If you are developing for a React component we should assume the logic is tied to only its component — e.g. since the grid may sit in multiple places each with a different widths.