diff --git a/src/App.js b/src/App.js index 0d67ac0..657425f 100644 --- a/src/App.js +++ b/src/App.js @@ -248,7 +248,8 @@ class App extends Component { } state = { chatMsg: {}, - position: "" + position: "", + chatAreaHeight: 0 }; sendMsg(event) { @@ -283,10 +284,22 @@ class App extends Component { this.chatArea.reset(); } + scrollToBottom = () => { + if (this.chatBubble.scrollHeight > this.state.chatAreaHeight) { + this.chatBubble.scrollTop = this.chatBubble.scrollHeight; + this.setState({chatAreaHeight: this.chatBubble.scrollHeight}); + } + }; + componentDidMount() { + this.setState({chatAreaHeight: this.chatBubble.scrollHeight}); console.log("Apps dimulai"); } + componentDidUpdate() { + this.scrollToBottom(); + } + // sendLeft = (side, msg) => {}; sendLeft = () => { this.setState({position: "l"}); @@ -320,7 +333,11 @@ class App extends Component { - + { + this.chatBubble = el; + }} + > {Object.keys(this.state.chatMsg).map(key => (