|
1 | 1 | WindowScroller |
2 | 2 | --------------- |
3 | 3 |
|
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. |
5 | 5 | This can be used to create layouts similar to Facebook or Twitter news feeds. |
6 | 6 |
|
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. |
9 | 9 |
|
10 | 10 | ### Prop Types |
11 | 11 | | Property | Type | Required? | Description | |
12 | 12 | |:---|:---|:---:|:---| |
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` | |
14 | 14 | | onResize | Function | | Callback to be invoked on-resize; it is passed the following named parameters: `({ height: number, width: number })`. | |
15 | 15 | | onScroll | Function | | Callback to be invoked on-scroll; it is passed the following named parameters: `({ scrollTop: number, scrollLeft: number })`. | |
16 | 16 | | scrollElement | any | | Element to attach scroll event listeners. Defaults to `window`. | |
@@ -53,3 +53,37 @@ ReactDOM.render( |
53 | 53 | document.getElementById('example') |
54 | 54 | ); |
55 | 55 | ``` |
| 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 | +``` |
0 commit comments