joshwnj / react-visibility-sensor

Sensor component for React that notifies you when it goes in or out of the window viewport.
MIT License
2.33k stars 195 forks source link

Add option to detect elements that have no size #155

Open Gyanreyer opened 5 years ago

Gyanreyer commented 5 years ago

I have a scenario where I am implementing a basic form of lazy loading where I'm waiting for an empty element to become visible before loading an element inside of it - this worked fine until I recently upgraded to a more recent version of react-visibility-sensor and discovered that the ability to detect the visibility of elements with 0 width/height has been disabled.

I understand why this was done, but I would love some sort of option that would allow you to still detect the visibility of elements with no width/height.

jetpack3331 commented 5 years ago

Any progress here?

Gyanreyer commented 5 years ago

Thanks for reminding me about this! I just went ahead and threw together a PR for it: https://github.com/joshwnj/react-visibility-sensor/pull/167

For now if you just need something to work, the best (but kinda gross) solution is just going to be setting a min-height: 1px and min-width: 1px style on the placeholder element to make sure it will have some size that can be detected.

kula124p commented 4 years ago

I "hacked" this by setting min hight of an "invisible" element to 1px in css Works fine in my case :)

arkadash commented 4 years ago

Any news about this one? I can see it's still in PR... Can you please update the state?