
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
textarea-autosize
Advanced tools
Vertically adjust a textarea based on user input without needing a clone or ghost element.
This package contains a TextareaAutoSize
ES6 class for vertically adjusting a textarea based on user input and controlling any presentation in CSS. No clone or ghost elements are used. No jQuery dependency either, just plain vanilla JS. 😉
This was a fun project I started in Aug 2012 as a jQuery plugin. Nowadays, the same hack can be implemented using vanilla JS with such little code that I don't recommend using this package. Instead just implement the component code in your project so it can be modified to your requirements.
npm install textarea-autosize
Import the script and find the desired textarea
elements on which to initialize the component with.
<textarea class="js-auto-size" rows="1"></textarea>
<script type="module">
import { TextareaAutoSize } from './textarea-autosize'
const wrapper = new TextareaAutoSize(document.querySelector('textarea.js-auto-size'))
</script>
In the following example, the minimum height is one line of text which is determined from the inherited font size, line height, and vertical padding. So if your font-size is 16px, line-height is 1.5, top/bottom padding is 6px each, then the minimum height would be 36px since 16 * 1.5 + 12 = 36
.
textarea {
box-sizing: border-box;
max-height: 160px; /* optional but recommended */
min-height: 38px;
}
Increase the min-height
to have more initial rows. Once text exceeds that minimum height the textarea will expand naturally until it reaches the maximum height if declared.
If you pre-fill the textarea before page load the textarea will adjust to fit automatically but if given a value after page load (e.g. single page app) then you will need to trigger an update on the textarea after setting its value for it to size correctly.
wrapper.update()
Calling the destroy
method will remove the event handler and release the element reference.
wrapper.destroy()
npm install
npx playwright install
npm test
npm run start
Replace {type} with any of the following: patch, minor or major
npm version {type}
git push origin --tags
npm run predeploy && npm publish
Run npm run deploy
to release on GitHub Pages using gh-pages package.
FAQs
Vertically adjust a textarea based on user input without needing a clone or ghost element.
The npm package textarea-autosize receives a total of 1,746 weekly downloads. As such, textarea-autosize popularity was classified as popular.
We found that textarea-autosize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.