Skip to content

Commit ab5cead

Browse files
committed
Moved to returning scroll parent through a function
1 parent 1bc8605 commit ab5cead

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ You can define a custom `parentNode` element to base the scroll calulations on.
6969
hasMore={true || false}
7070
loader={<div className="loader" key={0}>Loading ...</div>}
7171
useWindow={false}
72-
scrollParent={this.scrollParentRef}
72+
getScrollParent={() => return this.scrollParentRef}
7373
>
7474
{items}
7575
</InfiniteScroll>
@@ -88,7 +88,7 @@ You can define a custom `parentNode` element to base the scroll calulations on.
8888
| `loadMore`       | `Function`   |           | A callback when more items are requested by the user. Receives a single parameter specifying the page to load e.g. `function handleLoadMore(page) { /* load more items here */ }` }|
8989
| `loader` | `Component` | | A React component to render while more items are loading. The parent component must have a unique key prop. |
9090
| `pageStart` | `Number` | `0` | The number of the first page to load, With the default of `0`, the first page is `1`.|
91-
| `scrollParent` | `React.Element`| | Override for the scroll listener to attach to if not the immediate parent. |
91+
| `getScrollParent` | `Function`| | Override method to return a different scroll listener if not the immediate parent. |
9292
| `threshold` | `Number` | `250` | The distance in pixels before the end of the items that will trigger a call to `loadMore`.|
9393
| `useCapture` | `Boolean` | `false` | Proxy to the `useCapture` option of the added event listeners.|
9494
| `useWindow` | `Boolean` | `true` | Add scroll listeners to the window, or else, the component's `parentNode`.|

dist/InfiniteScroll.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ var InfiniteScroll = (function(_Component) {
166166
{
167167
key: 'getParentElement',
168168
value: function getParentElement(el) {
169-
var scrollParent = this.props.scrollParent;
169+
var scrollParent = this.props.getScrollParent();
170170
if (scrollParent != null) {
171171
return scrollParent;
172172
}
@@ -308,6 +308,7 @@ var InfiniteScroll = (function(_Component) {
308308
threshold = renderProps.threshold,
309309
useCapture = renderProps.useCapture,
310310
useWindow = renderProps.useWindow,
311+
getScrollParent = renderProps.getScrollParent,
311312
props = _objectWithoutProperties(renderProps, [
312313
'children',
313314
'element',
@@ -321,6 +322,7 @@ var InfiniteScroll = (function(_Component) {
321322
'threshold',
322323
'useCapture',
323324
'useWindow',
325+
'getScrollParent',
324326
]);
325327

326328
props.ref = function(node) {
@@ -360,7 +362,7 @@ InfiniteScroll.propTypes = {
360362
loadMore: _propTypes2.default.func.isRequired,
361363
pageStart: _propTypes2.default.number,
362364
ref: _propTypes2.default.func,
363-
scrollParent: _propTypes2.default.element,
365+
getScrollParent: _propTypes2.default.func,
364366
threshold: _propTypes2.default.number,
365367
useCapture: _propTypes2.default.bool,
366368
useWindow: _propTypes2.default.bool,
@@ -376,7 +378,7 @@ InfiniteScroll.defaultProps = {
376378
isReverse: false,
377379
useCapture: false,
378380
loader: null,
379-
scrollParent: null,
381+
getScrollParent: null,
380382
};
381383
exports.default = InfiniteScroll;
382384
module.exports = exports['default'];

src/InfiniteScroll.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class InfiniteScroll extends Component {
1212
loadMore: PropTypes.func.isRequired,
1313
pageStart: PropTypes.number,
1414
ref: PropTypes.func,
15-
scrollParent: PropTypes.element,
15+
getScrollParent: PropTypes.func,
1616
threshold: PropTypes.number,
1717
useCapture: PropTypes.bool,
1818
useWindow: PropTypes.bool,
@@ -29,7 +29,7 @@ export default class InfiniteScroll extends Component {
2929
isReverse: false,
3030
useCapture: false,
3131
loader: null,
32-
scrollParent: null,
32+
getScrollParent: null,
3333
};
3434

3535
constructor(props) {
@@ -89,7 +89,7 @@ export default class InfiniteScroll extends Component {
8989
}
9090

9191
getParentElement(el) {
92-
const scrollParent = this.props.scrollParent;
92+
const scrollParent = this.props.getScrollParent();
9393
if (scrollParent != null) {
9494
return scrollParent;
9595
}
@@ -211,7 +211,7 @@ export default class InfiniteScroll extends Component {
211211
threshold,
212212
useCapture,
213213
useWindow,
214-
scrollParent,
214+
getScrollParent,
215215
...props
216216
} = renderProps;
217217

0 commit comments

Comments
 (0)