While we are using SUSI Web Chat Application we may have to send lengthy messages. Existing application’s Message composer supports for lengthy messages but it manages a constant value for every user input. While we were developing the application we got a requirement to build a growing message composer.
Final output of this implementation produces a message composer that grows when user completes a new line until user completes 5 lines and after 5 lines it maintains a fixed size and enables scrolling.
So we tried several packages to get this done. And finally we did this using react-textarea-autosize it gives all these features and it gives user to customize the elements furthermore.
First we have to install the npm package:
After the installation we have to import the package on top of the “MessageComposer.react.js”
Next we need to use this package like this,
This package provides “minRows” and “maxRows” attributes and we can define minimum height of the text area and maximum height it can grow. If you need to know more about auto growing text areas and to get examples refer this.
Next we wanted to hide the scrollbar which is displaying when the textarea height is exceeding.
How we hide the scrollbars on chrome browsers.
This is how we hide the scrollbar on firefox browser.
Now we have to style up the textarea because it comes with default styles. We wrapped up the textarea with the div and applied our styles to that. In my case we wrapped up my textarea with “<div className=“textBack”>”
This is how we styled the textarea using the wrapper div.
Our textarea is like this.
It expands when user exceeds the width of textarea.
This is how we implemented the SUSI Web Chat’s growing message composer. If you would like to contribute please fork our repository on github
- NPM package and documentation: https://www.npmjs.com/package/react-textarea-autosize
- Examples of auto growing textareas: https://andreypopp.github.io/react-textarea-autosize/