Skip to content

Commit 87b7cce

Browse files
committed
made overflow auto default, updated readme
1 parent 23fe3db commit 87b7cce

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ At its most basic, you pass an array of data and a row component to render the i
1515

1616
All of the props are optional. If you don't provide any data or a row component, it won't render anything, but it won't cause any errors, either.
1717

18+
You need to apply `height`, either in the css class or the style object. You can use a specific height, or `calc()`.
19+
20+
Due to a CSS limitation with how overflow works with padding, `height: 100%` does not work.
21+
22+
The `overflow` default value of `auto` is applied via `style`. So, if you want to use a css class to control it, you need to pass `null`, `undefined`, or an empty string to `overflow`. If you use a style object, you can set it there, since the default `auto` is applied before your style object and thus can be overwritten that way.
23+
1824
#### Props
1925
- `className` - A css className that will be applied to the component.
2026
- `data` - An array of items to be passed to your row component.
27+
- `overflow` - You can set this to `auto` or `scroll` ("auto" is the default).
2128
- `row` - Your row component.
2229
- `rowHeight` - Starting row height (100 by default) - it starts with this as an estimate for all rows, and then measures and caches the actual height of each row is as you scroll.
2330
- `style` - A style object applied to the component if you prefer using inline styling instead of css.
@@ -29,6 +36,7 @@ import ReactSmartScroll from 'react-smart-scroll';
2936
<ReactSmartScroll
3037
className="demo-smart-scroll"
3138
data={data}
39+
overflow="scroll"
3240
row={TestRow}
3341
onClick={() => console.log('Hello!')} // passed to row components
3442
label="My text is: " // passed to row components
@@ -49,12 +57,7 @@ Your row component receives the following props:
4957
- `height` - The current measured height of the row. It's provided for debugging or if you have a use for it.
5058
- `rowIndex` - The index of the item in the data array. Also provided for debugging, use if you like.
5159
- `rowRef` - *required* You need to include `ref={rowRef}` prop on your row component's container element.
52-
- `...rowProps` - Any additional props you passed to the ReactSmartScroll component will be available on every row.
53-
54-
ReactSmartScroll does not come with any default styling. Two properties are required in the css class or the style object. This provides complete flexibility in how its implemented.
55-
56-
1. `height` - You need to provide a height or it won't work. Due to the way CSS works with padding, `height: 100%` will not work. You can use a specific height, or `calc()`.
57-
2. `overflow-y` Set this to `auto` or `scroll`.
60+
- `...rowProps` - Any additional props you passed to the ReactSmartScroll component will be available on every row.
5861

5962
## How It Works
6063
ReactSmartscroll renders enough rows to fill the visible space of the scroll area, plus an extra one above and below. It measures the height of each of the visible row and caches that height as you scroll (or resize) so that the next render of the same row is more efficient. It simulates the total height of all the items by adjusting the padding top and bottom of the div that contains the rows as you scroll.

nwb.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ module.exports = {
44
esModules: true,
55
umd: false
66
}
7-
}
7+
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-smart-scroll",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Smart Scroll React Component for long lists",
55
"author": "Steven Sacks",
66
"homepage": "https://github.com/stevensacks/react-smart-scroll",
@@ -14,6 +14,7 @@
1414
"react list scroll"
1515
],
1616
"main": "lib/index.js",
17+
"module": "es/index.js",
1718
"files": [
1819
"es",
1920
"lib"

src/ReactSmartScroll/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import useScroll from '../hooks/useScroll';
1313
import useScrollToTop from '../hooks/useScrollToTop';
1414

1515
const ReactSmartScroll = props => {
16-
const {className, data, row, rowHeight, style, ...rowProps} = props;
16+
const {className, data, overflow, row, rowHeight, style, ...rowProps} = props;
1717

1818
const [actualHeights, setActualHeights] = useReducer((state, action) => {
1919
if (!action.reset) {
@@ -79,7 +79,7 @@ const ReactSmartScroll = props => {
7979
const {endIndex, paddingBottom, paddingTop, startIndex} = measurements;
8080

8181
return (
82-
<div ref={scrollRef} className={className || ''} style={style}>
82+
<div ref={scrollRef} className={className || ''} style={{overflow, ...style}}>
8383
<div style={{paddingBottom, paddingTop: paddingTop}}>
8484
{data.slice(startIndex, endIndex + 1).map((item, i) => (
8585
<ReactSmartScrollRow
@@ -100,6 +100,7 @@ const ReactSmartScroll = props => {
100100
ReactSmartScroll.defaultProps = {
101101
className: '',
102102
data: [],
103+
overflow: 'auto',
103104
row: () => null,
104105
rowHeight: 100,
105106
style: {},

0 commit comments

Comments
 (0)