mirror of
https://github.com/KevinMidboe/vue-js-modal.git
synced 2025-10-29 18:00:20 +00:00
Closing modal when ESC button pressed
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user