Преглед изворни кода

Merge pull request #2211 from thecrypticace/support-backspace-with-delete-alias

Support backspace with "delete" keycode alias
Evan You пре 10 година
родитељ
комит
fe02b38c4f
2 измењених фајлова са 44 додато и 1 уклоњено
  1. 2 1
      src/directives/public/on.js
  2. 42 0
      test/unit/specs/directives/public/on_spec.js

+ 2 - 1
src/directives/public/on.js

@@ -7,7 +7,7 @@ const keyCodes = {
   tab: 9,
   enter: 13,
   space: 32,
-  'delete': 46,
+  'delete': [8, 46],
   up: 38,
   left: 37,
   right: 39,
@@ -28,6 +28,7 @@ function keyFilter (handler, keys) {
     }
     return keyCodes[key]
   })
+  codes = [].concat.apply([], codes)
   return function keyHandler (e) {
     if (codes.indexOf(e.keyCode) > -1) {
       return handler.call(this, e)

+ 42 - 0
test/unit/specs/directives/public/on_spec.js

@@ -88,6 +88,48 @@ describe('v-on', function () {
     })
   })
 
+  it('with delete modifier capturing DEL', function (done) {
+    new Vue({
+      el: el,
+      template: '<a v-on:keyup.delete="test">{{a}}</a>',
+      data: {a: 1},
+      methods: {
+        test: function () {
+          this.a++
+        }
+      }
+    })
+    var a = el.firstChild
+    trigger(a, 'keyup', function (e) {
+      e.keyCode = 46
+    })
+    _.nextTick(function () {
+      expect(a.textContent).toBe('2')
+      done()
+    })
+  })
+
+  it('with delete modifier capturing backspace', function (done) {
+    new Vue({
+      el: el,
+      template: '<a v-on:keyup.delete="test">{{a}}</a>',
+      data: {a: 1},
+      methods: {
+        test: function () {
+          this.a++
+        }
+      }
+    })
+    var a = el.firstChild
+    trigger(a, 'keyup', function (e) {
+      e.keyCode = 8
+    })
+    _.nextTick(function () {
+      expect(a.textContent).toBe('2')
+      done()
+    })
+  })
+
   it('with key modifier (keycode)', function (done) {
     new Vue({
       el: el,