Skip to content
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

Add option to detect visibility for contents with no width or height #167

Closed
wants to merge 1 commit into from

Conversation

Gyanreyer
Copy link

This PR would resolve issue #155

Changes:

  • Adds requireContentsSize prop which determines whether the sensor should be able to detect elements as visible even when they have no width or height

Why:
This resolves a problem introduced in pull request #114 which added a check that would prevent an element from being detected as visible if its client rect had no width and/or height. This was done for good reason - after all, this is a visibility sensor and the element is clearly not visible.

However, this change causes some problems for people who are trying to use react-visibility-sensor for lazy loading/rendering solutions. I had a scenario where I had a component which I only wanted to render when it entered or got near the viewport - otherwise, I would just render an empty div in its place. I ended up being forced to apply a style of min-height: 1px to the div to make it work, which is okay, but it's messy and that behavior felt unintuitive and unexpected to me until I actually dug into the source code to figure out what was happening. This new requireContentsSize prop helps both by making it more clear that contents without width or height will not be detected by default and providing developers with an option to disable that behavior if they need to.

…ld require its contents to have width and height
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to detect elements that have no size
1 participant