Automatically expand a <textarea> to fit its content, in a few bytes
npm install fit-textarea[badge-gzip]: https://img.shields.io/bundlephobia/minzip/fit-textarea.svg?label=gzipped
[link-npm]: https://www.npmjs.com/package/fit-textarea
> Automatically expand a to fit its content, in a few bytes
Try the demo!
Features:
- Small
- No layout thrashing (no DOM changes unless necessary)
- You can set a minimum height (via rows attribute or height CSS property)
- If the field is resizable, the new size will be treated as minimum height
```
npm install fit-textarea
`js`
// This module is only offered as a ES Module
import fitTextarea from 'fit-textarea';
`html`
`js`
const textarea = document.querySelector('textarea');
fitTextarea(textarea);
#### One element
`js`
const textarea = document.querySelector('textarea');
fitTextarea.watch(textarea);
#### Array/NodeList/Iterable of elements
`js`
const textareas = document.querySelectorAll('textarea');
fitTextarea.watch(textareas);
#### With a selector
The selector is run once, so it's equivalent to the example above.
`js`
fitTextarea.watch('textarea');
- indent-textarea - Add editor-like tab-to-indent functionality to