npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

autoheight-textarea

v1.0.3

Published

Custom element for automatically resizing textareas. Works everywhere: Virtual DOM and plain HTML

Downloads

166

Readme

NPM

autoheight-textarea is a small (7kb gzipped) HTML5 custom element wrapper around textarea elements that will automatically resize itself as the user types.

It works everywhere, because it's implemented as a custom element. Including: Virtual DOMs (React, Elm, etc.), server-side rendered HTML and, of course, good old index.html files.

The component will respect any minimum height set on the textarea via the rows attribute.

Demo

Example gif

Code sandboxes

  • Basic HTML: https://codesandbox.io/s/unruffled-http-2vm4c
  • React.js: https://codesandbox.io/s/misty-violet-p1jwb

Example usage

For any of the following examples, all you need to do is include the script. For example, you could add this to the top of your main JS file:

import "autoheight-textarea";

// Your code here... React, jQuery, whatever

React

const App = () => {
  return (
    <autoheight-textarea>
      <textarea rows={4} placeholder="Type something..." />
    </autoheight-textarea>
  );
}

HTML / PHP

<autoheight-textarea>
  <textarea placeholder="Type something..." rows="4"></textarea>
</autoheight-textarea>

Elm

Html.node "autoheight-textarea" [] [ 
    textarea [ placeholder "Type something..." , rows 4 ] [] 
  ]

Feel free to add any other elements inside of the autoheight-textarea node. For instance, you could implement a Bootstrap textarea with form help text like so:

<div class="form-group">
  <autoheight-textarea>
    <label for="my_textarea">Example textarea</label>
    <textarea class="form-control" id="my_textarea" rows="4"></textarea>
    <small class="form-text text-muted">This is what a Bootstrap textarea looks like</small>
  </autoheight-textarea>
</div>

Why would you do that? Mostly because it makes things easier to select with CSS. For instance you might want to hide the help text until the textarea has focus.

textarea:not(:focus) + .form-text {
  display: none;
}

Browser support

All major browsers — including IE11.

This package uses @webcomponents/custom-elements under the hood.