[hook-intersection] intersects state should be based on intersectionRatio
and isIntersecting
#32
Labels
Type: Bug
Something isn't working
Description
Using this hook statefully, like:
provides a boolean
intersects
value that is derived from the isIntersecting value of the underlying IntersectionObserverEntry.In the simple case (as above), this is fine, but if thresholds are defined, expectations change:
Here, the expectation is that
intersects
will be true only if the intersectionRatio is 0.75 or greater.This works as expected in Chrome, but not in Firefox. As it turns out, this may be due to a chromium bug. Interestingly, MDN suggests that the chromium behavior is correct, but it seems the spec actually sides with Firefox.
Steps to Reproduce
View the stateful example in Firefox.
Expected Result
The example stays red until the intersection ratio meets the provided threshold.
Actual Result
The example turns green as soon as any intersection occurs. This results in the example always being green, but if you modify the example to move the element out of the containing view, you can see in the DOM that it switches to red.
Additional Context
We most likely need to update our
intersects
state calculation to compare the provided thresholds to intersectionRatio, not just base it on isIntersecting. Note that it's possible to define multiple thresholds, like:so the calculation must account for this case.
The text was updated successfully, but these errors were encountered: