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

@lecoupa/v-hotkey

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lecoupa/v-hotkey

Vue 2.x directive - binding hotkeys for components.

  • 0.7.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

v-hotkey

bundlephobia minified size npm package version github license js standard style

Vue 2.x directive for binding hotkeys to components.

Play with me

https://dafrok.github.io/v-hotkey

Install

$ npm i --save v-hotkey

Usage

import Vue from 'vue'
import VueHotkey from 'v-hotkey'

Vue.use(VueHotkey)
<template>
  <span v-hotkey="keymap" v-show="show"> Press `ctrl + esc` to toggle me! Hold `enter` to hide me! </span>
</template>

<script>
export default {
  data () {
    return {
      show: true
    }
  },
  methods: {
    toggle () {
      this.show = !this.show
    },
    show () {
      this.show = true
    },
    hide () {
      this.show = false
    }
  },
  computed: {
    keymap () {
      return {
        // 'esc+ctrl' is OK.
        'ctrl+esc': this.toggle,
        'enter': {
          keydown: this.hide,
          keyup: this.show
        }
      }
    }
  }
}
</script>

Event Handler

  • keydown (as default)
  • keyup

Key Combination

Use one or more of following keys to fire your hotkeys.

  • ctrl
  • alt
  • shift
  • meta (windows / command)

Modifiers

prevent

Add the prevent modifier to the directive to prevent default browser behavior.

<template>
  <span v-hotkey.prevent="keymap" v-show="show"> Press `ctrl + esc` to toggle me! Hold `enter` to hide me! </span>
</template>

stop

Add the stop modifier to the directive to stop event propagation.

<template>
  <div v-hotkey.stop="keymap">
    <span> Enter characters in editable areas doesn't trigger any hotkeys. </span>
    <input>
  </div>
</template>

Key Code Alias

The default key code map is based on US standard keyboard. This ability to provide their own key code alias for developers who using keyboards with different layouts. The alias name must be a single character.

Definition

import Vue from 'vue'
import VueHotkey from 'v-hotkey'

Vue.use(VueHotkey, {
  '①': 49 // the key code of character '1'
})

Template

<span v-hotkey="keymap"></span>
<script>
export default {
  foo () {
    console.log('Hooray!')
  },
  computed: {
    keymap () {
      return {
        '①': foo
      }
    }
  }
}
</script>

Keywords

FAQs

Package last updated on 13 Jan 2020

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