@@ -148,7 +148,7 @@ var InfiniteScroll = (function(_Component) {
148148 value : function detachScrollListener ( ) {
149149 var scrollEl = window ;
150150 if ( this . props . useWindow === false ) {
151- scrollEl = this . scrollComponent . parentNode ;
151+ scrollEl = this . getParentElement ( this . scrollComponent ) ;
152152 }
153153
154154 scrollEl . removeEventListener (
@@ -163,16 +163,31 @@ var InfiniteScroll = (function(_Component) {
163163 ) ;
164164 } ,
165165 } ,
166+ {
167+ key : 'getParentElement' ,
168+ value : function getParentElement ( el ) {
169+ return el . parentNode ;
170+ } ,
171+ } ,
172+ {
173+ key : 'filterProps' ,
174+ value : function filterProps ( props ) {
175+ return props ;
176+ } ,
177+ } ,
166178 {
167179 key : 'attachScrollListener' ,
168180 value : function attachScrollListener ( ) {
169- if ( ! this . props . hasMore ) {
181+ if (
182+ ! this . props . hasMore ||
183+ ! this . getParentElement ( this . scrollComponent )
184+ ) {
170185 return ;
171186 }
172187
173188 var scrollEl = window ;
174189 if ( this . props . useWindow === false ) {
175- scrollEl = this . scrollComponent . parentNode ;
190+ scrollEl = this . getParentElement ( this . scrollComponent ) ;
176191 }
177192
178193 scrollEl . addEventListener (
@@ -211,6 +226,7 @@ var InfiniteScroll = (function(_Component) {
211226 value : function scrollListener ( ) {
212227 var el = this . scrollComponent ;
213228 var scrollEl = window ;
229+ var parentNode = this . getParentElement ( el ) ;
214230
215231 var offset = void 0 ;
216232 if ( this . props . useWindow ) {
@@ -230,15 +246,14 @@ var InfiniteScroll = (function(_Component) {
230246 ( el . offsetHeight - scrollTop - window . innerHeight ) ;
231247 }
232248 } else if ( this . props . isReverse ) {
233- offset = el . parentNode . scrollTop ;
249+ offset = parentNode . scrollTop ;
234250 } else {
235251 offset =
236- el . scrollHeight -
237- el . parentNode . scrollTop -
238- el . parentNode . clientHeight ;
252+ el . scrollHeight - parentNode . scrollTop - parentNode . clientHeight ;
239253 }
240254
241- if ( offset < Number ( this . props . threshold ) ) {
255+ // Here we make sure the element is visible as well as checking the offset
256+ if ( offset < Number ( this . props . threshold ) && el . offsetParent !== null ) {
242257 this . detachScrollListener ( ) ;
243258 // Call loadMore after detachScrollListener to allow for non-async loadMore functions
244259 if ( typeof this . props . loadMore === 'function' ) {
@@ -261,20 +276,21 @@ var InfiniteScroll = (function(_Component) {
261276 value : function render ( ) {
262277 var _this2 = this ;
263278
264- var _props = this . props ,
265- children = _props . children ,
266- element = _props . element ,
267- hasMore = _props . hasMore ,
268- initialLoad = _props . initialLoad ,
269- isReverse = _props . isReverse ,
270- loader = _props . loader ,
271- loadMore = _props . loadMore ,
272- pageStart = _props . pageStart ,
273- ref = _props . ref ,
274- threshold = _props . threshold ,
275- useCapture = _props . useCapture ,
276- useWindow = _props . useWindow ,
277- props = _objectWithoutProperties ( _props , [
279+ var renderProps = this . filterProps ( this . props ) ;
280+
281+ var children = renderProps . children ,
282+ element = renderProps . element ,
283+ hasMore = renderProps . hasMore ,
284+ initialLoad = renderProps . initialLoad ,
285+ isReverse = renderProps . isReverse ,
286+ loader = renderProps . loader ,
287+ loadMore = renderProps . loadMore ,
288+ pageStart = renderProps . pageStart ,
289+ ref = renderProps . ref ,
290+ threshold = renderProps . threshold ,
291+ useCapture = renderProps . useCapture ,
292+ useWindow = renderProps . useWindow ,
293+ props = _objectWithoutProperties ( renderProps , [
278294 'children' ,
279295 'element' ,
280296 'hasMore' ,
0 commit comments