Vue Textarea Autosize

1.1.1 · abandoned · verified Sun Apr 19

vue-textarea-autosize is a lightweight Vue.js component that provides a `<textarea>` element with automatically adjustable height based on its content. It supports standard `v-model` binding, allowing for two-way data synchronization, and includes props for setting `minHeight` and `maxHeight` to constrain the textarea's dimensions. The component differentiates itself by explicitly stating it has no external dependencies or wrappers, aiming for a simple and performant solution. Currently at version 1.1.1, the package appears to be primarily targeted at Vue 2 applications, as indicated by its documentation and a Vue 2 badge. With its last update approximately four years ago and Vue 2 having reached end-of-life, the project is likely in an abandoned state, meaning new feature development or compatibility updates for Vue 3 are not expected.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to globally register and use the `textarea-autosize` component with `v-model`, `min-height`, `max-height`, and native event handling in a Vue 2 application. It also shows how to programmatically interact with the underlying `<textarea>` element using refs.

import Vue from 'vue';
import TextareaAutosize from 'vue-textarea-autosize';

Vue.use(TextareaAutosize);

new Vue({
  el: '#app',
  data() {
    return {
      value: 'Initial text for the autosizing textarea. Type something here to see it expand automatically.',
    };
  },
  methods: {
    onBlurTextarea() {
      console.log('Textarea blurred (native event)');
    },
    focusTextarea() {
      if (this.$refs.myTextarea && this.$refs.myTextarea.$el) {
        this.$refs.myTextarea.$el.focus();
      }
    },
    blurTextarea() {
      if (this.$refs.myTextarea && this.$refs.myTextarea.$el) {
        this.$refs.myTextarea.$el.blur();
      }
    },
    selectTextarea() {
      if (this.$refs.myTextarea && this.$refs.myTextarea.$el) {
        this.$refs.myTextarea.$el.select();
      }
    },
  },
  template: `
    <div id="app">
      <h2>Vue Textarea Autosize Example</h2>
      <textarea-autosize
        placeholder="Type something here..."
        ref="myTextarea"
        v-model="value"
        :min-height="50"
        :max-height="250"
        style="width: 100%; border: 1px solid #ccc; padding: 8px; font-size: 14px; box-sizing: border-box;" 
        @blur.native="onBlurTextarea"
      />
      <p>Current value: {{ value }}</p>
      <button @click="focusTextarea">Focus Textarea</button>
      <button @click="blurTextarea">Blur Textarea</button>
      <button @click="selectTextarea">Select Content</button>
    </div>
  `,
});

view raw JSON →