Skip to content

Commit

Permalink
Support backspace with delete key code alias
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Jan 22, 2016
1 parent e4accfc commit 10fd2b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/directives/public/on.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const keyCodes = {
tab: 9,
enter: 13,
space: 32,
'delete': 46,
'delete': [8, 46],
up: 38,
left: 37,
right: 39,
Expand All @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions test/unit/specs/directives/public/on_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 10fd2b0

Please sign in to comment.