Skip to content

Commit 56d55da

Browse files
authored
Rename childRef to registerChild and add some docs (bvaughn#947)
Rename childRef to registerChild and add some docs
1 parent 2a4c52d commit 56d55da

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

docs/WindowScroller.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
WindowScroller
22
---------------
33

4-
High-order component that enables a `Table` or `List` component to be scrolled based on the window's scroll positions.
4+
A component that enables a `Table` or `List` component to be scrolled based on the window's scroll positions.
55
This can be used to create layouts similar to Facebook or Twitter news feeds.
66

7-
**Note** that this HOC does not currently work with a horizontally-scrolling `Grid` as horizontal scrolls reset the internal `scrollTop`.
8-
This may change with a future release but for the time being this HOC is should be used with `Table` or `List` only.
7+
**Note** that this component does not currently work with a horizontally-scrolling `Grid` as horizontal scrolls reset the internal `scrollTop`.
8+
This may change with a future release but for the time being this component is should be used with `Table` or `List` only.
99

1010
### Prop Types
1111
| Property | Type | Required? | Description |
1212
|:---|:---|:---:|:---|
13-
| children | Function || Function responsible for rendering children. This function should implement the following signature: `({ height: number, width: number, isScrolling: boolean, scrollTop: number, onChildScroll: function }) => PropTypes.element` |
13+
| children | Function || Function responsible for rendering children. This function should implement the following signature: `({ height: number, width: number, isScrolling: boolean, scrollTop: number, registerChild: function, onChildScroll: function }) => PropTypes.element` |
1414
| onResize | Function | | Callback to be invoked on-resize; it is passed the following named parameters: `({ height: number, width: number })`. |
1515
| onScroll | Function | | Callback to be invoked on-scroll; it is passed the following named parameters: `({ scrollTop: number, scrollLeft: number })`. |
1616
| scrollElement | any | | Element to attach scroll event listeners. Defaults to `window`. |
@@ -53,3 +53,37 @@ ReactDOM.render(
5353
document.getElementById('example')
5454
);
5555
```
56+
57+
or using `registerChild` you can specify grid container deeper in layout (by default `WindowScroller` uses `ReactDOM.findDOMNode` function)
58+
59+
```javascript
60+
import React from 'react';
61+
import ReactDOM from 'react-dom';
62+
import { List, WindowScroller } from 'react-virtualized';
63+
import 'react-virtualized/styles.css'; // only needs to be imported once
64+
65+
ReactDOM.render(
66+
<WindowScroller>
67+
{({ height, isScrolling, registerChild, scrollTop }) => (
68+
<div>
69+
<header>
70+
Table header
71+
</header>
72+
<div ref={registerChild}>
73+
<List
74+
autoHeight
75+
height={height}
76+
isScrolling={isScrolling}
77+
rowCount={...}
78+
rowHeight={...}
79+
rowRenderer={...}
80+
scrollTop={scrollTop}
81+
width={...}
82+
/>
83+
</div>
84+
</div>
85+
)}
86+
</WindowScroller>,
87+
document.getElementById('example')
88+
);
89+
```

source/WindowScroller/WindowScroller.example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ export default class WindowScrollerExample extends PureComponent<{}, State> {
8686
<WindowScroller
8787
ref={this._setRef}
8888
scrollElement={isScrollingCustomElement ? customElement : window}>
89-
{({height, isScrolling, childRef, onChildScroll, scrollTop}) => (
89+
{({height, isScrolling, registerChild, onChildScroll, scrollTop}) => (
9090
<div className={styles.WindowScrollerWrapper}>
9191
<AutoSizer disableHeight>
9292
{({width}) => (
93-
<div ref={childRef}>
93+
<div ref={registerChild}>
9494
<List
9595
ref={el => {
9696
window.listEl = el;

source/WindowScroller/WindowScroller.jest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('WindowScroller', () => {
8282
expect(component._positionFromLeft).toEqual(left);
8383
});
8484

85-
it('should allow passing child element with childRef of children function param', () => {
85+
it('should allow passing child element with registerChild of children function param', () => {
8686
const scrollElement = document.createElement('div');
8787
scrollElement.scrollTop = 100;
8888
scrollElement.scrollLeft = 150;
@@ -97,7 +97,7 @@ describe('WindowScroller', () => {
9797
});
9898
const renderFn = jest.fn();
9999
const component = render(getMarkup({scrollElement, renderFn}));
100-
renderFn.mock.calls[0][0].childRef(child);
100+
renderFn.mock.calls[0][0].registerChild(child);
101101
expect(component._positionFromTop).toEqual(300 + 100 - 200);
102102
expect(component._positionFromLeft).toEqual(350 + 150 - 250);
103103
});

source/WindowScroller/WindowScroller.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type Props = {
2020
* This function should implement the following signature:
2121
* ({ height, isScrolling, scrollLeft, scrollTop, width }) => PropTypes.element
2222
*/
23-
children: (params: {
23+
children: ({
2424
onChildScroll: ({scrollTop: number}) => void,
25-
childRef: (?Element) => void,
25+
registerChild: (?Element) => void,
2626
height: number,
2727
isScrolling: boolean,
2828
scrollLeft: number,
@@ -31,10 +31,10 @@ type Props = {
3131
}) => React.Node,
3232

3333
/** Callback to be invoked on-resize: ({ height, width }) */
34-
onResize: (params: {height: number, width: number}) => void,
34+
onResize: ({height: number, width: number}) => void,
3535

3636
/** Callback to be invoked on-scroll: ({ scrollLeft, scrollTop }) */
37-
onScroll: (params: {scrollLeft: number, scrollTop: number}) => void,
37+
onScroll: ({scrollLeft: number, scrollTop: number}) => void,
3838

3939
/** Element to attach scroll event listeners. Defaults to window. */
4040
scrollElement: ?Element,
@@ -173,7 +173,7 @@ export default class WindowScroller extends React.PureComponent<Props, State> {
173173

174174
return children({
175175
onChildScroll: this._onChildScroll,
176-
childRef: this._childRef,
176+
registerChild: this._registerChild,
177177
height,
178178
isScrolling,
179179
scrollLeft,
@@ -182,7 +182,7 @@ export default class WindowScroller extends React.PureComponent<Props, State> {
182182
});
183183
}
184184

185-
_childRef = element => {
185+
_registerChild = element => {
186186
this._child = element;
187187
this.updatePosition();
188188
};

0 commit comments

Comments
 (0)