import React from "react";
import ReactDOM from "react-dom";
const symShouldStick = Symbol("shouldStick");
const isAtBottom = v => v.scrollTop + v.clientHeight === v.scrollHeight;
export default Component => Object.assign(class AutoScrollWrapper extends Component {
static displayName = Component.name;
componentWillUpdate() {
const viewport = ReactDOM.findDOMNode(this);
this[symShouldStick] = viewport.scrollTop && isAtBottom(viewport);
super.componentWillUpdate && super.componentWillUpdate();
}
componentDidUpdate() {
const viewport = ReactDOM.findDOMNode(this);
if (this[symShouldStick] && !isAtBottom(viewport)) {
viewport.scrollTop = viewport.scrollHeight;
}
super.componentDidUpdate && super.componentDidUpdate();
}
}, Component);
input type='hidden' name='id' value='ac24f203cc4141d6d27f27dc173e04fc5edde741'/>
blob: 739e00613c08ff2aa9fe9660b6f439b916dd5d92 (
plain)