Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onScrolled callback #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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