Giter Club home page Giter Club logo

vue-directive-long-press's Introduction

Long Press - Vue directive

Build Status

expose long press event on any element or component

Getting Started

npm install vue-directive-long-press
<template>
  <button
    v-long-press="300"
    @long-press-start="onLongPressStart"
    @long-press-stop="onLongPressStop">
    Click and Hold for 300ms</button>
</template>
<script>
import LongPress from 'vue-directive-long-press'

export default {
  directives: {
    'long-press': LongPress
  },
  methods: {
    onLongPressStart () {
      // triggers after 300ms of mousedown
    },
    onLongPressStop () {
     // triggers on mouseup of document
    }
  }
}
</script>

To use directive globally

import Vue from 'vue'
import LongPress from 'vue-directive-long-press'

Vue.directive('long-press', LongPress)

Demo

View and edit the demo at StackBlitz here!

Running the tests

npm run test

License

This project is licensed under the MIT License - see the LICENSE.md file for details

vue-directive-long-press's People

Contributors

dependabot[bot] avatar feliciousx avatar kiyui avatar naeramarth7 avatar

Stargazers

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

Watchers

 avatar

vue-directive-long-press's Issues

possible to add event

in vue i want to get the mouse (or finger) position of the long press. i wanted to do this by adding the event, but this gives undefined:

`
@long-press-start="onLongPressStart(e)"

onLongPressStart (e) {
console.log(e);
},
`

Include typescript definitions in package

Right now the typescript definitions file that should be alongside index.js in the dist folder simply isn't there. This makes it unnecessarily painful to use this package in a typescript project.

Need a way to prevent @click event

At the moment, it doesn't seem possible to combine @click with @long-press-start.
Therefor, every time the long press event fires, the click event also fires.

Need something like @long-press-start.prevent where the click event won't fire.

Error with Nuxt

With Nuxt, using from a component or from a plugin, I get CustomEvent is not defined in the file node_modules/vue-directive-long-press/dist/index.js.

Use directive as a plugin

Breaking change

  • allow export default to be a plugin and spread export to use directive locally per component

Need a way to determine right or left click

I'm working on a PWA that is used both on touch devices and computers. When right clicking a event that has a longpress-event binded to it, then "long-press-start" is triggered, but "long-press-stop" is never trigered, not until one click with the left button and the regular event cycle kicks in.

I solved this manually by listening for "window.oncontextmenu" to detect if the click is right or left, and the discard the long press event if the right button was used.

Would this be something that the longpress should detect, whether the right or left mouse button is clicked?

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.