jackmoore / autosize

Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.
http://www.jacklmoore.com/autosize/
MIT License
5.1k stars 702 forks source link

How to resize plus additional more row. #386

Closed jhunexjun closed 3 years ago

jhunexjun commented 3 years ago

Is it possible to auto adjust but plus a certain non-negative integer number for the row. So it will adjust + additional row if it wants to.

jackmoore commented 3 years ago

@jhunexjun Autosize is restricted to sizes based on pixels (computations based on getComputedStyle, which returns pixels), instead of rows. If you knew roughly the pixel-size of the row you could modify the Autosize source to add that extra amount. Here's an example of one place you could do it:

https://github.com/jackmoore/autosize/blob/d32047a7c06d81fedb12e0e9bfdd108e3a0a68f1/dist/autosize.js#L87

In this file, on like 87, you could add the following to increase the height by 20 pixels:

heightOffset += 20;

But this is visually no different than adding 20 pixels to the bottom padding of the textarea though CSS, which is why I didn't feel the need to provide a built-in option. You have more flexibility with CSS, allowing you to use units like em or calc.

jhunexjun commented 3 years ago

Thank you for giving me an immediate and precise answer.