Answer the question
In order to leave comments, you need to log in
How to get textarea height?
How to get the height of an element's textarea (also get when it increases) in a React component. Thanks
Answer the question
In order to leave comments, you need to log in
1. Get a reference to the home element using ref
2. Get the height of the resulting DOM element
Height can be received through el.outerHeight
And to receive it when increases it is necessary to write the crutch. The most banal option is when you listen to the onchange event, you can also listen to the merge of the mouse (if you want to catch the resize with the mouse, and not the increase due to the amount of content)
<textarea ref=(node=>this.__anyName) onInput={(e)=>console.log(e.currentTarget.scrollHeight)} />
const height = this.__anyName.scrollHeight
Working with textarea in React is not the most trivial.
You can see the implementations:
- TextareaAutosize in Material UI: https://github.com/mui-org/material-ui/blob/master...
- react-textarea-autosize: https://github.com/andreypopp/react -textarea-autosize
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question