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

Update not works when transition set to textarea #381

Closed andyBobro closed 1 year ago

andyBobro commented 4 years ago

Hello everyone! I'm using autosize with svelte and it works fine, but height doesn't update if I set transition to textarea and trying to delete text in textarea. I will be grateful for the help

jackmoore commented 4 years ago

Hi @andyBobro, unfortunately this in incompatible with the approach that autosize is using (it changes the textarea height and measures the scroll overflow, then changes the height to the desired height), as it requires instantaneous changes to the textarea element's measurements.

An alternative would be to mirror content into some off-screen textarea element and use that textarea as a basis for measurements, but there are other issues related to that approach. It's difficult to guarantee those two textarea elements are exactly the same size.

If I had this as a requirement, I would probably replace the textarea element with a content-editable div, as auto-height and CSS transition would be supported by default, and use JS to mirror it a textarea for form submission.