Magic-Grid icon indicating copy to clipboard operation
Magic-Grid copied to clipboard

Detect parent element resize?

Open IniZio opened this issue 6 years ago • 8 comments

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

IniZio avatar Feb 06 '19 15:02 IniZio

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.

e-oj avatar Feb 07 '19 13:02 e-oj

Maybe i will add an extra prop in react version for that, will close it when implemented.

IniZio avatar Feb 07 '19 14:02 IniZio

Done

IniZio avatar Feb 07 '19 16:02 IniZio

Cool. Don't forget to add it to your docs

e-oj avatar Feb 07 '19 16:02 e-oj

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.

robertwbradford avatar Feb 14 '19 21:02 robertwbradford

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 :)

IniZio avatar Feb 15 '19 00:02 IniZio

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.

e-oj avatar Feb 15 '19 00:02 e-oj

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.

ptcampbell avatar Dec 06 '19 06:12 ptcampbell