Giter VIP home page Giter VIP logo

vue-input-autowidth's Introduction

vue-input-autowidth tests

A Vue.js directive that automatically resizes an input's width to fit its contents.

🚦 Looking for Vue 2 support? Check out the master branch.

Installation

npm install vue-input-autowidth@next --save
# or...
yarn add vue-input-autowidth@next

or

Use the UMD build from Unpkg, available as VueInputAutowidth in the global scope.

<script src="/vendor/vue.js" />
<script src="https://unpkg.com/vue-input-autowidth@next" />

Usage

Globally

Import and register the directive in your app's entrypoint.

import { createApp } from 'vue'
import App from './App.vue'
import { plugin as VueInputAutowidth } from 'vue-input-autowidth'

createApp(App).use(VueInputAutowidth).mount('#app')

Per-component

<script>
import { directive as VueInputAutowidth } from "vue-input-autowidth"

export default {
  directives: { autowidth: VueInputAutowidth },
  setup() {
    ...
  },
}
</script>

...and in your template:

<template>
  <input type="text" placeholder="First Name" v-model="msg" v-autowidth />
</template>

You can also pass some options:

<template>
  <input
    type="text"
    placeholder="First Name"
    v-model="msg"
    v-autowidth="{
      minWidth: '75px',
      maxWidth: '75%',
      comfortZone: '1ch',
    }"
  />
</template>

Available Options

Name Type Default Value Description
maxWidth string undefined Sets the max-width CSS property on the element. The value should be a valid CSS size and unit.
minWidth string undefined Sets the min-width CSS property on the element. The value should be a valid CSS size and unit.
comfortZone string 0px Uses CSS calc() to add the specificied amount to the calculated width. The value should be a valid CSS size and unit.
watchWindowSize boolean false When enabled, the directive will listen to the window resize event, and resize the input if needed.
windowResizeHandlerDebounceTime number 150 The debounce time in milliseconds for the window resize event. Only applies if watchWindowSize is true.
disableNonInputWarning boolean false Disables the console warning if you try and use the directive on a non-input element.

License

MIT © Collin Henderson

vue-input-autowidth's People

Contributors

dependabot[bot] avatar lenzls avatar mr-sanders avatar nachodd avatar p-rivero avatar syropian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vue-input-autowidth's Issues

[Vue warn]: A plugin must either be a function or an object with an "install" function.

Thank you for making this great plugin!

I believe I've followed your instructions for installation and usage on the v2 branch, but get [Vue warn]: A plugin must either be a function or an object with an "install" function. when I try to use it.

For your reference, here's my main.js:

import { createApp } from "vue";
import { plugin as VueInputAutowidth } from 'vue-input-autowidth';

import App from "./App.vue";
import router from "./router";

import "./assets/main.css";

const app = createApp(App);

app.use(VueInputAutowidth); // this is the line with the warning
app.use(router);

app.mount("#app");

This problem seems to prevent me from using your plugin. I attempt to use it in a component I get:

[Vue warn]: Failed to resolve directive: autowidth 
  at <HomeView onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > > 
  at <RouterView> 
  at <App> 

Not working when using :value directive on input.

I'm currently injecting data into the input component directly via the :value directive, which does not trigger the autoresize. Changing to v-model fixes it.

Is there a fundamental restriction when using the value directive which makes the autoresize functionality not work?

max/min width options probably not necessary

All it's currently doing is setting the min/max width css style on the element. This is something the user can likely do themselves, and with Vue's reactivity system, it's easy to update.

Dist should be ES5

This module does not work in IE11 due to it using ES6 Object.assign. The dist file should be ES5 for better browser support.

This is an issue to me because Browserify/Babelify does not transpile the node_modules folder.

q is not defined

image
I got this error on production (Heroku), I've been using Vue 2 with Meteor.

Maybe too narrow on Firefox

It could be this needs some inquiry but I think on Firefox (68.0.2 MacOS) the fiels are too narrow.
Other browser do work fine.

grafik

wrong width on password input

just a little bug when you use a password input, show you

| text input |
| •••••••••••      |

Wrong width

Hi,

On last version FF, since last update.

My input seems to appear with confortZone > 0 while ... :
v-autowidth="{maxWidth: '680px', minWidth: '50px', comfortZone: 0}"

image

Please fix 🤔
PS: no it's not minWidth. Seems to be OK on other browser like Chrome

Vue 3 support

I am currently migrating some of my apps to Vue3 which is currently in RC-2.

There is a few breaking changes to the directive API making the library not compatible.

I found a workaround in my apps by doing:

import VueInputAutowidth from 'vue-input-autowidth';

export default {
  [...]
  directives: {
    autowidth: {
      beforeMount: VueInputAutowidth.bind,
      mounted: VueInputAutowidth.inserted,
      updated: VueInputAutowidth.componentUpdated,
      unmounted: VueInputAutowidth.unbind,
    },
  },
}

but it would be nice to add support.

Autowidth on select element

I actually tried using your package on a select element and it worked pretty good. But it throws an error in the console warning me to only us it on input elements.

Since it is working, I will keep using it, but can I get rid of the error message?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.