Skip to content

Commit c1e1829

Browse files
committed
Fix Firefox intersectionRatio bug
1 parent f47c966 commit c1e1829

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/intersection.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ function onChange(changes) {
123123
const options = instance.options
124124

125125
let inView = false
126-
127-
if (Array.isArray(options.threshold)) {
126+
if (intersectionRatio < 0 && isIntersecting) {
127+
// Firefox bug, causes intersectionRatio to sometimes be less than zero if element is larger than viewport
128+
inView = true
129+
} else if (Array.isArray(options.threshold)) {
128130
// If threshold is an array, check if any of them intersects. This just triggers the onChange event multiple times.
129131
inView = options.threshold.some(threshold => {
130132
return instance.visible

stories/Observer.story.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ storiesOf('Intersection Observer', module)
5858
</Observer>
5959
</ScrollWrapper>
6060
))
61+
.add('Taller then viewport', () => (
62+
<ScrollWrapper>
63+
<Observer>
64+
{inView => (
65+
<Header style={{ height: '150vh' }}>
66+
Header is fully inside the viewport: {inView.toString()}
67+
</Header>
68+
)}
69+
</Observer>
70+
</ScrollWrapper>
71+
))
6172
.add('With threshold 100%', () => (
6273
<ScrollWrapper>
6374
<Observer threshold={1} onChange={action('Child Observer inview')}>
@@ -80,6 +91,17 @@ storiesOf('Intersection Observer', module)
8091
</Observer>
8192
</ScrollWrapper>
8293
))
94+
.add('Taller then viewport with threshold 100%', () => (
95+
<ScrollWrapper>
96+
<Observer threshold={1}>
97+
{inView => (
98+
<Header style={{ height: '150vh' }}>
99+
Header is fully inside the viewport: {inView.toString()}
100+
</Header>
101+
)}
102+
</Observer>
103+
</ScrollWrapper>
104+
))
83105
.add('With threshold array', () => (
84106
<ScrollWrapper>
85107
<Observer

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,9 +3087,9 @@ flatten@^1.0.2:
30873087
version "1.0.2"
30883088
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
30893089

3090-
flow-bin@^0.61.0:
3091-
version "0.61.0"
3092-
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.61.0.tgz#d0473a8c35dbbf4de573823f4932124397d32d35"
3090+
flow-bin@^0.62.0:
3091+
version "0.62.0"
3092+
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.62.0.tgz#14bca669a6e3f95c0bc0c2d1eb55ec4e98cb1d83"
30933093

30943094
flow-copy-source@^1.2.1:
30953095
version "1.2.1"

0 commit comments

Comments
 (0)