Close modal with escape key

This commit is contained in:
Jeffrey Biles
2020-03-18 16:41:47 -07:00
parent e297a104e4
commit d415b86386

View File

@@ -9,6 +9,21 @@
<script>
export default {
mounted: function () {
window.addEventListener('keydown', this.onkey)
},
beforeUnmount: function () {
window.removeEventListener('keydown', this.onkey)
},
methods: {
onkey(event){
if(!this.isOpened) { return null }
if(event.key == 'Escape') {
this.closeModal()
}
}
},
props: {
isOpened: {
type: Boolean,