react-chatview scrolling bug

by Alex Klibisz

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-0.14.6.js"></script>
<script src="https://fb.me/react-dom-0.14.6.js"></script>
<script src="https://rawgit.com/lodash/lodash/3.10.1/lodash.js"></script>
<script src="//cdn.jsdelivr.net/bluebird/3.1.1/bluebird.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<script src="https://rawgit.com/dustingetz/react-chatview/184094e84eab3e6862bd25d5686d41736a81e09a/dist/react-chatview.js"></script>

<div id="root"/>

CSS

.view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: lightyellow;
  
  display: flex;
  flex-direction: column;
}

.view .header {
  height: 30px;
  width: 100%;
  background-color: #abcdef;
}

.view .chat-container {
  /* Fill the remaining space between the header and footer */
  flex: 1 1 auto;  
  /* If not relative, then the absolute-positioned chat-content will grow beyond this div. */
  position: relative;
}

.view .chat-container .chat-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.view .footer {
  min-height: 50px;
  background-color: #abcdef;
}

/* Chat input should start at 50px tall, grow until 130px for multi-line messages, then scroll */
.view .footer .chat-input {
  border: 1px solid black;
  background: white;
  padding: 3px;
  min-height: 50px;
  max-height: 130px;
  overflow-y: scroll;
}

JavaScript 1.7

class App extends React.Component {
  constructor (props) {
    super(props);
    this.state = { 
    	messages: _.range(50).map(v => 'hi'),
      chatContainerHeight: '300px',
      chatContainerWidth: '100%'
    };
  }
  
  render () {
    return <div className='view'>
      <div className="header">
      	Header with a search bar, tabs, etc.
      </div>
      <div className='chat-container'>
        <ReactChatView 
          className="chat-content"
          flipped={true}
          scrollLoadThreshold={50}
          onInfiniteLoad={this.loadMoreHistory.bind(this)}>
          {this.state.messages.map((v, ix) => <div key={ix}>{`${ix}: ${v}`}</div>)}
        </ReactChatView>
      </div>
      <div className="footer">
      	<div>
        	<span>Some indicators, e.g. "10 users present, 2 users typing"</span>
        </div>
      	<div className='chat-input' contentEditable={true}>
					Content-editable input area that can grow vertically (like slack) up to a max-height.
          Try entering a few more lines. You'll notice that the last few messages at the bottom
          of the chat-view component get covered up.
				</div>
      </div>
    </div>;
  }
  
  loadMoreHistory () {
    return new Promise((resolve, reject) => {
      let more = _.range(20).map(v=>'yo');
      this.setState({ messages: this.state.messages.concat(more)});
      resolve();
    });
  }
}

ReactDOM.render(<App />, document.getElementById('root'));