Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-autosize-input

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-autosize-input

Auto-resizing Input Component for Vue

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
81
increased by145.45%
Maintainers
1
Weekly downloads
 
Created
Source

Vue-autosize-input

A text input for Vue that resizes itself to the current content.

Demo & Examples

Live demo: houjiazong.github.io/vue-autosize-input

To run the examples locally, run:

yarn install
yarn serve

Then open localhost:8000 in a browser.

Installation

NPM

npm install vue-autosize-input --save

Yarn

yarn add vue-autosize-input

Usage

Vue-autosize-input generates an input field, wrapped in a <div> tag so it can detect the size of its value. Otherwise it behaves very similarly to a standard Vue input.

<template>
  <autosize-input
    v-model="value"
    @change="onChange />
</template>

<script>
import AutosizeInput from 'vue-autosize-input'

export default {
  components: {
    AutosizeInput,
  },
  data () {
    return {
      value: '',
    }
  },
  methods: {
    onChange (e) {
      console.log(e.target.value)
    },
  },
}
</script>

Gotchas

Changing the styles at runtime

The styles applied to the input are only copied when the component mounts. Because of this, subsequent changes to the stylesheet may cause size to be detected incorrectly.

To work around this, either re-mount the input (e.g. by providing a different key prop) or call the copyInputStyles() method after the styles change.

CSP and the IE "clear" indicator

The input will automatically inject a stylesheet that hides IE/Edge's "clear" indicator, which otherwise breaks the UI. This has the downside of being incompatible with some CSP policies.

To work around this, you can pass the injectStyles={false} prop, but if you do this I strongly recommend targeting the input element in your own stylesheet with the following rule:

input::-ms-clear {display: none;}

Custom font sizes

If your input uses custom font sizes, you will need to provide the custom size to AutosizeInput.

<template>
  <autosize-input
    name="form-field-name"
    v-model="value"
    :style={{ fontSize: '36px' }}
    @change="onChange />
</template>

<script>
import AutosizeInput from 'vue-autosize-input'

export default {
  components: {
    AutosizeInput,
  },
  data () {
    return {
      value: '',
    }
  },
  methods: {
    onChange (e) {
      console.log(e.target.value)
    },
  },
}
</script>

License

Copyright (c) 2018 houjiazong. MIT License.

FAQs

Package last updated on 07 Dec 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc