• Stars
    star
    721
  • Rank 62,814 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue 2.x directive for binding hotkeys to components.

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 v-hotkey
# or
$ yarn add 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
  • command (MacOS)
  • windows (Windows)

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>

More Repositories

1

vue-baidu-map

Baidu Map components for Vue 2.x
Vue
2,413
star
2

vue-iscroll-view

IScroll-view component for Vue 2.x
Vue
148
star
3

fuck-ie

Check whether your browser is a f**king specified version of IE or not.
JavaScript
46
star
4

if-emoji

Check a character if it is a correctly supported emoji.
JavaScript
40
star
5

clip-it

A totally easy way for modern browsers to put something into clipboard.
JavaScript
12
star
6

dafrok.github.io

Blog
JavaScript
10
star
7

mysql-backup

JavaScript
6
star
8

BMapLib.MarkerClusterer

JavaScript
6
star
9

vue-fitd

Vue UI Library & FIT Design
Vue
5
star
10

game-pick-it-up

Game: Pick it up!
JavaScript
5
star
11

san-mixin

mixin function for san components
JavaScript
5
star
12

form-to-from

An ATOM plugin which helps you spell "from" right.
JavaScript
4
star
13

webpack2-docker

JavaScript
3
star
14

gzip-size-online

A tool for measuring the gzip size of a file online
JavaScript
3
star
15

BMapLib.LuShu

An UMD module of BaiduMap LuShu library.
JavaScript
3
star
16

thrash

别看了,没什么正经东西,划水用的。
HTML
3
star
17

css-color-playground

Easily transforming & copy your CSS color to other formats.
HTML
3
star
18

issues-bot

Webhook for issues
JavaScript
2
star
19

react-shortcut-key

Shortcut key wrapper for react components.
JavaScript
2
star
20

color-factory

CSS colors converter
JavaScript
2
star
21

deep-empty-object

JavaScript
1
star
22

cocalc

HTML
1
star
23

sheikah.dafrok.top

Sheikah language panel
JavaScript
1
star
24

issue-of-vue-loader

Deprecated
JavaScript
1
star
25

illiterate-editor

文盲编辑器,成为文盲不再是梦想。
JavaScript
1
star
26

ewent

Connect browser windows by events.
JavaScript
1
star
27

Pianer

An app for photographers and cosplayers
HTML
1
star
28

Weboy

CSS
1
star
29

f-check

JavaScript
1
star
30

Mobum.js

Mobile Album
JavaScript
1
star
31

awesome-docker-libraries

1
star
32

npud

Show the update date of npm packages dependencies in your project.
JavaScript
1
star
33

buy-buy-buy

1
star
34

BMapLib.TextIconOverlay

JavaScript
1
star
35

rndgen

Vue
1
star
36

abmid.js

Fix DOM elements always in the middle of the wrapper easily
JavaScript
1
star
37

bdshare

A shell of bdshare.
JavaScript
1
star
38

react-digiclock

JavaScript
1
star
39

cookie-proxy

Graceful cookie API
JavaScript
1
star
40

SimpleRC4

Python
1
star