Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ $ npm i react-auto-scroll
var React = require('react')
var AutoScroll = require('react-auto-scroll')
var Component = AutoScroll({
property: 'propertyName'
property: 'propertyName',
autoScrollBuffer: 30
})(React.createClass(/* ... */))
```

Expand All @@ -26,6 +27,8 @@ var Component = AutoScroll({

* `options.property` (string) Property to track for scrolling

* `options.autoScrollBuffer` (number) Scroll distance from bottom buffer when autoscroll should take effect. Default: `0`

## License

MIT
3 changes: 2 additions & 1 deletion lib/AutoScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var ReactDOM = require('react-dom')

module.exports = function AutoScroll (options) {
var property = options.property
var autoScrollBuffer = options.autoScrollBuffer || 0

return function (Component) {
var displayName = Component.displayName || Component.name || 'Component'
Expand All @@ -28,7 +29,7 @@ module.exports = function AutoScroll (options) {
componentWillUpdate: function componentWillUpdate (nextProps) {
if (this.props[property] !== nextProps[property]) {
var node = this._node
this._shouldScroll = node.scrollTop + node.offsetHeight === node.scrollHeight
this._shouldScroll = node.scrollTop + node.offsetHeight >= node.scrollHeight - autoScrollBuffer
}
},

Expand Down