Skip to content

Conversation

wmertens
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants