Skip to content

Commit

Permalink
Merge pull request #4230 from helaoutar/bugfix/4132_edit_message_scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
deetergp authored Jul 27, 2021
2 parents e043ac2 + 9be3668 commit bd23235
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/TextInputFocusable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TextInputFocusable extends React.Component {
this.dragNDropListener = this.dragNDropListener.bind(this);
this.handlePaste = this.handlePaste.bind(this);
this.handlePastedHTML = this.handlePastedHTML.bind(this);
this.handleWheel = this.handleWheel.bind(this);
}

componentDidMount() {
Expand All @@ -141,6 +142,7 @@ class TextInputFocusable extends React.Component {
document.addEventListener('dragleave', this.dragNDropListener);
document.addEventListener('drop', this.dragNDropListener);
this.textInput.addEventListener('paste', this.handlePaste);
this.textInput.addEventListener('wheel', this.handleWheel);
}
}

Expand Down Expand Up @@ -168,6 +170,7 @@ class TextInputFocusable extends React.Component {
document.removeEventListener('dragleave', this.dragNDropListener);
document.removeEventListener('drop', this.dragNDropListener);
this.textInput.removeEventListener('paste', this.handlePaste);
this.textInput.removeEventListener('wheel', this.handleWheel);
}
}

Expand Down Expand Up @@ -304,6 +307,18 @@ class TextInputFocusable extends React.Component {
}
}

/**
* Manually scrolls the text input, then prevents the event from being passed up to the parent.
* @param {Object} event native Event
*/
handleWheel(event) {
if (event.target === document.activeElement) {
this.textInput.scrollTop += event.deltaY;
event.preventDefault();
event.stopPropagation();
}
}

/**
* Check the current scrollHeight of the textarea (minus any padding) and
* divide by line height to get the total number of rows for the textarea.
Expand Down

0 comments on commit bd23235

Please sign in to comment.