react-overflow
react-overflow copied to clipboard
Add `onScrolled` callback
This corrects and supersedes #2.
The use-case for this is to be able to add scroll indicators when the dom element is scrolled.
I wonder if perhaps the edge state should be provided in reverse, which would mean you don't need to initialize state
nor negate the position. E.g. notAtTop
etc? The example would then look like
import { OverflowDetector } from 'react-overflow';
class TextWithArrows extends React.Component {
state = {};
handleScrolled = pos => this.setState(pos);
render() {
const { text } = this.props;
const { notAtTop, notAtBottom, notAtLeft, notAtRight } = this.state;
return (
<ConstrainedTextDiv>
<OverflowDetector onScrolled={this.handleScrolled}>
{notAtTop && <UpArrow />}
{text}
{notAtBottom && <DownArrow />}
</OverflowDetector>
</ConstrainedTextDiv>
);
}
}