Closing modal when ESC button pressed

This commit is contained in:
euvl
2017-11-19 09:04:18 +00:00
parent 0be4f011ef
commit 7d66dc9d8c
3 changed files with 32 additions and 10 deletions

View File

@@ -256,12 +256,20 @@
})
}
}
if (this.clickToClose) {
window.addEventListener('keyup', this.onEscapeKeyUp)
}
},
/**
* Removes "resize" window listener
*/
beforeDestroy () {
window.removeEventListener('resize', this.onWindowResize)
if (this.clickToClose) {
window.removeEventListener('keyup', this.onEscapeKeyUp)
}
},
computed: {
/**
@@ -372,6 +380,12 @@
modal.heightType = height.type
},
onEscapeKeyUp (event) {
if ((event.keyCode || event.which) === 27 && this.visible) {
this.$modal.hide(this.name)
}
},
onWindowResize () {
this.window.width = window.innerWidth
this.window.height = window.innerHeight