react-overflow icon indicating copy to clipboard operation
react-overflow copied to clipboard

Add `onScrolled` callback

Open wmertens opened this issue 7 years ago • 0 comments

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>
    );
  }
}

wmertens avatar Oct 13 '17 08:10 wmertens