Skip to content

Commit

Permalink
Allow messages scrolling within edit box.
Browse files Browse the repository at this point in the history
  • Loading branch information
helaoutar committed Jul 26, 2021
1 parent fc965f6 commit 9be3668
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 @@ -123,6 +123,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 @@ -146,6 +147,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 @@ -173,6 +175,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 @@ -322,6 +325,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 9be3668

Please sign in to comment.