v-autosize Vue Textarea Autosize Directive

2.0.1 · active · verified Sun Apr 19

v-autosize is a lightweight Vue 3 directive designed to wrap the standalone `autosize` library, enabling `<textarea>` HTML elements to automatically adjust their height to perfectly fit their content. The current stable version, 2.0.1, is built specifically for Vue 3. Users requiring Vue 2 compatibility should refer to `v-autosize@1`. This package differentiates itself from other solutions like `vue-autosize` and `vue-textarea-autosize` by being actively maintained for the current Vue ecosystem (Vue 3) and providing a simple, directive-based integration rather than a component-based one, ensuring minimal boilerplate. Release cadence is typically tied to updates in the core `autosize` library or significant Vue ecosystem changes, prioritizing stability and a small bundle size.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to globally register the `v-autosize` directive plugin and apply it to a `<textarea>` element within a Vue 3 application, enabling automatic height adjustment.

import { createApp } from 'vue';
import autosizePlugin from 'v-autosize/src/plugin.js';

const app = createApp({
  template: `
    <div>
      <label for="my-textarea">Resizable Textarea:</label>
      <textarea id="my-textarea" v-autosize style="width: 300px; padding: 8px; border: 1px solid #ccc;" placeholder="Type something..."></textarea>
      <p>The textarea above will automatically adjust its height as you type.</p>
    </div>
  `,
});

app.use(autosizePlugin);
app.mount('#app');

view raw JSON →